fix(store): opportunistic PASSIVE WAL checkpoint to bound the content-store WAL (#985)#988
Open
alove20 wants to merge 1 commit into
Open
fix(store): opportunistic PASSIVE WAL checkpoint to bound the content-store WAL (#985)#988alove20 wants to merge 1 commit into
alove20 wants to merge 1 commit into
Conversation
…re WAL (mksglu#985) closeDB()'s wal_checkpoint(TRUNCATE) is the only WAL-truncation path and only runs on graceful shutdown. A server killed hard (crash, reboot, SIGKILL, or a Windows parent-death before the lifecycle guard fires) never reaches it, so under multi-session load the shared per-project content-store WAL grows unbounded — the reader-starvation failure ADR 0001 attributes to mksglu#560. Add startWalCheckpointTimer(db, intervalMs): an .unref()'d periodic PASSIVE checkpoint. PASSIVE never blocks and adds no locking, so it stays within ADR 0001's multi-writer contract (no EXCLUSIVE, no lockfile). The server starts it for the content store (default 60s, CONTEXT_MODE_WAL_CHECKPOINT_MS tunes it, 0 disables); ContentStore.close()/cleanup() stop it. Adds unit coverage.
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.
Addresses the WAL-bloat / reader-starvation half of #985, within the constraints of ADR 0001 (no per-DB locking).
Problem.
closeDB()'swal_checkpoint(TRUNCATE)is the only WAL-truncation path and only runs on graceful shutdown. A server killed hard — crash, reboot, SIGKILL, or a Windows parent-death before the lifecycle guard fires — never reaches it. Under multi-session load the shared per-projectcontent/<hash>.dbWAL then grows unbounded (observed 30 MB+ regrowth within an hour; the same reader-starvation failure ADR 0001 attributes to #560, where a lingering reader lock prevents any checkpoint from resetting the WAL).Change. Add
startWalCheckpointTimer(db, intervalMs)— an.unref()'d periodicPRAGMA wal_checkpoint(PASSIVE). PASSIVE reclaims whatever WAL frames it can between reader gaps; it never blocks and adds no locking, so it stays fully within ADR 0001's multi-writer contract (no EXCLUSIVE, no lockfile). The server starts it for the content store only (session DBs are per-session and uncontended); default 60 s,CONTEXT_MODE_WAL_CHECKPOINT_MStunes it (0 disables).ContentStore.close()/cleanup()stop the timer.Complements the parent-death fix (#982 / #987): that removes the lingering-reader root cause on graceful paths; this bounds the WAL on the hard-exit paths that never checkpoint at all.
Adds
tests/util/wal-checkpoint-timer.test.ts(fires PASSIVE on interval, stop works, disabled on non-positive/non-finite, swallows pragma errors, and asserts it never issues TRUNCATE/EXCLUSIVE). Full build + typecheck + store/timer suites green.