pub struct CheckpointManager { /* private fields */ }Expand description
Manages periodic checkpointing to bound recovery time.
Checkpointing ensures that:
- All data up to a certain LSN is persisted to the main database file
- WAL segments before that LSN can be truncated
- Recovery only needs to replay WAL records after the checkpoint
§Checkpoint Process
- Record current WAL LSN as checkpoint_lsn
- Persist all in-memory data to the main database file
- fsync the main database file
- Update meta page with checkpoint_lsn
- fsync meta page
- Truncate WAL segments before checkpoint_lsn
Implementations§
Source§impl CheckpointManager
impl CheckpointManager
Sourcepub fn new(config: CheckpointConfig) -> Self
pub fn new(config: CheckpointConfig) -> Self
Creates a new checkpoint manager with the given configuration.
Sourcepub fn restore(
config: CheckpointConfig,
checkpoint_info: CheckpointInfo,
) -> Self
pub fn restore( config: CheckpointConfig, checkpoint_info: CheckpointInfo, ) -> Self
Restores checkpoint manager state from persisted checkpoint info.
Sourcepub fn should_checkpoint(&self, wal: &Wal) -> bool
pub fn should_checkpoint(&self, wal: &Wal) -> bool
Determines if a checkpoint should be performed based on configured thresholds.
A checkpoint is triggered if any of these conditions are met:
- Time since last checkpoint exceeds
config.interval - WAL growth since checkpoint exceeds
config.wal_threshold - Records since checkpoint exceed
config.min_records
Sourcepub fn record_writes(&mut self, count: usize)
pub fn record_writes(&mut self, count: usize)
Records that records have been written since last checkpoint.
Sourcepub fn record_checkpoint(&mut self, lsn: Lsn)
pub fn record_checkpoint(&mut self, lsn: Lsn)
Records that a checkpoint was completed at the given LSN.
Sourcepub fn record_checkpoint_with_wal_size(&mut self, lsn: Lsn, wal_size: u64)
pub fn record_checkpoint_with_wal_size(&mut self, lsn: Lsn, wal_size: u64)
Records that a checkpoint was completed at the given LSN, tracking WAL size.
Sourcepub fn last_checkpoint_lsn(&self) -> Lsn
pub fn last_checkpoint_lsn(&self) -> Lsn
Returns the LSN of the last completed checkpoint.
Sourcepub fn create_checkpoint_info(
&self,
lsn: Lsn,
entry_count: u64,
) -> CheckpointInfo
pub fn create_checkpoint_info( &self, lsn: Lsn, entry_count: u64, ) -> CheckpointInfo
Creates checkpoint info for the given LSN.
Auto Trait Implementations§
impl Freeze for CheckpointManager
impl RefUnwindSafe for CheckpointManager
impl Send for CheckpointManager
impl Sync for CheckpointManager
impl Unpin 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> 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