From 9f966910bc9dc69e89613da179b3fe205c4a057b Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Mon, 9 Jun 2025 16:04:47 -0400 Subject: [PATCH] Add manual wal sync before checkpoint in connection Drop --- core/lib.rs | 18 +++++++----------- core/storage/pager.rs | 6 ++++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/core/lib.rs b/core/lib.rs index 6a275b383..8368ac661 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -343,6 +343,12 @@ pub struct Connection { cache_size: Cell, } +impl Drop for Connection { + fn drop(&mut self) { + let _ = self.close(); + } +} + impl Connection { #[instrument(skip_all, level = Level::TRACE)] pub fn prepare(self: &Rc, sql: impl AsRef) -> Result { @@ -566,17 +572,7 @@ impl Connection { /// Close a connection and checkpoint. pub fn close(&self) -> Result<()> { - loop { - // TODO: make this async? - match self.pager.checkpoint()? { - CheckpointStatus::Done(_) => { - return Ok(()); - } - CheckpointStatus::IO => { - self.pager.io.run_once()?; - } - }; - } + self.pager.checkpoint_shutdown() } pub fn last_insert_rowid(&self) -> i64 { diff --git a/core/storage/pager.rs b/core/storage/pager.rs index dd77b951c..4121a39b8 100644 --- a/core/storage/pager.rs +++ b/core/storage/pager.rs @@ -821,6 +821,12 @@ impl Pager { .expect("Failed to clear page cache"); } + pub fn checkpoint_shutdown(&self) -> Result<()> { + self.wal.borrow_mut().sync()?; + self.wal_checkpoint(); + Ok(()) + } + pub fn wal_checkpoint(&self) -> CheckpointResult { let checkpoint_result: CheckpointResult; loop {