CheckpointManager

Struct CheckpointManager 

Source
pub struct CheckpointManager { /* private fields */ }
Expand description

Manages periodic checkpointing to bound recovery time.

Checkpointing ensures that:

  1. All data up to a certain LSN is persisted to the main database file
  2. WAL segments before that LSN can be truncated
  3. Recovery only needs to replay WAL records after the checkpoint

§Checkpoint Process

  1. Record current WAL LSN as checkpoint_lsn
  2. Persist all in-memory data to the main database file
  3. fsync the main database file
  4. Update meta page with checkpoint_lsn
  5. fsync meta page
  6. Truncate WAL segments before checkpoint_lsn

Implementations§

Source§

impl CheckpointManager

Source

pub fn new(config: CheckpointConfig) -> Self

Creates a new checkpoint manager with the given configuration.

Source

pub fn restore( config: CheckpointConfig, checkpoint_info: CheckpointInfo, ) -> Self

Restores checkpoint manager state from persisted checkpoint info.

Source

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
Source

pub fn record_writes(&mut self, count: usize)

Records that records have been written since last checkpoint.

Source

pub fn record_checkpoint(&mut self, lsn: Lsn)

Records that a checkpoint was completed at the given LSN.

Source

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.

Source

pub fn last_checkpoint_lsn(&self) -> Lsn

Returns the LSN of the last completed checkpoint.

Source

pub fn create_checkpoint_info( &self, lsn: Lsn, entry_count: u64, ) -> CheckpointInfo

Creates checkpoint info for the given LSN.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.