mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-03 21:45:51 -04:00
fix(sqlite): Add WAL checkpoints when vacuuming
For some reason, the automatic WAL checkpoints don't seem to be working as expected. Since we should periodically run VACUUM operations, we might as well add checkpoints before vacuuming (so the WAL size is reset and can grow to fit the whole DB) and after (so we clean up after that).
This commit is contained in:
committed by
Jorge Martin Espinosa
parent
5dcd877dcd
commit
3be6fb1a80
@@ -187,6 +187,7 @@ pub(crate) trait SqliteAsyncConnExt {
|
||||
///
|
||||
/// Only returns an error in tests, otherwise the error is only logged.
|
||||
async fn vacuum(&self) -> Result<()> {
|
||||
self.wal_checkpoint().await;
|
||||
if let Err(error) = self.execute_batch("VACUUM").await {
|
||||
// Since this is an optimisation step, do not propagate the error
|
||||
// but log it.
|
||||
@@ -198,11 +199,19 @@ pub(crate) trait SqliteAsyncConnExt {
|
||||
return Err(error.into());
|
||||
} else {
|
||||
trace!("VACUUM complete");
|
||||
self.wal_checkpoint().await;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn wal_checkpoint(&self) {
|
||||
match self.execute_batch("PRAGMA wal_checkpoint(TRUNCATE);").await {
|
||||
Ok(_) => trace!("WAL checkpoint completed"),
|
||||
Err(error) => error!(?error, "WAL checkpoint error"),
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_db_size(&self) -> Result<usize> {
|
||||
let page_size =
|
||||
self.query_row("PRAGMA page_size;", (), |row| row.get::<_, usize>(0)).await?;
|
||||
|
||||
Reference in New Issue
Block a user