pub struct CheckpointManager { /* private fields */ }Expand description
Checkpoint manager for WAL maintenance.
Manages periodic checkpoints and WAL trimming to keep the WAL file size bounded.
Implementations§
Source§impl CheckpointManager
impl CheckpointManager
Sourcepub fn new(wal: Arc<WriteAheadLog>, wal_path: &Path) -> Self
pub fn new(wal: Arc<WriteAheadLog>, wal_path: &Path) -> Self
Sourcepub fn with_interval(self, interval: Duration) -> Self
pub fn with_interval(self, interval: Duration) -> Self
Sourcepub fn checkpoint<F>(&self, apply_fn: F) -> DbxResult<u64>
pub fn checkpoint<F>(&self, apply_fn: F) -> DbxResult<u64>
Performs a checkpoint.
Applies all WAL records to the database and writes a checkpoint marker. This method should be called by the Database engine.
§Arguments
apply_fn- Function to apply a WAL record to the database
§Returns
The sequence number of the checkpoint
§Example
let wal = Arc::new(WriteAheadLog::open(Path::new("./wal.log"))?);
let checkpoint_mgr = CheckpointManager::new(wal, Path::new("./wal.log"));
let apply_fn = |record: &WalRecord| -> dbx_core::DbxResult<()> {
// Apply record to database
Ok(())
};
let checkpoint_seq = checkpoint_mgr.checkpoint(apply_fn)?;Sourcepub fn recover<F>(wal_path: &Path, apply_fn: F) -> DbxResult<usize>
pub fn recover<F>(wal_path: &Path, apply_fn: F) -> DbxResult<usize>
Recovers the database by replaying WAL records.
This is called during database startup to restore the state after a crash.
§Arguments
wal_path- Path to the WAL fileapply_fn- Function to apply a WAL record to the database
§Returns
The number of records replayed
§Example
let apply_fn = |record: &WalRecord| -> dbx_core::DbxResult<()> {
// Apply record to database
Ok(())
};
let count = CheckpointManager::recover(Path::new("./wal.log"), apply_fn)?;
println!("Replayed {} records", count);Sourcepub fn trim_before(&self, sequence: u64) -> DbxResult<()>
pub fn trim_before(&self, sequence: u64) -> DbxResult<()>
Trims the WAL file by removing records before the specified sequence.
This is called after a successful checkpoint to keep the WAL file size bounded.
§Arguments
sequence- Sequence number to trim before
§Example
let wal = Arc::new(WriteAheadLog::open(Path::new("./wal.log"))?);
let checkpoint_mgr = CheckpointManager::new(wal, Path::new("./wal.log"));
// Trim records before sequence 100
checkpoint_mgr.trim_before(100)?;Auto Trait Implementations§
impl Freeze for CheckpointManager
impl RefUnwindSafe for CheckpointManager
impl Send for CheckpointManager
impl Sync for CheckpointManager
impl Unpin for CheckpointManager
impl UnsafeUnpin for CheckpointManager
impl UnwindSafe for CheckpointManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more