feat(store): expose mmap_size via CBM_SQLITE_MMAP_SIZE env#315
Open
edwardmhughes wants to merge 1 commit intoDeusData:mainfrom
Open
feat(store): expose mmap_size via CBM_SQLITE_MMAP_SIZE env#315edwardmhughes wants to merge 1 commit intoDeusData:mainfrom
edwardmhughes wants to merge 1 commit intoDeusData:mainfrom
Conversation
Hard-coded `PRAGMA mmap_size = 67108864` in configure_pragmas() left no path for users running multiple cbm-mcp instances against the same cache to opt out of memory-mapped I/O. On macOS, when one instance's checkpoint or reindex truncates the DB file under another instance's live mmap, accessing the now-missing pages raises SIGBUS, taking the process down. Setting CBM_SQLITE_MMAP_SIZE=0 reverts to read()/pread() I/O, which returns recoverable SQLITE_IOERR instead of crashing the process. - Default unchanged (67108864 / 64 MB). No behavior change for single-instance users. - Malformed values (non-numeric, partial-numeric) fall back to the default rather than failing the store open. - Negative values clamp to 0. - New tests: tests/test_store_pragmas.c covers all five resolver paths plus an integration smoke that opens a file-backed store with mmap disabled. Empirical evidence: 9 SIGBUS crash reports collected on macOS arm64 v0.6.0 in a 14-hour window, all signature 'cluster_pagein past EOF' with stacks bottoming in SQLite btree code under the watcher thread's incremental-index pipeline.
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
Hard-coded
PRAGMA mmap_size = 67108864left no path for users running multiplecodebase-memory-mcpinstances against the same cache to opt out of memory-mapped I/O.On macOS, when one instance's checkpoint or reindex truncates the DB file under another instance's live mmap, accessing the now-missing pages raises
SIGBUS, which takes down the process. SettingCBM_SQLITE_MMAP_SIZE=0reverts toread()/pread()I/O, which returns recoverableSQLITE_IOERRinstead.Changes
src/store/store.c: Extractscbm_store_resolve_mmap_size()— readsCBM_SQLITE_MMAP_SIZE, validates withstrtoll, clamps negative to 0, falls back to default67108864on missing/malformed inputsrc/store/store.h: Declarescbm_store_resolve_mmap_size()for teststests/test_store_pragmas.c(new): 7 tests covering default, zero, explicit value, negative clamp, garbage input, partial garbage, and store-open smoke testMakefile.cbm+tests/test_main.c: Wire new test suiteBehavior
CBM_SQLITE_MMAP_SIZEunsetPRAGMA mmap_size = 67108864CBM_SQLITE_MMAP_SIZE=0PRAGMA mmap_size = 0(disables mmap)CBM_SQLITE_MMAP_SIZE=1048576PRAGMA mmap_size = 1048576Single-instance users: no behavior change.
Fixes #314