pub struct SnapshotManager { /* private fields */ }Expand description
Manages snapshot creation, storage, loading, and cleanup
Implementations§
Source§impl SnapshotManager
impl SnapshotManager
Sourcepub fn new(config: SnapshotConfig) -> RaftResult<Self>
pub fn new(config: SnapshotConfig) -> RaftResult<Self>
Create a new snapshot manager
Initializes the snapshot directory and scans for existing snapshots.
Sourcepub fn create_snapshot(
&mut self,
data: Vec<u8>,
last_included_index: LogIndex,
last_included_term: Term,
) -> RaftResult<SnapshotMetadata>
pub fn create_snapshot( &mut self, data: Vec<u8>, last_included_index: LogIndex, last_included_term: Term, ) -> RaftResult<SnapshotMetadata>
Create and persist a new snapshot
Writes the snapshot data and metadata to disk atomically (write-to-temp
- fsync + rename), updates the latest metadata cache, and cleans up old snapshots.
Sourcepub fn load_latest(&self) -> RaftResult<Option<Snapshot>>
pub fn load_latest(&self) -> RaftResult<Option<Snapshot>>
Load the most recent snapshot from disk
Sourcepub fn should_snapshot(&self, log_size: u64) -> bool
pub fn should_snapshot(&self, log_size: u64) -> bool
Check whether the log has grown enough to warrant a new snapshot
Sourcepub fn get_latest_metadata(&self) -> Option<&SnapshotMetadata>
pub fn get_latest_metadata(&self) -> Option<&SnapshotMetadata>
Get the metadata of the latest snapshot
Sourcepub fn last_included_index(&self) -> LogIndex
pub fn last_included_index(&self) -> LogIndex
Get the last included index of the latest snapshot
Sourcepub fn last_included_term(&self) -> Term
pub fn last_included_term(&self) -> Term
Get the last included term of the latest snapshot
Sourcepub fn cleanup_old_snapshots(&self) -> RaftResult<()>
pub fn cleanup_old_snapshots(&self) -> RaftResult<()>
Remove old snapshots, keeping only the most recent max_snapshots
Sourcepub fn list_all_snapshots(&self) -> RaftResult<Vec<SnapshotMetadata>>
pub fn list_all_snapshots(&self) -> RaftResult<Vec<SnapshotMetadata>>
List all snapshot metadata files in the snapshot directory
Sourcepub fn install_snapshot(
&mut self,
snapshot: Snapshot,
) -> RaftResult<SnapshotMetadata>
pub fn install_snapshot( &mut self, snapshot: Snapshot, ) -> RaftResult<SnapshotMetadata>
Install a snapshot received from the leader via InstallSnapshot RPC
This handles the case where a follower is too far behind and the leader sends its snapshot directly. The follower must replace its log and state.