persistit: settle MVCC state at the end of Persistit.initialize()#266
Open
vharseko wants to merge 1 commit into
Open
persistit: settle MVCC state at the end of Persistit.initialize()#266vharseko wants to merge 1 commit into
vharseko wants to merge 1 commit into
Conversation
Recovery completes synchronously inside initialize(), but two maintenance tasks were left to background timers: the TransactionIndex active-transaction cache update and CleanupManager's pruneTimelyResources() (first pass no earlier than 1s after startup). Until they ran, residual tree-version state from before a crash could leak into step-based MVCC visibility — e.g. Volume.getTree(name, false) reporting a tree created at step 1 as visible at step 0. Update the active-transaction cache and prune timely resources synchronously at the end of initialize(), before the background managers start, so applications get correct step visibility immediately after initialize() returns. Both calls are idempotent and their cost is bounded (one ATC recompute plus one pass over recovered timely resources). Fixes OpenIdentityPlatform#264.
This was referenced Jul 10, 2026
maximthomas
approved these changes
Jul 11, 2026
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.
Problem
Fixes #264.
After a crash/restart,
Volume.getTree(name, false)(and step-based MVCC visibility checks generally) can return a stale answer until background maintenance happens to run. Recovery itself completes synchronously insidePersistit.initialize(), but two maintenance tasks are asynchronous after it:TransactionIndexactive-transaction-cache updater thread;CleanupManager'spruneTimelyResources(), which fires no earlier than 1 second after startup (MINIMUM_MAINTENANCE_INTERVAL_NSguard:start()sets_lastMaintenance = now, andpoll()skips maintenance until the interval elapses).Until those run, residual tree-version state from before the crash can leak into step-based visibility — e.g. a tree created at transaction step 1 is reported visible at step 0. A fresh
ActiveTransactionCachehas_ceiling = 0, sohasConcurrentTransaction()returnstruefor everything until the firstrecompute(), keeping residual versions alive; and recovery'sDefaultRollbackListener.removeTreeis a TODO no-op whileendTransactionmarks the aborted status withsetMvvCount(0), so tree-lifecycle residue of uncommitted transactions survives recovery and waits for timer-driven pruning. An application callingVolume.getTree(name, false)shortly afterinitialize()has no way to know it must wait for internal maintenance timers.This surfaced as the intermittent CI failure of
TreeTransactionalLifetimeTest.createRemoveByStep(see #260 for the test-side settle workaround and #257 for the review discussion that raised the core-level question).Fix
At the end of
initialize(), afterpruneObsoleteTransactions()and before the background managers start, settle the recovered MVCC state synchronously:The order matters: pruning consults the active-transaction cache. Both calls are idempotent (the CleanupManager performs the same work on its timer), and the cost is bounded — one ATC recompute (no application transactions exist yet at this point) plus one pass over the timely resources touched during recovery.
copyBackPages()already uses the same synchronous idiom before checkpointing.A deeper follow-up candidate noted in #264: implementing the
DefaultRollbackListener.removeTreeTODO so rollback replay prunes tree-lifecycle residue itself, instead of relying on later background pruning.Verification
All green locally (macOS, JDK 21):
TreeTransactionalLifetimeTest— 5/5, includingcreateRemoveByStepRecoveryTest— 11 run, 1 skipped (skipped before the change as well)AccumulatorRecoveryTest— 4/4WarmupTest— 2/2