pub struct CheckpointManager<S: CheckpointStore = InMemoryCheckpointStore> { /* private fields */ }Expand description
Drives periodic checkpointing and provides recovery support.
Call Self::on_event after processing each event. When the cumulative sequence
number reaches the next scheduled checkpoint, a new CheckpointState is
automatically saved to the underlying store.
Implementations§
Source§impl<S: CheckpointStore> CheckpointManager<S>
impl<S: CheckpointStore> CheckpointManager<S>
Sourcepub fn new(store: S, checkpoint_interval: u64) -> Self
pub fn new(store: S, checkpoint_interval: u64) -> Self
Create a manager with the given store and interval.
Use a durable store such as FileCheckpointStore for recovery that
survives a process restart, or InMemoryCheckpointStore for tests and
single-process, non-recoverable use.
Sourcepub fn on_event(
&mut self,
stream_id: &str,
sequence: u64,
watermark_ns: u64,
) -> Result<bool, StreamingError>
pub fn on_event( &mut self, stream_id: &str, sequence: u64, watermark_ns: u64, ) -> Result<bool, StreamingError>
Called after each processed event.
Returns Ok(true) if a checkpoint was taken, Ok(false) otherwise.
Sourcepub fn recover(&self, stream_id: &str) -> Result<Option<u64>, StreamingError>
pub fn recover(&self, stream_id: &str) -> Result<Option<u64>, StreamingError>
Return the sequence number from which to resume, or None if no
checkpoint exists for the stream.
With a durable store this reads the last checkpoint persisted before a crash, enabling minimal-replay recovery.
Sourcepub fn total_checkpoints(&self) -> u64
pub fn total_checkpoints(&self) -> u64
Total checkpoints taken since this manager was created.