Repository navigation
Conversation
Badger is one ordered key space on an LSM tree, so the driver is the bbolt layout without the page tricks: a namespace byte leads every key, an operation row is keyed by step and phase and upserted in place with its state inside, the output sits in the terminal row, and the terminality commit deletes the run's stage and slot in its own transaction. Transactions are serializable; a commit refused as a conflict is retried, which is how two CreateRuns racing for one slot resolve. Sync writes are on by default; WithMemTableSize bounds Badger's buffer and with it the largest transaction. It is a module of its own, github.com/dangra/durable/store/badger, because Badger's dependency graph (OpenTelemetry, flatbuffers, compress) should enter only the binaries that import the driver. The release script discovers tagged modules under store/ as well as contrib/, CI builds, tests, fuzzes, staticchecks, and vulnerability scans the module, and dependabot holds its runtime dependency to patch updates. The differential contract fuzzer moves from the bbolt test into store/internal/storetest, shared by both persistent drivers.
There was a problem hiding this comment.
🟡 Changes recommended
A concurrent accepted cancellation can be lost during terminalization, and memtable parsing permits integer overflow.
3 open findings
What changed in this PR
Adds a lockstep-released Badger-backed persistent store, with shared contract fuzzing and full CI/release integration.
Changes:
- Implements Badger storage, URI options, garbage collection, tests, and benchmarks.
- Extracts differential fuzzing for reuse by persistent drivers.
- Integrates the module into documentation, releases, CI, and Dependabot.
| File | Description |
|---|---|
store/store.go |
Documents the Badger driver. |
store/internal/storetest/storetest.go |
Adds shared differential fuzzing. |
store/bbolt/fuzz_test.go |
Uses the shared fuzzer. |
store/badger/store.go |
Implements Badger persistence. |
store/badger/store_test.go |
Tests storage semantics and recovery. |
store/badger/open.go |
Registers URI configuration. |
store/badger/open_test.go |
Tests URI opening and validation. |
store/badger/fuzz_test.go |
Applies shared contract fuzzing. |
store/badger/bench_test.go |
Adds driver benchmarks. |
store/badger/go.mod |
Defines the separate module. |
store/badger/go.sum |
Locks module dependencies. |
store/badger/testdata/fuzz/FuzzStoreContract/9ce1b12254efbcda |
Adds fuzz corpus input. |
store/badger/testdata/fuzz/FuzzStoreContract/880fe9fa59e5ecf0 |
Adds fuzz corpus input. |
store/badger/testdata/fuzz/FuzzStoreContract/03e3357aa67793e4 |
Adds fuzz corpus input. |
README.md |
Lists Badger as persistent storage. |
doc.go |
Updates package documentation. |
spec/README.md |
Adds Badger to the architecture. |
spec/04-engine.md |
Documents shared driver fuzzing. |
docs/releasing.md |
Covers store-module releases. |
scripts/release.sh |
Discovers and tags store modules. |
.github/workflows/ci.yml |
Tests, fuzzes, and scans Badger. |
.github/dependabot.yml |
Configures Badger dependency updates. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…memtable sizes Badger's conflict detection sees every point read, a missing key included, but of a prefix walk only the seek key and the rows it returned. A RequestCancel committing while a terminality commit was in flight inserted a row the commit's walk never saw, so the commit went through, wrote a terminal record without the request, and deleted the row RequestCancel had reported accepted. The terminality commit now point-reads the cancel key, so the cancel committing first forces a retry that folds it in. TestCancelRacingTerminalityIsKept interleaves the two transactions by hand and fails without the read. parseBytes rejects counts that overflow int64 once the unit is applied, and the package doc counts a nonterminal head as five point reads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…workloads BenchmarkCompare runs ten engine workloads over every in-tree store (and Badger without sync writes, for scale): sequential and burst machine starts and small actions, a retry storm, an unwind wave, an await fan-in, status polling, recovery, and reap. Each pass opens a fresh store and reports per-run throughput, latency, allocations, and disk use. Payloads are random so Badger's block compression does not flatter it, and the suite warns when TMPDIR is tmpfs, where fsync is free. It lives in this module, the only one that can import all three drivers, and is skipped under -short, which CI's benchmark smoke step now passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…close The store comparison found four gaps against bbolt; each has a fix. Group commit. Badger in sync-writes mode syncs its log per committed transaction and shares nothing between concurrent ones: a 1,000-run burst paid about 10,000 syncs where bbolt paid 50. Every write now goes through one goroutine that commits whatever writes are queued in one transaction, the way bbolt's Batch shares an fsync. A write that fails runs alone so its error is its own, and the rest retry as a batch. Turning sync writes off and sharing DB.Sync instead was rejected: memtable rotation does not sync the log it retires, so a power loss could drop a commit that had been reported durable. Blob cache. The engine reads a run whole each time its worker picks it up, and Badger's iterator copies every value it passes, so a retrying run copied its 32 KB input on every attempt. bbolt's cache of in-flight inputs and states moves to store/internal/blobcache and both drivers use it. States get a row of their own beside the operation row, whose value now leads with a flag byte saying whether one is there, so a read fetches them by point reads, from the cache when it can, and walks only the operation rows. Snapshot walks. An iterator opened in a write transaction sorts every pending write of the transaction, which under batching is the whole batch; terminality and the CreateRun dedup path walked there, which made recovery quadratic in the batch. They walk a read-only snapshot now. With one writer the snapshot is what is committed, and the only row of a run another write in the same batch can add is a cancel request, which terminality reads and deletes by key. Compact at close. Deleted rows stay on disk until compaction rewrites their tables, and level 0 is compacted only once several tables pile up, so a quiet store kept what it had reaped. Close compacts level 0. The comparison now reports disk both while the store is open and after Close. Head reads decode rows in place instead of copying them first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



A
driver.Storeon dgraph-io/badger v4, registered as thebadgerscheme:store.Open("badger:///var/lib/app/durable"), withsync_writesandmemtableas query options.Layout. Badger is one ordered key space on an LSM tree, so this is the bbolt layout without the page tricks. A namespace byte leads every key (
aactive rows,ccursor,tterminal,eexpiry index,sslots). An operation row is keyed by step and phase and upserted in place, state inside it; the output sits in the terminal row; nothing is kept beside its row, since Badger moves values past its threshold to the value log by itself. The terminality commit writes the terminal row and deletes the run's stage and slot in the same transaction, so there is no staged bucket and no sweep. Reap walks the expiry index. A head is four point reads.Transactions. Serializable with conflict detection at commit. A commit Badger refuses as a conflict is retried, which is how two
CreateRuns racing for one slot resolve: both read it free, the second to commit is refused, the retry finds the occupant (TestConcurrentCreateRunsOneWins). Badger coalesces concurrent commits into one write batch, the group commit the bbolt driver does by hand. Sync writes are on by default, matching bbolt's durability;WithSyncWrites(false)trades the last moments before a power loss for throughput.WithMemTableSizebounds Badger's buffer and with it the largest transaction; the value threshold follows it. Badger's own logs are discarded unlessWithLoggerroutes them to slog. A value-log GC pass runs once a minute.Its own module. Badger's dependency graph (OpenTelemetry API, flatbuffers, klauspost/compress, ristretto) should enter only the binaries that import the driver, so
store/badgerhas its owngo.mod, released in lockstep like the otel contrib: the release script now discovers tagged modules understore/as well ascontrib/,verifypasses, anddocs/releasing.mdsays so. CI builds, tests, benchmarks, fuzzes, staticchecks, and vulnerability-scans the module; dependabot holds its runtime dependency to patch updates. Two transitive dependencies with uncalled advisories are pinned at their fixed versions.Shared contract test. The differential fuzzer moves out of the bbolt test into
store/internal/storetest(Seed,Fuzz,Canonicalize); both persistent drivers call it, and the badger seed corpus is bbolt's. Twenty seconds of fuzzing found no divergence fromstore/mem.Numbers.
BenchmarkCompareruns ten engine workloads over every in-tree store; medians of seven passes on an NVMe disk (ext4 on LUKS), random payloads. The figures first posted here were taken on tmpfs, where fsync is free, and are withdrawn.The first real-disk run put Badger with sync writes 5 to 35 times behind bbolt under concurrency. Four fixes, all in this PR:
batch.go). Badger in sync-writes mode synced its log per commit and shared nothing: 10,047 syncs on the 1,000-run burst where bbolt made 50. Every write now goes through one goroutine that commits whatever is queued in one transaction, the way bbolt'sBatchshares an fsync; a write that fails runs alone so its error is its own. Sync writes off plus a sharedDB.Syncwas rejected: Badger does not sync the log of a memtable it retires, so a power loss could drop a commit reported durable.store/internal/blobcacheand both drivers use it. States get rows of their own beside the operation row, whose value leads with a flag byte saying whether one exists, so a read fetches blobs by point reads, from the cache when it can; Badger's iterator copies every value it passes. A retrying run allocates 327 KB instead of 3.0 MB (bbolt 307 KB).bbolt still leads on the small-action burst (14,022 vs 7,673; Badger without syncs reaches 10,232, so it is write-path CPU), status polls (758k vs 402k/s, five point reads per head), recovery, and disk held while open.
🤖 Generated with Claude Code