mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-23 00:45:37 +01:00
core/mvcc/logical-log: add threshold for checkpoints in logical log
This commit is contained in:
@@ -12,9 +12,17 @@ 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 struct LogicalLog {
|
||||
pub file: Arc<dyn File>,
|
||||
pub offset: u64,
|
||||
/// Size at which we start performing a checkpoint on the logical log.
|
||||
checkpoint_threshold: u64,
|
||||
}
|
||||
|
||||
/// Log's Header, this will be the 64 bytes in any logical log file.
|
||||
@@ -140,7 +148,11 @@ impl LogRecordType {
|
||||
|
||||
impl LogicalLog {
|
||||
pub fn new(file: Arc<dyn File>) -> Self {
|
||||
Self { file, offset: 0 }
|
||||
Self {
|
||||
file,
|
||||
offset: 0,
|
||||
checkpoint_threshold: DEFAULT_LOG_CHECKPOINT_THRESHOLD,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn log_tx(&mut self, tx: &LogRecord) -> Result<Completion> {
|
||||
@@ -215,6 +227,14 @@ impl LogicalLog {
|
||||
self.offset = 0;
|
||||
Ok(c)
|
||||
}
|
||||
|
||||
pub fn should_checkpoint(&self) -> bool {
|
||||
self.offset >= self.checkpoint_threshold
|
||||
}
|
||||
|
||||
pub fn set_checkpoint_threshold(&mut self, threshold: u64) {
|
||||
self.checkpoint_threshold = threshold;
|
||||
}
|
||||
}
|
||||
|
||||
pub enum StreamingResult {
|
||||
|
||||
@@ -38,6 +38,17 @@ impl Storage {
|
||||
pub fn get_logical_log_file(&self) -> Arc<dyn File> {
|
||||
self.logical_log.write().unwrap().file.clone()
|
||||
}
|
||||
|
||||
pub fn should_checkpoint(&self) -> bool {
|
||||
self.logical_log.read().unwrap().should_checkpoint()
|
||||
}
|
||||
|
||||
pub fn set_checkpoint_threshold(&self, threshold: u64) {
|
||||
self.logical_log
|
||||
.write()
|
||||
.unwrap()
|
||||
.set_checkpoint_threshold(threshold)
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Storage {
|
||||
|
||||
Reference in New Issue
Block a user