refactor: extract FreemapRecycle (structural recycle + freemap commit/alloc/persist/reclaim) — extraction PR 4 - #78
Merged
Conversation
…m) as an owned unit
🚦 Bench results: PR vs main
Per-scenario detail (4 metrics × cells)document-store
mutation-log
ycsb-a
ycsb-b
|
This was referenced Jun 23, 2026
Merged
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 4 of the
transaction.rsextraction (after #76, #77) — the hardest and most durability-critical step. ExtractsFreemapRecycle: the structural-page recycle cluster and the freemap commit/alloc/persist/reclaim machinery, out ofTransactionManagerinto an owned unit. Pure behavior-preserving refactor; the existing suite is the oracle.What changed
FreemapRecycle(intransaction/freemap.rs) now owns the five fieldshint/structural_reuse/structural_superseded/pending_structural_frees/session_owned. No code outsidefreemap.rstouches them directly (surface-checked).take_tree/cow_alloc_into/put_treereplacestake_freemap_tree/cow_alloc/put_freemap_tree. The six allocation call sites (data-page insert,ht_insert, 3× membership staging, the update/delete path) keep the same one-tree-per-insert lifetime — the alloc closure operates on a single persistentFreeMapTreewhosesession_owneddedup accumulates across the multiple COWs of one structure insert. Only the five fields moved behind the interface, not the tree's lifetime.mark_free_committed_path,persist,reclaim_orphans) becameFreemapRecyclemethods takingcache: &mut PageCache+roots: &mut Roots.persisttakestxn_freed_pages: &[u64](the oldmem::take/restore dance — only a borrow-checker dodge — is gone).reclaim_orphanstakessavepoint_active+superblock_countparams; the savepoint guard de-inversion issavepoint_active = !savepoints.is_empty().begin/commit/rollbacklifecycle hooks delegate toFreemapRecycle; the per-stream reasoning (one-commit-defer rotation, why rollback leavespendingintact, the two-free-streams) was relocated fromlifecycle.rsinto the FreemapRecycle docs (single source of truth).Verification
cargo test→ 578 passing, 0 failed (273 chisel-lib) — identical to the pre-refactor baseline; all named durability oracle tests green (I18persist_freemap_does_not_reuse_committed_live_pages, thestructural_recycle_*defer family, thereclaim_freemap_orphans_*sweep tests, the I28 commit-drain).cargo clippy --workspace --all-targets -- -D warningsclean;cargo fmt --checkclean;pytest→ 119 passing.cow_alloc/structural_extendbyte-identical, theput_tree-before-?error-path ordering preserved at every site, and the one-continuous-cache-borrow change equivalent. Only NITs surfaced — one unobservable internal-state diff in persist's error path (behind the I1 poison wall) and one relocated comment that is more accurate than the original.Next: Task 5 (CommitProtocol), one PR off updated
main.