Repository navigation
#817 DrainPendingClusterFinalizations never disposed its accessors, so the checkpoint gate never opened - #825
Merged
Merged
Conversation
…o the checkpoint gate never opened The method opened a ChunkAccessor over the cluster segment and another over the transient segment, read each drained chunk through GetChunkAddress(chunkId, dirty: true), and returned without disposing either. That dirty flag registers an ActiveChunkWriter on the chunk's page and the registration is released only by CommitChanges or Dispose, so every drained cluster left one behind permanently. Measured on the SpaceBattle demo: 458 of 458 skipped pages still held writer registrations with the simulation stopped, one of them eleven. The consequence lands three layers away. CP-11 skips any page with ActiveChunkWriters non-zero, and CK-03 gates the whole cycle when even one page is skipped, so the coverage gate never opened again for the life of the process: CheckpointLSN never advanced, CK-04 recycled no WAL segment, and the log grew at the full write rate until the writer stalled and the engine raised WalBackPressureTimeout from inside the tick fence. Twenty-two gigabytes across eighty-six segments in four minutes, against a hundred-and-twenty megabyte data file. Adding using to both accessors takes segments recycled from 0 to 11 and consecutive gated cycles from 40 to 0 on the same workload. CP-13 records the invariant that was missing rather than merely absent from the tests. CP-11 says when ActiveChunkWriters may be observed non-zero and CP-12 says when the decrement may be deferred; neither required that it ever happen, which is why a leaked registration was legal and why five thousand tests walked past it. ClusterFinalization_ReleasesEveryActiveChunkWriter verifies it by emptying a cluster and asserting no page holds a registration once nothing is in flight, and it is red without the fix. Quiescence is the whole trick: while a workload is running a leaked counter is indistinguishable from a busy one. ChangeSetDirtyMarkConservationTests lands quarantined and deliberately red against #824, a second and unrelated counter defect found in the same session. DirtyCounter inflates by K-1 every checkpoint cycle when K units of work touch one page, so pages become permanently unevictable and the page cache eventually starves. The oracle proves it in a hundred and nineteen milliseconds where the demo needs half an hour, and its remarks record the fix that looks right and is not: acking the observed DirtyCounter at capture turns all four arms green and breaks three durability tests, because it consumes marks still owned by in-flight units of work, which is the lost write of #385. The four page-counter census helpers on PagedMMF exist for those assertions and are read only with the workload quiescent.
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 #817. Found while hardening with the SpaceBattle demo.
The bug
ArchetypeClusterState.DrainPendingClusterFinalizationsopened twoChunkAccessors, read each drained chunk viaGetChunkAddress(chunkId, dirty: true), and returned without disposing either. Thatdirtyflag registers anActiveChunkWriteron the chunk's page, and the registration is released only byCommitChanges/Dispose— so every drained cluster left one behind permanently.The consequence lands three layers away, in a subsystem that never mentions clusters:
22 GB of WAL across 86 segments in four minutes, against a 120 MB data file.
Evidence
Measured with the workload quiescent — tick loop stopped, no transaction open:
Every skipped page still held registrations with nothing running; one held eleven. Isolated to migration by A/B (identical config, one giant cell ⇒ zero migrations):
cellSize=2000cellSize=200000The fix and its effect
Two
usings. Same workload, 40 checkpoints, 51 migrations/tick:CP-13 — the invariant that was missing, not just untested
CP-11 constrains when ACW may be observed non-zero; CP-12 when the decrement may be deferred. Neither required that it ever happen. That is why a leaked registration was legal and why 5 000+ tests walked past it.
ClusterFinalization_ReleasesEveryActiveChunkWriterverifies it — empties a cluster, then asserts no page holds a registration once nothing is in flight. Red without the fix (Expected: 0, But was: 1). Quiescence is the whole trick: while a workload runs, a leaked counter is indistinguishable from a busy one.Also included: a quarantined oracle for #824
ChangeSetDirtyMarkConservationTestslands deliberately red under[Category("Quarantine")], tracking #824 — a second, unrelated counter defect found in the same session.DirtyCounterinflates by K−1 per checkpoint cycle when K units of work touch one page, so pages become permanently unevictable and the cache eventually starves withPageCacheBackpressureTimeout.It proves that in 119 ms where the demo needs half an hour, and its remarks record the fix that looks right and is not: acking the observed
DirtyCounterat capture turns all four arms green and breaksFlipByteInPage_IsDetected,Truncation_IsDetectedandCleanShutdownReopenDoesNotRederive— it consumes marks still owned by in-flight units of work, which is #385's lost write. Whoever takes #824 starts with a gate that rejects the naive fix instead of a demo that takes thirty minutes to say so.The four page-counter census helpers on
PagedMMFexist for these assertions and are read only at quiesce.Verification
--filter "TestCategory!=Quarantine": 5460 passed, 0 failed, 16 skippedClusterMigrationTests: 25/25scripts/pre-push.sh --policy: passedNot included: the demo itself (
demo/SpaceBattle) and the investigation scaffolding used to find this — ACW/DC stack-trace ledgers, skip-cause counters, skip-identity diagnostics. They did their job and shouldn't outlive it; the reproduction is recorded in #817 and #824.