refactor: extract the commit protocol (3-fsync sequence) into commit.rs — extraction PR 5 - #79
Merged
Merged
Conversation
🚦 Bench results: PR vs main
Per-scenario detail (4 metrics × cells)document-store
mutation-log
ycsb-a
ycsb-b
|
Xof
added a commit
that referenced
this pull request
Jun 23, 2026
…ion deferred (I141) (#80) The 2026-06-22 review's god-module SMELL was worked through four unit extractions (SlotPacker #77, FreemapRecycle #78, CommitProtocol #79, FaultInjector #76); the final StagingTxn extraction is deliberately deferred. The candidate-prepare/install staging vocabulary is shared across allocate_inner (staging.rs) and update_inner/delete_inner (mutate.rs), so a context-based extraction cannot be contained to staging.rs without dragging the delicate mutation paths through a mechanical wrapper change. Recorded as future work to be done incrementally if/when those paths are touched, not re-triggered from the SMELL alone.
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.
Task 5 of the
transaction.rsextraction (after #76, #77, #78). Lifts the 3-fsync commit protocol — the body ofcommit_inner— out oflifecycle.rsinto a stateless function-moduletransaction/commit.rs. The most durability-critical sequence in the engine; moved VERBATIM, only field-access paths changed.What changed
commit.rs(new):CommitCtx<'a>bundles the ten pieces of manager state the protocol touches (cache as&RefCell, the rest&mut), andrun_commit(ctx)holds the load-bearing sequence: I27 savepoint-freed flatten → I28 pre-drain flush → freemap persist → main flush →txn_counterbump → superblock build → write to the inactive slot → superblock fsync → roots/packer/freemap promotion. Stateless — owns nothing.commit_inner(lifecycle.rs) is now a thin caller constructing the ctx. The publiccommit()poison-on-error wrapper is unchanged.TransactionManager::persist_freemapwrapper (its only caller wascommit_inner) was removed;run_commitinlinesfreemap.persist(...)directly, and the wrapper's "Step 0" reasoning was relocated into that scope.Why
CommitCtxtakescache: &RefCell<PageCache>The protocol deliberately drops and re-acquires the cache borrow three times (the I28 pre-drain flush and
persisteach borrow-and-release before the held borrow for steps 1-4). Passing theRefCellpreserves the original borrow lifetimes — a single&mut PageCachewould force one continuous borrow andpersist's ownborrow_mutwould panic. The three borrow scopes stay separate.Verification
cargo test→ 578 passing, 0 failed (273 chisel-lib) — identical to the pre-refactor baseline.tests/spillway_integration.rsfsync_delta == 3(I28 pre-drain + main + superblock) — green; the I18 guardrailpersist_freemap_does_not_reuse_committed_live_pages— green.cargo clippy --workspace --all-targets -- -D warningsclean (confirms no dead code from the removed wrapper);cargo fmt --checkclean;pytest→ 119 passing.run_commitstatement-by-statement against the originalcommit_inner: byte-identical ordering, onlyself.X→ctx.Xplus deref-assigns, all invariant comments (I27/I28/I119/the step descriptions) preserved verbatim.Next: Task 6 (StagingTxn — the BUG#2 atomic
allocate_innerprepare/install), the final extraction, one PR off updatedmain.