From 94c343770d67116fe73abbd28754c13b58370be2 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Tue, 7 Oct 2025 09:32:48 +0300 Subject: [PATCH] mvcc: Disable automatic checkpointing by default MVCC checkpointing currently prevents concurrent writes so disable it by default while we work on it. --- core/lib.rs | 4 ++-- core/mvcc/database/mod.rs | 4 ++-- core/mvcc/persistent_storage/logical_log.rs | 18 +++++++++--------- core/mvcc/persistent_storage/mod.rs | 4 ++-- core/translate/pragma.rs | 8 +++++--- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/core/lib.rs b/core/lib.rs index 8145af6e7..c62c05b80 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -2341,7 +2341,7 @@ impl Connection { *self.mv_tx.read() } - pub(crate) fn set_mvcc_checkpoint_threshold(&self, threshold: u64) -> Result<()> { + pub(crate) fn set_mvcc_checkpoint_threshold(&self, threshold: i64) -> Result<()> { match self.db.mv_store.as_ref() { Some(mv_store) => { mv_store.set_checkpoint_threshold(threshold); @@ -2351,7 +2351,7 @@ impl Connection { } } - pub(crate) fn mvcc_checkpoint_threshold(&self) -> Result { + pub(crate) fn mvcc_checkpoint_threshold(&self) -> Result { match self.db.mv_store.as_ref() { Some(mv_store) => Ok(mv_store.checkpoint_threshold()), None => Err(LimboError::InternalError("MVCC not enabled".into())), diff --git a/core/mvcc/database/mod.rs b/core/mvcc/database/mod.rs index 95014cbc2..c7352fe7c 100644 --- a/core/mvcc/database/mod.rs +++ b/core/mvcc/database/mod.rs @@ -2025,11 +2025,11 @@ impl MvStore { Ok(true) } - pub fn set_checkpoint_threshold(&self, threshold: u64) { + pub fn set_checkpoint_threshold(&self, threshold: i64) { self.storage.set_checkpoint_threshold(threshold) } - pub fn checkpoint_threshold(&self) -> u64 { + pub fn checkpoint_threshold(&self) -> i64 { self.storage.checkpoint_threshold() } } diff --git a/core/mvcc/persistent_storage/logical_log.rs b/core/mvcc/persistent_storage/logical_log.rs index a340d6c43..f2a09230e 100644 --- a/core/mvcc/persistent_storage/logical_log.rs +++ b/core/mvcc/persistent_storage/logical_log.rs @@ -12,17 +12,14 @@ use std::sync::{Arc, RwLock}; use crate::File; -pub const DEFAULT_LOG_CHECKPOINT_THRESHOLD: u64 = 1024 * 1024 * 8; // 8 MiB as default to mimic - // 2000 pages in sqlite which is - // pretty much equal to - // 8MiB if page_size == - // 4096 bytes +pub const DEFAULT_LOG_CHECKPOINT_THRESHOLD: i64 = -1; // Disabled by default pub struct LogicalLog { pub file: Arc, pub offset: u64, /// Size at which we start performing a checkpoint on the logical log. - checkpoint_threshold: u64, + /// Set to -1 to disable automatic checkpointing. + checkpoint_threshold: i64, } /// Log's Header, this will be the 64 bytes in any logical log file. @@ -229,14 +226,17 @@ impl LogicalLog { } pub fn should_checkpoint(&self) -> bool { - self.offset >= self.checkpoint_threshold + if self.checkpoint_threshold < 0 { + return false; + } + self.offset >= self.checkpoint_threshold as u64 } - pub fn set_checkpoint_threshold(&mut self, threshold: u64) { + pub fn set_checkpoint_threshold(&mut self, threshold: i64) { self.checkpoint_threshold = threshold; } - pub fn checkpoint_threshold(&self) -> u64 { + pub fn checkpoint_threshold(&self) -> i64 { self.checkpoint_threshold } } diff --git a/core/mvcc/persistent_storage/mod.rs b/core/mvcc/persistent_storage/mod.rs index 0c5514f6c..0ddf14223 100644 --- a/core/mvcc/persistent_storage/mod.rs +++ b/core/mvcc/persistent_storage/mod.rs @@ -44,11 +44,11 @@ impl Storage { self.logical_log.read().should_checkpoint() } - pub fn set_checkpoint_threshold(&self, threshold: u64) { + pub fn set_checkpoint_threshold(&self, threshold: i64) { self.logical_log.write().set_checkpoint_threshold(threshold) } - pub fn checkpoint_threshold(&self) -> u64 { + pub fn checkpoint_threshold(&self) -> i64 { self.logical_log.read().checkpoint_threshold() } } diff --git a/core/translate/pragma.rs b/core/translate/pragma.rs index 19542adad..149cfafa1 100644 --- a/core/translate/pragma.rs +++ b/core/translate/pragma.rs @@ -380,8 +380,10 @@ fn update_pragma( } PragmaName::MvccCheckpointThreshold => { let threshold = match parse_signed_number(&value)? { - Value::Integer(size) if size > 0 => size as u64, - _ => bail_parse_error!("mvcc_checkpoint_threshold must be a positive integer"), + Value::Integer(size) if size >= -1 => size, + _ => bail_parse_error!( + "mvcc_checkpoint_threshold must be -1, 0, or a positive integer" + ), }; connection.set_mvcc_checkpoint_threshold(threshold)?; @@ -699,7 +701,7 @@ fn query_pragma( PragmaName::MvccCheckpointThreshold => { let threshold = connection.mvcc_checkpoint_threshold()?; let register = program.alloc_register(); - program.emit_int(threshold as i64, register); + program.emit_int(threshold, register); program.emit_result_row(register, 1); program.add_pragma_result_column(pragma.to_string()); Ok((program, TransactionMode::None))