Skip to content

store: write the manifest before the beatree pages - #1001

Draft
citizen-stig wants to merge 2 commits into
thrumdev:masterfrom
citizen-stig:autoresearchresult-sov-commit-1s-04-early-manifest
Draft

citizen-stig wants to merge 2 commits into
thrumdev:masterfrom
citizen-stig:autoresearchresult-sov-commit-1s-04-early-manifest

Conversation

@citizen-stig

Copy link
Copy Markdown
Contributor

What changed

  • Each sync writes its value changeset to a new value_log file (store/value_log.rs, ~2 MB, fdatasync), alongside the bitbox WAL and the rollback delta.
  • The manifest is written as soon as those three are durable. It keeps the previous beatree state and marks the log as pending: meta version 2, with a u32 after the 64-byte Meta that is read only for version ≥ 2.
  • The hash-table writeout then runs while the beatree update finishes, through its own I/O pool (ht_io_pool), so beatree I/O doesn't queue behind 40k hash-table writes.
  • A second manifest write records the new beatree state.
  • Store::open replays a pending log onto the recorded beatree state. The beatree is copy-on-write, so pages written by an interrupted sync are free in that state.
  • Rehash preserves the marker. The PostMeta panic point now sits after the beatree pre-meta wait, so nothing is still writing in the background.

Why it is faster

The hash-table writeout is protected by the WAL, which is durable early, but it also waited for the beatree update before the manifest could be written. Now the two overlap. Every write is still durable before commit returns.

Measured

On its own with stock benchtop, the change is within noise (154 → 153 ms): the beatree's random leaf writes compete with the hash-table writes for the same IOPS. Combined with the staging-bypass and consecutive-leaves PRs, a node-profile benchmark went from 140.2 to 118.5 ms, and stock benchtop reached 90.4 ms with all four PRs (master: 152 ms).

Trade-offs

  • About 2 extra fsyncs and a 2 MB sequential write per commit.
  • Databases written by this version can't be opened by older code (meta version 2).

Tests

cargo test --workspace passes. wal_recovery_test_post_meta_swap now exercises the replay.

🤖 Generated with Claude Code

codex and others added 2 commits November 23, 2026 16:37
… changes

The manifest used to wait for the beatree update (about 60 ms) before the
hash-table pages could be written. Now each sync writes its value changeset
to a small log (about 2 MB) alongside the hash-table WAL and the rollback
delta, and writes the manifest once those are durable. The manifest keeps
the previous beatree state and marks the log as pending (meta version 2).
The hash-table writeout then runs while the beatree update finishes, and a
second manifest write records the new beatree state. On open, a pending log
is applied to the recorded beatree state; the beatree is copy-on-write, so
pages written by the interrupted sync are free in that state.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants