Add manual wal sync before checkpoint in connection Drop

This commit is contained in:
PThorpe92 2025-06-09 16:04:47 -04:00 committed by Jussi Saurio
parent 0cfcf0f5cb
commit 9f966910bc
2 changed files with 13 additions and 11 deletions

View file

@ -343,6 +343,12 @@ pub struct Connection {
cache_size: Cell<i32>,
}
impl Drop for Connection {
fn drop(&mut self) {
let _ = self.close();
}
}
impl Connection {
#[instrument(skip_all, level = Level::TRACE)]
pub fn prepare(self: &Rc<Connection>, sql: impl AsRef<str>) -> Result<Statement> {
@ -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 {

View file

@ -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 {