fix(store): use PASSIVE checkpoint to avoid file-shrink under concurrent readers#316
Open
edwardmhughes wants to merge 1 commit intoDeusData:mainfrom
Open
fix(store): use PASSIVE checkpoint to avoid file-shrink under concurrent readers#316edwardmhughes wants to merge 1 commit intoDeusData:mainfrom
edwardmhughes wants to merge 1 commit intoDeusData:mainfrom
Conversation
…ent readers cbm_store_checkpoint() invoked SQLITE_CHECKPOINT_TRUNCATE, the most aggressive mode. When two cbm-mcp processes share a cache dir, one process's TRUNCATE can shrink files while another has them mmap'd, raising SIGBUS on macOS. PASSIVE never blocks readers and never ftruncate()s either file; SQLite still autocheckpoints in PASSIVE mode at 1000-page boundaries, so reclamation is unaffected for single-process users. Recommended by SQLite docs for shared databases: https://www.sqlite.org/pragma.html#pragma_wal_checkpoint
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.
Summary
cbm_store_checkpoint()usedSQLITE_CHECKPOINT_TRUNCATE— the most aggressive checkpoint mode. On success it callsftruncate(fd, 0)on the WAL file. When twocodebase-memory-mcpprocesses share a cache dir, the truncation can shrink files while a sibling has the DB mmap'd through SQLite, raisingSIGBUSon macOS (cluster_pagein past EOF).Switching to
SQLITE_CHECKPOINT_PASSIVEcloses this truncation path:ftruncate()on either fileFrom the SQLite docs on wal_checkpoint:
Changes
src/store/store.c:SQLITE_CHECKPOINT_TRUNCATE→SQLITE_CHECKPOINT_PASSIVEwith explanatory commenttests/test_store_checkpoint.c(new): Verifies WAL is not truncated to zero bytes aftercbm_store_checkpoint()— this test would fail on the old TRUNCATE mode under the right timingMakefile.cbm+tests/test_main.c: Wire new test suiteFixes #314
Related: #277 (orphan-process WAL pin on Windows)