Add wal checkpointing to startup/vacuum (#533)

This commit is contained in:
Firstyear 2021-07-23 18:49:03 +10:00 committed by GitHub
parent 8b7f196b2a
commit 8bc7afe007
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,6 +26,15 @@ pub enum FsType {
Zfs = 65536, Zfs = 65536,
} }
impl FsType {
pub fn checkpoint_pages(&self) -> u32 {
match self {
FsType::Generic => 2048,
FsType::Zfs => 256,
}
}
}
#[derive(Debug)] #[derive(Debug)]
pub struct IdSqliteEntry { pub struct IdSqliteEntry {
id: i64, id: i64,
@ -1453,6 +1462,13 @@ impl IdlSqlite {
OperationError::SqliteError OperationError::SqliteError
})?; })?;
vconn
.execute_batch("PRAGMA wal_checkpoint(TRUNCATE);")
.map_err(|e| {
ladmin_error!(audit, "rusqlite wal_checkpoint error {:?}", e);
OperationError::SqliteError
})?;
vconn vconn
.pragma_update(None, "journal_mode", &"DELETE") .pragma_update(None, "journal_mode", &"DELETE")
.map_err(|e| { .map_err(|e| {
@ -1497,12 +1513,20 @@ impl IdlSqlite {
limmediate_warning!(audit, "NOTICE: db vacuum complete\n"); 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()) let manager = SqliteConnectionManager::file(cfg.path.as_str())
.with_init(move |c| { .with_init(move |c| {
c.execute_batch( 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); .with_flags(flags);