pub struct RaftStorage { /* private fields */ }Expand description
Combined log and state machine storage for Raft.
When disk is Some, all mutations are persisted to the raft directory
so that state survives restarts. When None, storage is purely in-memory
(used when cluster mode is disabled or no data directory is configured).
Implementations§
Source§impl Storage
impl Storage
Sourcepub fn new() -> (Arc<Self>, Receiver<ClusterStateData>)
pub fn new() -> (Arc<Self>, Receiver<ClusterStateData>)
Creates a new in-memory storage instance and returns a receiver that fires whenever the Raft state machine commits entries.
Sourcepub fn open(
raft_dir: PathBuf,
) -> Result<(Arc<Self>, Receiver<ClusterStateData>), RaftDiskError>
pub fn open( raft_dir: PathBuf, ) -> Result<(Arc<Self>, Receiver<ClusterStateData>), RaftDiskError>
Opens persistent storage at raft_dir, recovering any existing state.
On a fresh start the directory is created and empty files are written. On recovery, the vote, log entries, and snapshot are loaded from disk into memory so the Raft node can resume where it left off.
Sourcepub fn has_log_entries(&self) -> bool
pub fn has_log_entries(&self) -> bool
Returns true if the log has any entries (indicating a prior run).
Used by the bootstrap path to decide whether to call bootstrap_single()
(fresh start) or skip it (recovery from persisted state).