Compare commits

...

1 Commits

Author SHA1 Message Date
link2xt
dfffd90686 feat(sql): truncate WAL on stop_io() 2023-12-05 00:46:43 +00:00
2 changed files with 20 additions and 0 deletions

View File

@@ -423,6 +423,9 @@ impl Context {
/// Stops the IO scheduler.
pub async fn stop_io(&self) {
self.scheduler.stop(self).await;
if let Err(err) = self.sql.checkpoint(self).await {
error!(self, "Failed to checkpoint the database: {err:#}.");
}
}
/// Restarts the IO scheduler if it was running before

View File

@@ -131,6 +131,23 @@ impl Sql {
// drop closes the connection
}
/// Flushes the WAL file.
pub(crate) async fn checkpoint(&self, context: &Context) -> Result<()> {
let busy = self
.call_write(move |conn| {
let busy = conn.query_row("PRAGMA wal_checkpoint(TRUNCATE)", (), |row| {
let busy: bool = row.get(0)?;
Ok(busy)
})?;
Ok(busy)
})
.await?;
if busy {
warn!(context, "Failed to checkpoint WAL");
}
Ok(())
}
/// Imports the database from a separate file with the given passphrase.
pub(crate) async fn import(&self, path: &Path, passphrase: String) -> Result<()> {
let path_str = path