Repository navigation
beatree: skip the unread staging map during sync - #999
Draft
citizen-stig wants to merge 5 commits into
Draft
citizen-stig wants to merge 5 commits into
citizen-stig wants to merge 5 commits into
Conversation
…staging it Readers are excluded while a commit runs (every reader takes access_lock for reading and Overlay::commit holds it for writing), so the imbl staging map built in Tree::commit was never read. Collect and sort the changeset and pass it to ops::update; the leaf stage takes the values by move instead of cloning them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
citizen-stig
marked this pull request as draft
November 24, 2026 13:48
Session::finish checked that actuals are strictly sorted only under debug_assertions. Without them a repeated key went through: the trie kept the first write while the value store kept another, so the committed root disagreed with the stored values. Return an error instead. Reported as A4-3 and A7-10 in the 2026-11-23 audit. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017wb3qH3B6abyFmZUHWkjxH
The update assumes each key appears once. The staging map used to collapse repeats; now the changeset goes straight to the update, so check for them after sorting and fail the sync instead of writing a duplicate cell. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017wb3qH3B6abyFmZUHWkjxH
Since changes go straight to the update, primary_staging is always empty and secondary_staging always None. Drop both, their lookups, and the staging merge in BeatreeIterator, including the unsafe OrdMap cursor. Lookups and read transactions see the tree as of the last finished sync; say so in the docs. Explain why prepare_sync keeps the write lock. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017wb3qH3B6abyFmZUHWkjxH
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.
What changed
beatree::SyncController::begin_syncnow collects and sorts the changeset and passes it straight toTree::prepare_sync→ops::update→leaf_stage::run. The leaf stage takes the values by move instead of cloning them.Tree::commitandShared::take_staged_changesetare removed. The staging fields stay, so the read path is unchanged.Why it is faster
Every sync inserted its changeset into an
imbl::OrdMapstaging map before any leaf could be written: about 11 ms of CPU for 40k entries, on the critical path. Nothing reads that map during a commit, because every reader takesaccess_lockfor reading andOverlay::commitholds it for writing for the whole commit. The rollback session, which skips the guard, runs on the thread that already holds the write lock.Measured
Stock benchtop, ~33.5M keys, 39k random writes per block (1/3 inserts),
commit_concurrency8, 64M preallocated buckets, rollback on:Same final root.