From 8bc7afe00791eed9a9adc2b7ca4b7d26dee33cdc Mon Sep 17 00:00:00 2001 From: Firstyear Date: Fri, 23 Jul 2021 18:49:03 +1000 Subject: [PATCH] Add wal checkpointing to startup/vacuum (#533) --- kanidmd/src/lib/be/idl_sqlite.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/kanidmd/src/lib/be/idl_sqlite.rs b/kanidmd/src/lib/be/idl_sqlite.rs index 9a8cc82a9..7b64a7c4c 100644 --- a/kanidmd/src/lib/be/idl_sqlite.rs +++ b/kanidmd/src/lib/be/idl_sqlite.rs @@ -26,6 +26,15 @@ pub enum FsType { Zfs = 65536, } +impl FsType { + pub fn checkpoint_pages(&self) -> u32 { + match self { + FsType::Generic => 2048, + FsType::Zfs => 256, + } + } +} + #[derive(Debug)] pub struct IdSqliteEntry { id: i64, @@ -1453,6 +1462,13 @@ impl IdlSqlite { OperationError::SqliteError })?; + vconn + .execute_batch("PRAGMA wal_checkpoint(TRUNCATE);") + .map_err(|e| { + ladmin_error!(audit, "rusqlite wal_checkpoint error {:?}", e); + OperationError::SqliteError + })?; + vconn .pragma_update(None, "journal_mode", &"DELETE") .map_err(|e| { @@ -1497,12 +1513,20 @@ impl IdlSqlite { limmediate_warning!(audit, "NOTICE: db vacuum complete\n"); }; - let fstype = cfg.fstype as u32; + let fs_page_size = cfg.fstype as u32; + let checkpoint_pages = cfg.fstype.checkpoint_pages(); let manager = SqliteConnectionManager::file(cfg.path.as_str()) .with_init(move |c| { c.execute_batch( - format!("PRAGMA page_size={}; PRAGMA journal_mode=WAL;", fstype).as_str(), + format!( + "PRAGMA page_size={}; + PRAGMA journal_mode=WAL; + PRAGMA wal_autocheckpoint={}; + PRAGMA wal_checkpoint(RESTART);", + fs_page_size, checkpoint_pages + ) + .as_str(), ) }) .with_flags(flags);