Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/store/store.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ static int configure_pragmas(cbm_store_t *s, bool in_memory) {
if (rc != CBM_STORE_OK) {
return rc;
}
/* Recover stale WAL from previous crash (best-effort).
* PASSIVE never blocks readers and never ftruncates.
* May fail with SQLITE_BUSY if another process holds a lock. */
(void)sqlite3_exec(s->db, "PRAGMA wal_checkpoint(PASSIVE)", NULL, NULL, NULL);
rc = exec_sql(s, "PRAGMA synchronous = NORMAL;");
if (rc != CBM_STORE_OK) {
return rc;
Expand Down Expand Up @@ -725,6 +729,12 @@ void cbm_store_close(cbm_store_t *s) {
return;
}

/* Checkpoint WAL before close to prevent orphan WAL accumulation.
* Best-effort — silently skips if concurrent reader holds a lock. */
if (s->db && s->db_path) {
(void)sqlite3_wal_checkpoint_v2(s->db, NULL, SQLITE_CHECKPOINT_PASSIVE, NULL, NULL);
}

/* Finalize all cached statements */
finalize_stmt(&s->stmt_upsert_node);
finalize_stmt(&s->stmt_find_node_by_id);
Expand Down