mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 18:18:03 +00:00
Add manual wal sync before checkpoint in connection Drop
This commit is contained in:
parent
0cfcf0f5cb
commit
9f966910bc
2 changed files with 13 additions and 11 deletions
18
core/lib.rs
18
core/lib.rs
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue