pub mod admin;
pub mod file_snapshot_set;
use std::{io, path::PathBuf};
#[derive(PartialEq, Clone, Debug, Copy)]
pub enum SnapshotType {
Diff,
FullCompleted,
Pending,
}
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug, Copy)]
pub struct SnapshotOrdinal(pub u64);
impl std::fmt::Display for SnapshotOrdinal {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Clone, PartialEq, Debug)]
pub struct SnapshotInfo {
pub snapshot_type: SnapshotType,
pub ordinal: SnapshotOrdinal,
pub shard_paths: Vec<PathBuf>,
}
impl SnapshotInfo {
#[cfg(test)]
pub fn single_shard_path(&self) -> PathBuf {
assert!(
self.shard_paths.len() == 1,
"This snapshotInfo should have exactly one path"
);
self.shard_paths[0].clone()
}
}
pub trait SnapshotSet: Send {
fn create_or_get_snapshot(
&mut self,
snapshot_type: SnapshotType,
shard_count: u64,
may_append_existing: bool,
) -> Result<SnapshotInfo, io::Error>;
fn publish_completed_snapshot(
&mut self,
pending_snapshot_ordinal: SnapshotOrdinal,
purge_obsolete_diff_snapshots: bool,
purge_obsolete_pending_snapshots: bool,
) -> Result<(), io::Error>;
fn get_snapshots_to_restore(&self) -> Vec<&SnapshotInfo>;
}
pub use file_snapshot_set::FileSnapshotSet;