From e94fe5ff8cb0c9fea84c066bbaeb96546e98b1cc Mon Sep 17 00:00:00 2001 From: DJ Majumdar Date: Wed, 25 Mar 2026 20:32:02 -0700 Subject: [PATCH] fix: explicitly checkpoint WAL on shutdown to ensure consolidation pool.close() only triggers a passive checkpoint which can leave WAL files unconsolidated. Use PRAGMA wal_checkpoint(TRUNCATE) to force all WAL data back into the main database before closing. --- src/metadata/sqlite.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/metadata/sqlite.rs b/src/metadata/sqlite.rs index 73bf83a..2a33dd1 100644 --- a/src/metadata/sqlite.rs +++ b/src/metadata/sqlite.rs @@ -836,6 +836,14 @@ impl MetadataStore { /// Gracefully close the metadata store, flushing WAL to the main database. pub async fn close(&self) { + // Explicitly checkpoint and truncate the WAL before closing. + // pool.close() alone only passively checkpoints which may leave WAL files behind. + if let Err(e) = sqlx::query("PRAGMA wal_checkpoint(TRUNCATE)") + .execute(&self.pool) + .await + { + tracing::warn!("WAL checkpoint failed during shutdown: {e}"); + } self.pool.close().await; }