Repository navigation
Store backends: free the writer lane after quarantine, PG lane barrier, checkpoint fullfsync (#2 #3 #10 #11 #20) - #764
Merged
yifanxuaaa merged 3 commits intoNov 23, 2026
Conversation
…G lane Fixes the Store backend liveness findings #2, #3, #10 and #20 of the LayerFS 2.0.0 review. (#11 follows in its own commit.) #2 SQLite: a quarantined Session closes its connection while it still holds the Store directory flock (the job's own writer, or a held LaneHold around nested work), then releases the flock. sqlite3_close rolls back any write transaction the uncertain attempt left open, so SQLite teardown still precedes advisory release, and other Sessions and processes take the lane at once instead of waiting until the Session drops (process exit for a daemon). The checkpoint thread's connection, which may then be SQLite's last, closes with NO_CKPT_ON_CLOSE. The Session stays quarantined. #20 SQLite: run_decided waits for the cross-process flock before it takes the Session state mutex, so diagnostics() no longer queues behind another process's lane. The FIFO turn still serializes the Session; the Store identity is now checked with the lane held. #3 PostgreSQL: quarantine closes the session's ordinary connection. Corrected scope: a transaction the server aborts with an error already releases its row locks, so the store_lane row was not held in that case. What stayed until process exit was the backend with its session advisory keys, and every row lock when the uncertain outcome left the transaction live. SQLSTATE classes 21 and P0 (P0001 from pack_immutable) are now definite Integrity failures. #10 PostgreSQL: a lane barrier. Every writer that locks store_lane takes and at once releases an exclusive two-key advisory lock in the same batch; a write nested in a held lane holds that key shared from BEGIN and checks before COMMIT that the lane connection is still in the transaction recorded at hold_lane (one round trip). A lost lane rolls the nested write back and answers Closed. A new holder therefore cannot read until the previous holder's in-flight nested write ends, which keeps the head check and the object_location existence probe exact without a schema change. The branch-advance SQL is untouched (v2-commit-path adds its predicate there). Tests: new sqlite_quarantine_release (run and in-lane cases) and postgresql_lane_liveness (#3, #10), a foreign-lane case in diagnostics_during_lane (#20), SQLSTATE cases in postgresql_sqlstate. Each new case fails on the parent 343c59b and passes here. postgresql_commit_round_trips now counts 15 round trips for the lane + head + commit_branch phase (the lane check). No test deleted. diagnostics_during_lane joins the CI SLOW list (6.06 s). Docs: store/sqlite.md (write sequence, Quarantine), store/postgresql.md (quarantine, SQLSTATE classes, Lane barrier), store/README.md (error table, demonstrations). Production LOC: 206,537 -> 206,708 (delta +171) core 40,988 -> 40,988 (0) engine 95,899 -> 96,070 (+171) layerfs-persistence +171 control 59,325 -> 59,325 (0) api 10,325 -> 10,325 (0) reference absent (retired R9c; last counted 65,417 at tree 498dd19) Method: tools/production_loc.py --detail on parent 343c59b and the staged tree Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The checkpoint thread's connection set fullfsync=0 and left checkpoint_fullfsync at SQLite's default 0; only the session's own connection set it to 1. With wal_autocheckpoint=0 nearly every checkpoint runs on that thread, so on macOS each pass synced the Store file with plain fsync before the writer could restart the log over the copied frames. It now sets checkpoint_fullfsync=1, reads it back, refuses the open on a mismatch, and reports it as ConnectionProfile:: checkpoint_thread_checkpoint_fullfsync. Cost, measured on the macOS host, 2026-11-23, one sample each: the kept_objects_sort_files test target took 27.7 s at the previous commit and did not finish within the 120 s ceiling with this change (its last case, a 9,200-page mark, was still running). Linux ignores the setting. Kept as its own commit so it can be dropped if the owner prefers the speed. Tests: background_checkpoint and sqlite_publication assert the read-back. Docs: store/sqlite.md (checkpoint thread row, checkpoint rule with the cost). Production LOC: 206,708 -> 206,729 (delta +21) core 40,988 -> 40,988 (0) engine 96,070 -> 96,091 (+21) layerfs-persistence +21 control 59,325 -> 59,325 (0) api 10,325 -> 10,325 (0) reference absent (retired R9c; last counted 65,417 at tree 498dd19) Method: tools/production_loc.py --detail on parent 7c2f2b6 and the staged tree Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner decision, 2026-11-23: F_FULLFSYNC applies only to the idle and final checkpoint, not to every routine pass. With a31a742, three write-heavy test targets passed the 120 s ceiling on macOS (persistence kept_node_closure, kept_objects_sort_files, store-service scale_lineage_cap). The checkpoint thread's connection now sets checkpoint_fullfsync=0, reads it back, and refuses the open on a mismatch; ConnectionProfile::checkpoint_thread_checkpoint_fullfsync reports 0. The idle TRUNCATE (checkpoint_idle), checkpoint_holding and the last close already run on the session's own connection, which sets checkpoint_fullfsync=1 (profile.rs). Neither connection changes its setting after open. Remaining window, documented in store/sqlite.md: on macOS, fsync does not flush the drive cache. Once a routine pass has copied every frame, the next write restarts the log over them, and a power loss can then lose database pages. SQLite syncs the Store file during a checkpoint only when that checkpoint copies a frame. So an idle TRUNCATE or last close that finds every frame copied truncates or deletes the log without any sync, and the pages from routine passes then have no F_FULLFSYNC behind them. Linux is unaffected. No power-loss guarantee is claimed until layerfs-project#155 §7.5/§7.6. Tests: background_checkpoint asserts the session reads back 1 and the thread 0, that a routine pass leaves the log in place, and that the idle checkpoint (session connection only) truncates it. sqlite_publication's Normal case asserts the thread reads back 0. No test deleted. Timings on the macOS host, 2026-11-23, one sample each, 120 s cap, LAYERFS_CONSTRUCTION_WORKERS=1, 1-min load 5.5-11.9: kept_node_closure 6.7 s, kept_objects_sort_files 35.9 s, scale_lineage_cap 39.6 s, background_checkpoint 1.1 s, sqlite_publication (Normal case) 0.7 s, sqlite_quarantine_release 0.7 s, diagnostics_during_lane 3.7 s. Production LOC: 206,729 -> 206,729 (delta 0) core 40,988 -> 40,988 (0) engine 96,091 -> 96,091 (0) control 59,325 -> 59,325 (0) api 10,325 -> 10,325 (0) reference absent (retired R9c; last counted 65,417 at tree 498dd19) Method: tools/production_loc.py --detail on parent a31a742 and the staged tree 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.
Fixes the Store backend liveness and durability findings #2, #3, #10, #11 and #20 from the LayerFS 2.0.0 review (
layerfs_v2_0_0at 343c59b). Every finding was re-checked in code before it was fixed. #3 was partly wrong, see below.#11 narrowed to the idle/final checkpoint (owner decision, 2026-11-23)
a31a74243fhad the checkpoint thread sync every routine pass withF_FULLFSYNCon macOS. Merged with the other review PRs, that alone pushed three write-heavy targets past the 120 s cap on macOS:kept_node_closurekept_objects_sort_filesscale_lineage_capThe owner chose to narrow it. With
fb3b37bdf4:fsync. The thread's connection setscheckpoint_fullfsync=0and reads it back.checkpoint_holdingand the last close run on the session's own connection, which keepscheckpoint_fullfsync=1.Remaining window (macOS only, documented in
store/sqlite.md):fsync, which does not flush the drive cache.Linux is unaffected. No power-loss guarantee is claimed until layerfs-project#155 §7.5/§7.6.
Measured with
fb3b37bdf4on the macOS host (2026-11-23, one sample each, 120 s cap, 1-min load 5.5 to 11.9):kept_node_closurekept_objects_sort_filesscale_lineage_capbackground_checkpointsqlite_publication(Normal case)sqlite_quarantine_releasediagnostics_during_laneWhat changed
#2 SQLite: a quarantined writer kept the directory
flockuntil process exit.A quarantined Session now closes its connection while it still holds the lane, then releases the lane. The lane is held either by the job's own writer or by a
LaneHoldaround nested work.sqlite3_closerolls back the write transaction that the uncertain attempt left open, so SQLite teardown still comes before the advisory release. The checkpoint thread's connection may then be SQLite's last; it closes withNO_CKPT_ON_CLOSEinstead of checkpointing outside the lane. The Session stays quarantined.#20 SQLite: the
flockwait happened under the Session state mutex.run_decidednow waits for the cross-process lock before it takes the state mutex, sodiagnostics()no longer queues behind another process's lane. The FIFO turn still serializes the Session. The Store identity is now checked with the lane held.#3 PostgreSQL: a quarantined session kept its connection.
Quarantine now closes the session's ordinary connection. The review overstated one part of this finding. When the server raises an error, PostgreSQL aborts the transaction at once and releases its row locks, so in that case
store_lanewas not held. Observed: the backend satidle in transaction (aborted)with a NULLbackend_xid. These parts were real:store_laneincluded.SQLSTATE classes
21andP0(includingP0001from thepack_immutabletrigger) are now definiteIntegrityfailures.58xxxandXXcodes stay unknown.#10 PostgreSQL: in-lane writes relied on a lock held by another connection.
This adds a lane barrier and needs no schema change:
store_lanetakes and immediately releases an exclusive two-key advisory lock, in the same batch.BEGIN. BeforeCOMMITit checks that the lane connection is still in the transaction recorded athold_lane, which costs one round trip.Closed(OwnershipUnavailable).A new lane holder therefore cannot read anything until the previous holder's in-flight nested write has finished. That keeps the head check and the
object_locationexistence probe exact. The branch-advance SQL is untouched: v2-commit-path adds itshead_commit_id = expectedpredicate there.#11 SQLite: the checkpoint thread's
checkpoint_fullfsyncwas never set or checked.The thread's setting is now applied explicitly and read back, and the open is refused on a mismatch. It is reported as
ConnectionProfile::checkpoint_thread_checkpoint_fullfsync. After the owner's narrowing it is 0, and F_FULLFSYNC stays on the session connection, which runs the idle and final checkpoints (see above).Tests
New tests:
sqlite_quarantine_release: the run case and the in-lane case.postgresql_lane_liveness: perf(fs): optimize bytesToHex encoding #3 and [v0.1.1] Admit mixed-size namespace-v2 in the existing family #10.diagnostics_during_lane([v0.1.2][5] Rebuild three file-edit benchmark families as SDK-only size-invariance suites #20).postgresql_sqlstate.background_checkpointchecks that the session reads back 1 and the thread 0, that a routine pass leaves the log in place, and that the idle checkpoint, which only the session connection runs, truncates it.sqlite_publicationchecks the thread read-back.The uncertain SQLite outcome comes from ordinary behaviour: a raw connection adds a trigger that calls an unknown function, which makes the Store's
UPDATE store_policyfail with a genericSQLITE_ERROR. No test-only code is insrc/.Changed assertion:
postgresql_commit_round_tripsnow counts 15 round trips for the lane + head + commit_branch phase instead of 14; the extra one is the lane check. No test was deleted.diagnostics_during_lanejoins the CISLOWlist (6.06 s).Checks (macOS host, Rust 1.85.1, private worktree target)
cargo test -p layerfs-persistence --all-targets --no-run: builds with no warnings.cargo clippy -p layerfs-persistence --all-targets -- -D warnings: clean.rustfmt --checkon the changed files: clean.cargo fmt --all --checkreports drift only in files this PR does not touch, all already on the base.tools/check_product_boundary.py: PASS. Tools unit tests: 181 OK.layerfs-persistencetest binaries, 120 s cap each, against a privatepostgres:17server, withLAYERFS_CONSTRUCTION_WORKERS=1.a31a74243f: 88 pass andkept_objects_sort_filesreaches the cap (the [v0.1.1] Pipeline cold namespace initialization through bounded direct admission #11 cost above).fb3b37bdf4: the seven targets in the [v0.1.1] Pipeline cold namespace initialization through bounded direct admission #11 table pass. The full 89-binary run was not repeated.acquisition_batching,acquisition_disposal,acquisition_reads,space_reclamation,sqlite_compact_capacity,sqlite_compact_matrix,sqlite_pack_selection,sqlite_publication(only its Normal case ran),sqlite_recoveryandsqlite_reference_acquisition.Gaps
Off (default)row in postgresql.md'ssynchronous_committable (review V-DOC-1) is unchanged.Production LOC: 206,537 -> 206,729 (delta +192) over the range. Per commit: +171 for
7c2f2b6276, +21 fora31a74243f, 0 forfb3b37bdf4. All in engine/layerfs-persistence; core, control and api are unchanged.🤖 Generated with Claude Code