47 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
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 MangalandGitHub bbd4b3f95c chore: remove dependency on io/ioutil (#1879)
we still have a couple of places where we are using io/ioutil.
2023-02-21 08:06:07 +05:30
Aman MangalandGitHub 14b0d32c59 chores(linter): enable rest of the linters (#1871) 2023-02-17 18:33:17 +05:30
Aman MangalandGitHub f83f87e90b fix order of imports (#1869) 2023-02-15 02:12:59 +05:30
Ibrahim JarifandGitHub 1152b2df00 Increase value threshold from 1 KB to 1 MB (#1664)
The write amplification with value log can be unpredictably high. It's better to use value log only for really big values, and keep as many values as possible within the LSM tree.
2021-02-09 12:11:11 -08:00
Ibrahim JarifandGitHub 8eefb381cb Support SinceTs in iterators (#1653)
SinceTs can be used to read data above a particular timestamp. All data
with version less than or equal to the sinceTs will be ignored.

SinceTs is always less than the readTs and when sinceTs is set, the
data between sinceTs and readTs will be read.

sinceTs < data to be read <= readTs

Fixes DGRAPH-2958
2021-02-05 18:19:34 +05:30
Manish R JainandGitHub 82ff532103 feat(info): Add a flag to parse and print DISCARD file (#1662) 2021-02-04 18:38:20 -08:00
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
479ccf29f0 [BREAKING] opt(compactions): Improve compaction performance (#1574)
Implement multiple ideas for speeding up compactions:

1. Dynamic Level Sizes: https://rocksdb.org/blog/2015/07/23/dynamic-level.html
2. L0 to L0 compactions: https://rocksdb.org/blog/2017/06/26/17-level-based-changes.html
3. Sub Compactions: Split up one compaction into multiple sub-compactions using key ranges, which can be run concurrently.
4. If a table being generated at Li overlaps with >= 10 tables at Li+1, finish the table. This helps avoid big overlaps and expensive compactions later.
5. Update compaction priority based on the priority of the next level prioritizing compactions of lower levels over upper levels, resulting in an always healthy LSM tree structure.

With these changes, we can load 1B entries (160GB of data) into Badger (without the Stream framework) in 1h25m at 31 MB/s. This is a significant improvement over current master.

Co-authored-by: Ibrahim Jarif <ibrahim@dgraph.io>
2020-10-26 14:12:58 -07:00
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 fe6a2986b6 Move Closer from y to z (#1498)
The `Closer` type was moved by badger/y package to ristretto/z via https://github.com/dgraph-io/ristretto/pull/191
2020-09-07 23:20:46 +05:30
Ibrahim JarifandGitHub d76c75f30a Add IsClosed method (#1475)
Add an IsClosed method which denotes if badger instance is closed or not.
2020-08-26 15:33:36 +05:30
Ibrahim JarifandGitHub de3dbfb9b6 Increase default valueThreshold from 32B to 1KB (#1346)
Increase value threshold from 32 bytes to 1 KB to allow easier space
reclaimation. There have been multiple reports about value log garbage
collection being unsatisfactory. This commit increases the default value
of threshold from 32 bytes to 1 KB which would allow keys and values
upto 1 KB to be co-allocated in the LSM tree. This would allow GC to
reclaim space easily for values less than 1 KB.
2020-06-24 20:46:12 +05:30
Ibrahim JarifandGitHub 2d5d5050bb Tests: Do not leave behind state goroutines (#1349)
A bunch of tests would start goroutines and never stop them. This PR fixes
that. There should not be any goroutine left after all the tests are
completed.

This PR also adds a db.cleanup method which would be called in case badger.Open
call fails. The cleanup method will stop all the goroutines started by Open
call.
2020-06-09 16:16:19 +05:30
Ibrahim JarifandGitHub 25deb5200e Handle duplicates in ManagedWriteBatch (#1315)
When duplicate entries with different versions are inserted, the
current implementation would store only the latest update and
drop all the previous ones. This PR fixes it. We keep all
duplicate entries in ManagedWriteBatch.
2020-04-30 15:41:40 +05:30
Ibrahim JarifandGitHub 03ea87e26d Support entry version in Write batch (#1310)
This PR adds support for setting different versions for different
keys in write batch. The existing implementation of write batch
allows setting only a single version for all keys in the write batch.
With this PR, user can do the following
```
wb := db.NewManagedWriteBatch()
wb.SetEntryAt(e, ts)
wb.Flush()
```

Also, the existing behavior of `txn.Commit()` in `un-managed
(normal) mode` is to panic, the new behavior would be to
return an error.
2020-04-21 11:54:41 +05:30
Ibrahim JarifandGitHub 3e2ae0848a Introduce in-memory mode in badger (#1113)
This PR introduces in-memory mode in badger. The in-memory mode
can be enabled by setting options.InMemory=true. When badger is
running in in-memory mode no files are created and everything 
is stored in memory.

On DB close, all stored data is lost.
NOTE - An existing DB cannot be opened in in-memory mode.

Fixes - https://github.com/dgraph-io/badger/issues/1001
2019-11-26 01:34:23 +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
Ibrahim JarifandGitHub 73d93079b2 Introduce block cache in badger (#1066)
This commit adds ristretto to badger. All the reads are done through
the block cache. The block cache holds blocks in a decompressed and
unencrypted state. The memory usage of cache can be changed by
`MaxCacheSize` option. The default size of the cache is 1 GB.
2019-10-21 16:19:09 +05:30
Ibrahim JarifandGitHub c5ac7dbd59 Use removeDir instead of defer os.Remove in tests (#1085)
This commit refactors test code and adds `removeDir` function that
removes dir and handles returned error.
2019-10-17 18:32:32 +05:30
Ibrahim JarifandGitHub 7508749c8d Fix windows build for badger (#1038)
This commit fixes windows build issues. There were 4 issues

1. Trying to truncate a mmapped file.
    On linux, we can truncate a mmapped file but on windows this
    operation is invalid. We should unmap the file before truncating it.
2. Removing a file that has open file descriptor.
    On windows we cannot delete a file if it has an open file descriptor.
    The following functions would increment the ref for a table but never
    decrease it.
     - getTableInfo function in levels.go
    	The getTableInfo function would create an iterator but never
	close it and because of this we would have issues trying to
	delete the file.
     - CreateTable function in stream writer
	The createTable function calls OpenTable which sets the ref of a
	table to 1 but we would never decrement this ref.
3. AppVeyor file checksum mismatch error (iterator errors)
    These errors were caused because we were trying to create a file with
    a random name but on appVeyor the `rand.Int63()` would return the same
    value for multiple calls. The problem was that `rand.Seed` was called
    with a `time.Now()` timestamp which wasn't always unique on AppVeyor. 
4. AppVeyor out of disk space error.
    In some of the tests we weren't closing the DB and trying to remove
    the directory. This meant the directory would never get deleted and
    thus AppVeyor would run out of disk space.

With this commit, the AppVeyor build should succeed.
2019-09-17 19:09:22 +05:30
Ibrahim JarifandGitHub 0a8925eda3 Support WriteBatch API in managed mode (#948)
This commit adds a new `WriteBatchAt(commitTs)` API which allows the user to use 
write batch in managed mode.

Fixes https://github.com/dgraph-io/badger/issues/944
2019-08-03 12:17:34 +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
Ashish GoswamiandGitHub 0f0de55438 Have same prefix for directory in tests (#878)
Currently, we are using different prefixes for creating Badger directory in tests. This PR makes changes to have prefix badger-test in all tests.
2019-06-19 13:51:22 +05:30
Ashish GoswamiandGitHub f33efbe56c Breaking Change: Fix WriteBatch APIs(#845)
* Remove SetWithTTL from WriteBatch as part of New EntryAPIs.
As we have removed SetWith functions from Txn struct. We can
do same for WriteBatch. Anyone can create Entry using new Entry
APIs and call SetEntry on WriteBatch.
* Change WriteBatch Set method to have same syntax as Txn.Set
* Fix DOCs for Entry APIs
2019-06-04 18:45:39 +05:30
Ashish GoswamiandGitHub eb1b8d94ac Breaking Change: Introduce new APIs for Entry creation/modification
* Add functions to create, modify Entry

Currently no functions are exposed to create and modify Entry, to
be set in a transaction. Functions Set, SetWithMeta, SetWithDiscard,
SetWithTTL, all are part of Txn struct. These functions internally
create an entry and then call txn.SetEntry. All of Set functions,
set a specific property of Entry apart from key and value. This
restricts us from setting multiple property for same entry such as
meta and TTL.
This PR adds functions to set different properties on an existing
Entry. After setting desired properties, user can call txn.SetEntry
to add entry in the transaction. It also removes entry related functions
from Txn Struct except SetEntry and Set.

* Fix all compilation failure due to above change using
new Entry methods.

* Fix comments from GolangCI.
2019-05-28 10:58:37 +05:30
Martin Martinez RiveraandGitHub b3bf366e25 Handle nil closers (#726)
Change the methods Done and HasBeenNotified to be able to handle a nil closer.

Also fix a flaky test.
2019-02-26 14:53:17 -08:00
Manish R JainandGitHub f0958c6bf2 Introduce DropPrefix API in Badger (#715)
This API would allow Badger to completely get rid of the given prefix, P. It does this by:

1. Flushing memtables to disk (skipping over the keys with P).
2. Doing normal compaction from L0 -> L1 (skipping keys with P).
3. Doing same level compaction on all the rest of the levels, picking tables which might have the prefix and rewriting them to new tables (again, skipping keys with P).

Before starting, all the writes are paused, the usual bits which apply to `DropAll` apply here as well.

Note: This PR has a breaking change for the Logger interface. It adds a Debugf API.

Changes:

* Working drop prefix
* Make the drop prefix more robust. Add a new Debugf API for logging.
* Add parallel tests for DropPrefix
* Avoid a test failure due to removing p dir.
* Only test DropPrefix in DropPrefix test.
* Address Martin's comments
2019-02-22 13:19:55 -08:00
Manish R Jain f27821dc60 Fix a race condition caused by concurrent reads while Badger is replacing its inmemory tables during DropAll. 2019-01-16 16:16:07 -08:00
Manish R Jain f637d752b4 Do not block vlog.dropAll on pending transaction, otherwise we can be stuck forever. It should delete the files irrespective. 2019-01-15 16:23:15 -08:00
Manish R Jain 50cfb54786 Fix a bug where value log does not forget about the files after they get deleted during DropAll. It caused future DropAlls to throw errors. 2019-01-13 20:00:32 -08:00
XuanwoandMartin Martinez Rivera 1f711f4823 Fix TestDropReadOnly (fails on Windows) (#661) 2019-01-04 15:00:00 -08:00
Manish R JainandGitHub ade2e8cc30 Fix race condition in DropAll (#656)
- Fix a race condition in DropAll, caused if concurrent writes are going on.
- Use `blockWrites` during DB.Close as well, so users don't see channel panics when doing writes after DB.Close.
- Port tests over for Stream framework from Dgraph.

Changes:
* Starting to add a test for stream
* Add a test for Stream. Allow repeated calls to Orchestrate on the same Stream object.
* Fix various race conditions with concurrent writes during DropAll.
* Use blockWrites during Close as well, to avoid the chan panics users see when doing writes after Close.
* Add license for stream_test.go
* 100 chars
2018-12-30 11:35:11 -08:00
Manish R JainandGitHub 680a988b49 Port Stream framework from Dgraph to Badger (#653)
This PR ports over a Stream framework from Dgraph to Badger. This framework allows users to concurrently iterate over Badger, converting data to key-value lists, which then get sent out serially. In Dgraph we use this framework for shipping snapshots from leader to followers, doing periodic delta merging of updates, moving predicates from one Alpha group to another, and so on.

However, the framework is general enough that it could lie within Badger, and that's what this PR achieves. In addition, the Backup API of Badger now uses this framework to make taking backups faster.

Changes:
* Port Stream from Dgraph to Badger.
* Switch Backup to use the new Stream framework.
* Update godocs.
* Remove a t.Logf data race.
* Self-review
2018-12-28 12:23:50 -08:00
Manish R JainandGitHub f6e0ee6183 Rewrite DropAll to not use deletion markers (#651)
- Do not use deletion markers during DropAll, because that causes writes at lower timestamps to be ignored (in managed DB mode).
- Instead, delete all SSTables and all log files, and reset value log and value log head to zero.
- Make DropAll open to all users of Badger, including normal mode.

Changelog:
* Do not use delete markers in DropAll. Instead, delete the entire LSM tree and all the value logs.
* Moved DropAll to db.go, so it is available to all users of Badger. Fixed a bug where we were not catching memtable flushes during DropAll.
* Make DropAll test more races. Catch another place where writes should fail due to blockedWrite.
* Self-review
2018-12-26 19:22:33 -08:00
Manish R Jain c9154bfba8 Keep managedTxns option internal, so users have to use OpenManaged explicitly to open Badger. 2018-10-02 15:05:04 -07:00
Manish R JainandGitHub f9d7851910 Merge ManagedDB back into DB (#568)
* Remove the extra ManagedDB struct, which was causing maintenance headaches, due to the way Go handles polymorphism. Instead just expose the ManagedTxns option, and use it directly.

* Bring back the OpenManaged function for convenience.
2018-09-19 10:44:01 -07:00
Manish R Jain 47d76c1edc Use the same timestamp to delete keys as their latest versions. Thus, we can write back keys at the same timestamp without fear of losing them. 2018-07-12 15:02:33 -07:00
Manish R JainandGitHub dbf53a1b15 Add a DropAll method in ManagedDB (#525)
This method drops all tables from the LSM tree, except one to maintain the persistence of badgerHead key. This is important to avoid value log being replayed from scratch.

It then iterates over the rest of the keys and marks them as deleted. The end result should be that all keys are considered deleted.

This method would perform a lot better than deleting every key via iteration.

NOTE to users: The timestamp used for writes must be greater than the max timestamp of writes before DropAll, to ensure that new writes are not lower than the delete markers in terms of versioning.
2018-07-12 14:23:49 -07:00