Skip to content
Merged
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
30 changes: 25 additions & 5 deletions libsql/src/local/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,22 @@ impl Connection {
}

pub(crate) fn wal_checkpoint(&self, truncate: bool) -> Result<()> {
let rc = unsafe { libsql_sys::ffi::sqlite3_wal_checkpoint_v2(self.handle(), std::ptr::null(), truncate as i32, std::ptr::null_mut(), std::ptr::null_mut()) };
let mut pn_log = 0i32;
let mut pn_ckpt = 0i32;
let checkpoint_mode = if truncate {
libsql_sys::ffi::SQLITE_CHECKPOINT_TRUNCATE
} else {
libsql_sys::ffi::SQLITE_CHECKPOINT_PASSIVE
};
let rc = unsafe {
libsql_sys::ffi::sqlite3_wal_checkpoint_v2(
self.handle(),
std::ptr::null(),
checkpoint_mode,
&mut pn_log,
&mut pn_ckpt,
)
};
if rc != 0 {
let err_msg = unsafe { libsql_sys::ffi::sqlite3_errmsg(self.handle()) };
let err_msg = unsafe { std::ffi::CStr::from_ptr(err_msg) };
Expand All @@ -505,6 +520,12 @@ impl Connection {
format!("Failed to checkpoint WAL: {}", err_msg),
));
}
if truncate && (pn_log != 0 || pn_ckpt != 0) {
return Err(crate::errors::Error::SqliteFailure(
libsql_sys::ffi::SQLITE_ERROR,
"unable to truncate WAL".to_string(),
));
}
Ok(())
}

Expand Down Expand Up @@ -596,17 +617,16 @@ impl Connection {
)
};

if conflict != 0 {
return Err(errors::Error::WalConflict);
}
if rc != 0 {
return Err(errors::Error::SqliteFailure(
rc as std::ffi::c_int,
"wal_insert_frame failed".to_string(),
));
}

if conflict != 0 {
return Err(errors::Error::WalConflict);
}

Ok(())
}

Expand Down
Loading