MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / configure_pragmas

Function configure_pragmas

src/store/store.c:419–481  ·  view source on GitHub ↗

Configure connection pragmas. * in_memory — :memory: DB (synchronous OFF, no journal file). * read_only — query-only connection opened SQLITE_OPEN_READONLY. Runs * ONLY non-writing pragmas (foreign_keys, temp_store, * busy_timeout, mmap_size) and SKIPS journal_mode=WAL, * wal_checkpoint and synchronous — those WRITE to the DB/WAL *

Source from the content-addressed store, hash-verified

417 * fail on a read-only DB file / filesystem.
418 * in_memory and read_only are mutually exclusive. */
419static int configure_pragmas(cbm_store_t *s, bool in_memory, bool read_only) {
420 int rc;
421 rc = exec_sql(s, "PRAGMA foreign_keys = ON;");
422 if (rc != CBM_STORE_OK) {
423 return rc;
424 }
425 rc = exec_sql(s, "PRAGMA temp_store = MEMORY;");
426 if (rc != CBM_STORE_OK) {
427 return rc;
428 }
429
430 if (in_memory) {
431 rc = exec_sql(s, "PRAGMA synchronous = OFF;");
432 } else if (read_only) {
433 /* Non-writing pragmas only — see the function comment. */
434 rc = exec_sql(s, "PRAGMA busy_timeout = 10000;");
435 if (rc != CBM_STORE_OK) {
436 return rc;
437 }
438 char mmap_sql[ST_BUF_64];
439 snprintf(mmap_sql, sizeof(mmap_sql), "PRAGMA mmap_size = %lld;",
440 (long long)cbm_store_resolve_mmap_size());
441 rc = exec_sql(s, mmap_sql);
442 } else {
443 rc = exec_sql(s, "PRAGMA busy_timeout = 10000;");
444 if (rc != CBM_STORE_OK) {
445 return rc;
446 }
447 rc = exec_sql(s, "PRAGMA journal_mode = WAL;");
448 if (rc != CBM_STORE_OK) {
449 return rc;
450 }
451 /* Recover stale WAL from previous crash (best-effort).
452 * PASSIVE never blocks readers and never ftruncates.
453 * May fail with SQLITE_BUSY if another process holds a lock. */
454 (void)sqlite3_exec(s->db, "PRAGMA wal_checkpoint(PASSIVE)", NULL, NULL, NULL);
455 rc = exec_sql(s, "PRAGMA synchronous = NORMAL;");
456 if (rc != CBM_STORE_OK) {
457 return rc;
458 }
459 /* #1083: bound the WAL file so a checkpoint-starved log is physically
460 * reclaimed the next time a checkpoint can reset it. Shared/live
461 * checkpoints are PASSIVE (they never ftruncate — see
462 * cbm_store_checkpoint's SIGBUS note), so without a size limit the -wal
463 * file only ever grows; journal_size_limit truncates it back to N bytes
464 * on the next successful
465 * reset. N is far above the healthy WAL (~4 MiB under the default
466 * 1000-page autocheckpoint), so normal indexing never triggers
467 * truncate/regrow churn — it only fires after abnormal growth.
468 * Shared/live paths do NOT use a TRUNCATE checkpoint: truncating the WAL
469 * to zero can raise SIGBUS in a sibling process that has the DB mmap'd
470 * on macOS. Exclusive staging publication seals separately below. */
471 rc = exec_sql(s, "PRAGMA journal_size_limit = 268435456;"); /* 256 MiB */
472 if (rc != CBM_STORE_OK) {
473 return rc;
474 }
475 char mmap_sql[ST_BUF_64];
476 snprintf(mmap_sql, sizeof(mmap_sql), "PRAGMA mmap_size = %lld;",

Callers 2

store_open_internalFunction · 0.85

Calls 2

exec_sqlFunction · 0.85

Tested by

no test coverage detected