From 66c69461fba0638e46f382d0b474c595ecdb141c Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Tue, 7 Oct 2025 10:09:39 +0530 Subject: [PATCH 1/5] Add getter/setter for checkpoint threshold in LogicalLog Wire threshold access through Storage Add checkpoint threshold accessors to MvStore --- core/mvcc/database/mod.rs | 4 ++++ core/mvcc/persistent_storage/logical_log.rs | 4 ++++ core/mvcc/persistent_storage/mod.rs | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/core/mvcc/database/mod.rs b/core/mvcc/database/mod.rs index 3c3b4aaff..5425adead 100644 --- a/core/mvcc/database/mod.rs +++ b/core/mvcc/database/mod.rs @@ -2035,6 +2035,10 @@ impl MvStore { pub fn set_checkpoint_threshold(&self, threshold: u64) { self.storage.set_checkpoint_threshold(threshold) } + + pub fn checkpoint_threshold(&self) -> u64 { + self.storage.checkpoint_threshold() + } } /// A write-write conflict happens when transaction T_current attempts to update a diff --git a/core/mvcc/persistent_storage/logical_log.rs b/core/mvcc/persistent_storage/logical_log.rs index ee572f225..a902bac98 100644 --- a/core/mvcc/persistent_storage/logical_log.rs +++ b/core/mvcc/persistent_storage/logical_log.rs @@ -235,6 +235,10 @@ impl LogicalLog { pub fn set_checkpoint_threshold(&mut self, threshold: u64) { self.checkpoint_threshold = threshold; } + + pub fn checkpoint_threshold(&self) -> u64 { + self.checkpoint_threshold + } } pub enum StreamingResult { diff --git a/core/mvcc/persistent_storage/mod.rs b/core/mvcc/persistent_storage/mod.rs index 1cc8d0c2b..ede456bc3 100644 --- a/core/mvcc/persistent_storage/mod.rs +++ b/core/mvcc/persistent_storage/mod.rs @@ -49,6 +49,10 @@ impl Storage { .unwrap() .set_checkpoint_threshold(threshold) } + + pub fn checkpoint_threshold(&self) -> u64 { + self.logical_log.read().unwrap().checkpoint_threshold() + } } impl Debug for Storage { From fb5f5d9a9010d0d720534597cf7077d7cf2afaf3 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Tue, 7 Oct 2025 10:10:47 +0530 Subject: [PATCH 2/5] Add MVCC checkpoint threshold APIs to Connection --- core/lib.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/lib.rs b/core/lib.rs index 11b85be81..9327d7447 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -2360,6 +2360,23 @@ impl Connection { pub(crate) fn get_mv_tx(&self) -> Option<(u64, TransactionMode)> { *self.mv_tx.read() } + + pub(crate) fn set_mvcc_checkpoint_threshold(&self, threshold: u64) -> Result<()> { + match self.db.mv_store.as_ref() { + Some(mv_store) => { + mv_store.set_checkpoint_threshold(threshold); + Ok(()) + } + None => Err(LimboError::InternalError("MVCC not enabled".into())), + } + } + + 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())), + } + } } #[derive(Debug)] From 551dbf518e2f8abf5c819eab7af5469b7196a772 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Tue, 7 Oct 2025 10:11:20 +0530 Subject: [PATCH 3/5] Add new mvcc_checkpoint_threshold pragma name --- core/pragma.rs | 4 ++++ parser/src/ast.rs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/core/pragma.rs b/core/pragma.rs index c83509a69..c238134e4 100644 --- a/core/pragma.rs +++ b/core/pragma.rs @@ -127,6 +127,10 @@ pub fn pragma_for(pragma: &PragmaName) -> Pragma { PragmaFlags::Result0 | PragmaFlags::SchemaReq | PragmaFlags::NoColumns1, &["cipher"], ), + PragmaName::MvccCheckpointThreshold => Pragma::new( + PragmaFlags::NoColumns1 | PragmaFlags::Result0, + &["mvcc_checkpoint_threshold"], + ), } } diff --git a/parser/src/ast.rs b/parser/src/ast.rs index ced93b722..6b69682f0 100644 --- a/parser/src/ast.rs +++ b/parser/src/ast.rs @@ -1449,6 +1449,8 @@ pub enum PragmaName { UserVersion, /// trigger a checkpoint to run on database(s) if WAL is enabled WalCheckpoint, + /// Sets or queries the threshold (in bytes) at which MVCC triggers an automatic checkpoint. + MvccCheckpointThreshold, } /// `CREATE TRIGGER` time From 68b6ffe57cac29cb208baaaa46edd74a98d5c051 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Tue, 7 Oct 2025 10:11:53 +0530 Subject: [PATCH 4/5] Implement mvcc_checkpoint_threshold pragma --- core/translate/pragma.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/translate/pragma.rs b/core/translate/pragma.rs index d8b26143a..37707533e 100644 --- a/core/translate/pragma.rs +++ b/core/translate/pragma.rs @@ -378,6 +378,15 @@ fn update_pragma( connection.set_data_sync_retry(retry_enabled); Ok((program, TransactionMode::None)) } + 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"), + }; + + connection.set_mvcc_checkpoint_threshold(threshold)?; + Ok((program, TransactionMode::None)) + } } } @@ -687,6 +696,14 @@ fn query_pragma( program.add_pragma_result_column(pragma.to_string()); Ok((program, TransactionMode::None)) } + PragmaName::MvccCheckpointThreshold => { + let threshold = connection.mvcc_checkpoint_threshold()?; + let register = program.alloc_register(); + program.emit_int(threshold as i64, register); + program.emit_result_row(register, 1); + program.add_pragma_result_column(pragma.to_string()); + Ok((program, TransactionMode::None)) + }, } } From afadb32c4ce69a4ded180c91f02d9d5765a8866e Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Tue, 7 Oct 2025 10:20:13 +0530 Subject: [PATCH 5/5] fmt fixes --- core/translate/pragma.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/translate/pragma.rs b/core/translate/pragma.rs index 37707533e..19542adad 100644 --- a/core/translate/pragma.rs +++ b/core/translate/pragma.rs @@ -703,7 +703,7 @@ fn query_pragma( program.emit_result_row(register, 1); program.add_pragma_result_column(pragma.to_string()); Ok((program, TransactionMode::None)) - }, + } } }