60 Commits
Author SHA1 Message Date
Hanzo AI ab37e5f078 feat: reset module path to luxfi/zapdb v1.0.0
Removed /v4 suffix from module path and all internal imports.
Go module is now github.com/luxfi/zapdb (no major version suffix).
Import as: import "github.com/luxfi/zapdb"

No code changes — only module path and import rewrite.
2026-04-11 00:01:08 -07:00
Zach Kelling ebeadbd0a2 Rebrand badger to zapdb
- Rename module from github.com/dgraph-io/badger/v4 to github.com/luxfi/zapdb/v4
- Update all internal imports to use new module path
- Preserve all ZAP enhancements from badger fork
2026-02-08 14:14:21 -08:00
Benjamin WangandGitHub 774a135e5c fix: correct the comment on value size in skl.node (#2250)
**Description**

Correct an incorrect comment on the value size in skl.node.

Background: the PR https://github.com/dgraph-io/badger/pull/880 changed
the value size from uint16 to uint32, but the did not update the
comment.

**Checklist**

- [X] Code compiles correctly and linting passes locally
- [X] Tests added for new functionality, or regression tests for bug
fixes added as applicable

Signed-off-by: Benjamin Wang <benjamin.ahrtr@gmail.com>
2025-12-28 18:05:42 -05:00
Matthew McNeelyandGitHub 56b2d31d75 chore: update README.md with correct links and badges (#2239)
**Description**

Updated links

Closes #2238
2025-12-10 22:11:18 +00:00
Ryan Fox-TylerandGitHub 94498ea84c chore: align repo conventions (#2158) 2025-02-05 17:00:32 -05:00
Aman MangalandGitHub 3220a35a10 retract v4.3.0 due to #2121 and #2113, upgrade to Go v1.23, use ristretto v2 (#2122)
Fixes #2121
2024-10-25 22:03:34 +05:30
Joshua GoldsteinandGitHub ad428b8122 chore(ci): update changelog + import paths for v4 (#1886)
Changelog should reflect that we are switching to SemVer. This requires
moving to a new major version. We also update all import paths in
Badger.
2023-02-27 22:21:42 +00:00
Aman MangalandGitHub 4a93c43eac chore(linter): enable unconvert linter (#1881) 2023-02-22 23:32:29 +05:30
Aman MangalandGitHub 18972258dc chore: use atomic types instead (#1878) 2023-02-22 23:06:03 +05:30
aman bansalandGitHub dbca3723b3 changing badger module path to v3 (#1636)
* changing badger module path to v3

* running go mod tidy

* updating metric keys + proto package
2021-01-13 10:55:37 +05:30
Ajeet D'SouzaandGitHub dd74611a45 Revert mmap in skiplists (#1620) 2020-12-14 17:10:56 +05:30
Ahsan BarkatiandGitHub d7b55494b6 fix(skiplist): Remove z.Buffer from skiplist (#1600)
Remove z.Buffer from skiplist because we are using static sized buffer.
2020-11-19 22:29:41 +05:30
Ahsan BarkatiandGitHub e3b685c341 Add ValueUint64 api for skiplist iterator (#1575)
Add method to get uint64 value from skiplist iterator.
2020-10-23 17:59:26 +05:30
Ahsan BarkatiandGitHub 4036ad6584 Use mmap for skiplist (#1571)
Add support for memory-mapping in skiplist and expose the APIs 
for Uint64 values, i.e. GetUint64 and PutUint64.
2020-10-23 12:19:57 +05:30
Manish R JainandGitHub 4ed8fbdc02 [BREAKING]: Change how Badger handles WAL (#1555)
This PR significantly improves Badger's disk usage behavior.

Breaking: This PR increases the magic version from 7 to 8. So, no older Badger directories would work with this change.

With this PR, we no longer use value log as write-ahead log. Instead, each MemTable has its own WAL. Value logs now only write values which are greater than ValueThreshold, while MemTable WAL only writes smaller values and value pointers.

On a crash and restart, the MemTable WALs are replayed to apply updates to Skiplist. When MemTables are flushed to L0, the corresponding WALs are deleted.

This PR makes big changes to how value log GC works:
- Discard stats are now stored in a separate file, instead of within the LSM tree.
- GC only picks up value logs based off discard stats.
- GC no longer does sampling, it uses discard stats to inform when a value log needs to be GCed.
- Value log would now no longer grow indefinitely, because of the shift to MemTable WAL.
- Removed the `badger gc` tool.
- Value Log Head pointer tracking is removed.
- Only the last value log file is replayed on every start, and truncated as necessary.

This PR also makes a bunch of other changes:
- Removes ValueLogLoadingMode (always uses mmap now).
- Removes TableLoadingMode (always uses mmap now).
- Removes Truncate option.
- Removes KeepL0InMemory option.
2020-10-06 18:41:41 -07:00
Ibrahim JarifandGitHub 6ade9fc5c2 Use fastRand instead of locked-rand in skiplist (#1173)
The math/rand package (https://golang.org/src/math/rand/rand.go) uses
a global lock to allow concurrent access to the rand object.

The PR replaces `math.Rand` with `ristretto/z.FastRand()`. `FastRand`
is much faster than `math.Rand` and `rand.New(..)` generators.

The change improves concurrent writes to skiplist by ~30%
```go
func BenchmarkWrite(b *testing.B) {
	value := newValue(123)
	l := NewSkiplist(int64((b.N + 1) * MaxNodeSize))
	defer l.DecrRef()
	b.ResetTimer()
	b.RunParallel(func(pb *testing.PB) {
		rng := rand.New(rand.NewSource(time.Now().UnixNano()))
		for pb.Next() {
			l.Put(randomKey(rng), y.ValueStruct{Value: value, Meta: 0, UserMeta: 0})
		}
	})
}
```
```
name      old time/op  new time/op  delta
Write-16   657ns ± 3%   441ns ± 1%  -32.94%  (p=0.000 n=9+10)
```
2020-01-14 19:52:29 +05:30
Daniel MaiandGitHub 3ac1b68fe5 Update go.mod to v2 and add v2 import paths. (#1102)
* Update go.mod to v2 and add v2 import paths.

* Run go mod tidy.
2019-10-25 17:45:10 -07:00
Ashish GoswamiandGitHub b1a25c86c0 [breaking/format] Block level changes (#880)
* Have block based on size.
* Implementation of binary search inside block.
* Support for checksum at block level
* Update table benchmarks
* Support for max value size of uint32
2019-07-09 16:11:32 +05:30
Francesc Campoy 74d83eea3e Removing support for Go Modules
As explained in https://discuss.dgraph.io/t/go-modules-on-badger-and-dgraph/4662,
Go Modules force an import path rename that currently breaks support for most other
dependency management systems, including dep.

It seems an effort is being made to add support for this import path renaming by
patching the go tool itself, but until the community hasn't settled and Go Modules
is an easier option to adopt, we are simply not supporting them.

For those willing to use badger v2 from Go modules it is still very simple, you might
notice that once you set the version to be v2.0.0 a +incompatible will be added to it
indicating the dependency has not opted-in into Go Modules. That's normal and not to
be a concern.
2019-06-25 10:52:36 -07:00
Francesc Campoy 05d91d5ad8 release badger v2.0.0
Modify the import path on go.mod and every internal reference.
2019-06-20 11:02:19 -07:00
huangnauhandManish R Jain 20c8777ef9 free head pointer (#849)
To avoid memory leaks
2019-06-11 19:30:46 -07:00
Martin Martinez RiveraandGitHub e84a9f608e Fix unused warnings. (#855) 2019-06-10 09:53:48 -07:00
Martin Martinez RiveraandGitHub 79d343b668 Fix TestOneKey on Windows. (#672)
Use AddInt32 instead of StoreInt32
2019-01-04 17:33:37 -08:00
Manish R Jain 7e0c36815e Enforce ValueThreshold max to uint16.
Keep ValueThreshold to below uint16, because that value size limit is
baked into the header of the key-value pairs in SSTable. Keeps most of
the simplifications of the previous change by Andy Kimball, while
bringing the uint16 limits back. In fact, this change enforces that
limit by returning an explicit error for invalid ValueThreshold.
2018-05-02 06:11:08 -07:00
Andy KimballandManish R Jain 11331f506a Enable skiplist values that are up to 32 bits in length (#472)
Currently, inline skiplist values are limited to a length of 16 bits.
This commit increases that limit to 32 bits. It does this by making
node.value a uint64, and then packing the value offset and size into
it, as two uint32 values.

Because node.value is accessed with atomic.LoadUint64, it must be
aligned on a 64-bit boundary. This is guaranteed by Arena.putNode,
which is changed to always align on a 64-bit boundary rather than
on a pointer boundary (which would incorrectly align on 32-bit
boundary on a 32-bit machine).
2018-05-01 21:20:32 -07:00
Deepak Jois 17d6b53212 Fixing 64-bit alignment in structs that use sync.atomic
This change fixes segmentation faults on Arm v7.

From https://golang.org/pkg/sync/atomic/:

> On both ARM and x86-32, it is the caller's responsibility to arrange
for 64-bit alignment of 64-bit words accessed atomically. The first word
in a variable or in an allocated struct, array, or slice can be relied
upon to be 64-bit aligned.

Had to modify a couple of tests to get them to pass.

Fixes #311.
2017-11-13 16:29:04 +05:30
Janardhan Reddy 6b231701d4 Use custom comparator for comparing keys.
* Add test for value log replay, iteration
* Fix seek during reverse iteration
* Throw error if user tries to get empty key.
* If user tries to seek for empty key, then rewind
2017-10-04 10:53:02 +11:00
Janardhan ReddyandGitHub e0ad839873 Fix all unit tests
LSM Get checks in all levels if key is not found in memtable or level 0 to find latest version.
Fix parseItem. Breakage caused by how we store key in KVItem.
 Fix storing/reading readTs from badger head
2017-10-02 17:47:46 +11:00
Manish R Jain b8e3bf0985 Implement Transactions: Part 2
- Move all errors into a new file: errors.go.
- Remove all public APIs from kv.go. All the public APIs now flow through transactions.
- Remove SetIfAbsent, CompareAndSet, etc. They should all be done via transactions now.
- Remove CAS counter from everywhere.
- Simplify serialization/deserialization of various structs.
- Move them into new structs.go file (currently only contains value.go structs).
- Logic to handle transaction boundaries when replaying value log.
2017-09-28 18:54:33 +10:00
Manish R Jain 2c7468c346 Implement Transactions (Part 1)
- Enable versioning in Badger.
- Implement SSI (serializable snapshot isolation) based transactions, which can
be run concurrently, based on Yabandeh's paper: A critique of snapshot isolation
(with modifications).  Using a map of committed rows -> timestamp to detect
conflicts.

What works:

- Transactions: Concurrency, Conflict detection, Read snapshots, Versioning, etc.
- Get, Set, Commit
- Iteration within transactions.
- All the transaction logic works. The effect on other components needs to be done.

[WIP]

- The replay logic needs to be updated to understand txn boundaries and init
readTs at start.
- Existing APIs need to be removed.
2017-09-28 10:33:28 +10:00
Andy KimballandManish R Jain eeccca45f4 Allocate nodes from the arena. (#231)
* Allocate nodes from the arena.

The skiplist allocates keys and values from the arena, but not nodes.
This change begins allocating nodes from the arena. Links between
nodes at the same level are now offsets into the arena rather than
pointers. The "tower" of links is allocated as extra bytes appended
to the end of the node rather than a separate array.

Together, these changes significantly speed up skiplist writes and
reads. It also reduces overall memory usage (by using next offsets
rather than next pointers), as well as GC pressure (nodes do not
use pointers to reference one another).

* Allocate full tower in node struct.

The current code allocates the first tower entry in the node struct
and then allocates additional entries beyond the end of the node.
This change instead allocates all the tower entries as part of the
node struct, and then allocates only a subset of those entries in
the arena. This makes the code slightly simpler (no unsafeTower).
2017-09-19 11:27:16 +10:00
Andy KimballandManish R Jain 579ac854b5 Use atomic operations to access value. (#232)
* Use atomic operations to access value.

Using atomic operations saves 8 bytes per node (size of mutex).

* Update value field comment.
2017-09-19 10:54:37 +10:00
cardbotandManish R Jain 5ba065dae4 Use unsynchronized random number generator. (#229)
The skiplist benchmark was using the global random number generator,
which is guarded by a mutex. This causes contention on multi-core
machines and skews the benchmark results in a material way. Instead,
use a separate random number generator per benchmark goroutine.
Update the README results.
2017-09-18 11:36:39 +10:00
Sam Hughes 736ccdaedd Address golint and go vet complaints
Some immaterial code changes:

- Simplified Safecopy

- Replaced SafeMutex with empty warning parameters

- Removed unused functions

- Unexported functions (instead of commenting them)
2017-09-08 12:53:04 -07:00
Sam Hughes 5bdeeba526 Rename Skiplist::Size to MemSize 2017-08-13 20:41:49 -07:00
Sam Hughes d2e6a4bca5 Replace mistaken test of memtable size before last flush 2017-08-13 20:00:20 -07:00
Sam Hughes 67d864c1d7 Use incrementing 64-bit CAS counter
We ended up implementing it with an atomic variable.

!badger!head is used to store a sufficiently large CAS value that,
after replaying the value log, it is accurately greater than or equal
to the previously used CAS values.
2017-07-27 18:06:11 -07:00
Janardhan ReddyandGitHub 41e9f2ac2e allow users to store usermetadata in lsm (#123) 2017-07-27 10:19:14 +10:00
Sam Hughes 57dd3d0123 Remove ArenaPool
It seems not to help performance or memory usage substantially.  Maybe
it does not help at all.
2017-07-18 12:32:58 -07:00
Pawan Rawal a40a15eb50 Add kv.Touch(key) method which puts the key in LSM tree quickly. 2017-07-06 12:55:33 +10:00
Pawan Rawal 5af02d2b09 Use s.Height() which loads the height using atomic 2017-07-05 12:28:32 +10:00
Manish R Jain fad98504c0 Refactor compaction logic, improve logging.
Refactor compaction logic to be in-line with how RocksDB does things.
This refactoring now allows multiple compactions to happen
simultaneously, even at the same level; ensuring that the ranges being
compacted are not overlapping.

We no longer ask for verbosity of output, because all logging has now
been switched over to trace package. We use trace.Trace for compactions,
and trace.EventLog for KV and ValueLog.

The following is a log of all the individual commits.

commit 746c5118a3463483ccb41126d34a7bf35a19c686
Author: Manish R Jain <manish@dgraph.io>
Date:   Tue Jun 6 15:43:07 2017 +1000

    Address comments

commit 3957d6b5d2b39b93fcd901b45ae09c5d2d04752c
Author: Manish R Jain <manish@dgraph.io>
Date:   Tue Jun 6 15:29:01 2017 +1000

    Keep more events per compaction

commit e79c87f0502a6bd2ad0ba48c162d47a71e05e9e3
Author: Manish R Jain <manish@dgraph.io>
Date:   Tue Jun 6 15:22:11 2017 +1000

    Remove y.Printf entirely, along with verbose mode. All logging is done via event log and tracing.

commit b0452d8c1bdd511a7bb088489637a7da035acfaa
Author: Manish R Jain <manish@dgraph.io>
Date:   Tue Jun 6 15:04:47 2017 +1000

    Move compaction logs entirely to tracer

commit 28bb7cfeec1fbf59301428845cb9aa14d15cb94e
Author: Manish R Jain <manish@dgraph.io>
Date:   Tue Jun 6 04:53:26 2017 +0000

    Use tracers for each compaction.

commit 71462ceaa433b9d96bab267101f4df560afa7ef5
Author: Manish R Jain <manish@dgraph.io>
Date:   Tue Jun 6 11:08:17 2017 +1000

    Switch compactions to trace.Trace

commit c982b4ec81710b7ab1cbc389800a379a59ceb92b
Author: Manish R Jain <manish@dgraph.io>
Date:   Mon Jun 5 09:58:52 2017 +0000

    Move stuff to elog

commit f1883fc5594e979803cb4b9639d20bb698ad2fae
Author: Manish R Jain <manish@dgraph.io>
Date:   Fri Jun 2 19:31:41 2017 +1000

    Move compaction logs to event log

commit e86865802929e6fc996fb04f3bb8a9995a6b85fe
Author: Manish R Jain <manish@dgraph.io>
Date:   Fri Jun 2 16:21:12 2017 +1000

    Double check in compareandadd if we really need a compactino.

commit a4cf25515249188c5a16b60648b909a2cc61629c
Author: Manish R Jain <manish@dgraph.io>
Date:   Fri Jun 2 16:09:09 2017 +1000

    Try other levels if can't run compaction.

commit 3f34dca250f612557d8e17337bf5efec73c4214f
Author: Manish R Jain <manish@dgraph.io>
Date:   Thu Jun 1 18:40:38 2017 +1000

    Keep track of tables being currently compacted.

commit e9c895a64a7e942aef53300b2f605bfd91c859b9
Author: Manish R Jain <manish@dgraph.io>
Date:   Thu Jun 1 18:23:22 2017 +1000

    Run 3 compactors simultaneously

commit 9e3dfc101ac9dfb644b36d13a026062d178effe5
Author: Manish R Jain <manish@dgraph.io>
Date:   Thu Jun 1 13:52:53 2017 +1000

    Kinda works with compaction using key ranges to determine overlap.

commit c767a55ab9b30c55c0eda10e6606460bf5bac317
Author: Manish R Jain <manish@dgraph.io>
Date:   Wed May 31 19:47:09 2017 +1000

    Allow multiple compactions to happen concurrently.
2017-06-06 15:56:25 +10:00
Manish R Jain a305e5747a Return error from iterator.Close() function. 2017-05-30 23:46:58 +10:00
Minjie ZhaandManish R Jain 5097dc672a skl: fix findNear comments (#40) 2017-05-22 10:08:00 +10:00
Manish R Jain 2c4aab8c57 Add Apache 2.0 license 2017-05-14 20:23:38 +10:00
Ganesh Acharya 0f42ef1816 Update CAS logic. Store CAS counters in vlog. 2017-04-30 13:39:14 -07:00
Ganesh Acharya b75404cf4a CAS Put and Delete 2017-04-28 00:31:24 +08:00
Ganesh Acharya 4307c97965 Comments 2017-04-26 22:15:25 +08:00
Ganesh Acharya 0f63b21469 Fix a few race conditions 2017-04-26 22:11:01 +08:00
Ganesh Acharya d17997f159 Unidirectional iterator, forward and backward 2017-04-25 00:10:31 +08:00