pub struct StateMachine { /* private fields */ }Expand description
State machine wrapping ClusterMetadata
Implementations§
Source§impl StateMachine
impl StateMachine
Sourcepub fn new(snapshot_dir: impl Into<PathBuf>) -> Self
pub fn new(snapshot_dir: impl Into<PathBuf>) -> Self
Create new state machine with a snapshot directory
Sourcepub fn new_default() -> Self
pub fn new_default() -> Self
Create state machine for legacy callers (in-memory, temp dir for snapshots)
Sourcepub async fn metadata(&self) -> RwLockReadGuard<'_, ClusterMetadata>
pub async fn metadata(&self) -> RwLockReadGuard<'_, ClusterMetadata>
Get current metadata (read-only)
Sourcepub async fn load_latest_snapshot(&self) -> Result<bool, StorageError<NodeId>>
pub async fn load_latest_snapshot(&self) -> Result<bool, StorageError<NodeId>>
Load the latest snapshot from disk (called during startup).
This avoids replaying the entire Raft log by restoring the most recent snapshot into the state machine.
Trait Implementations§
Source§impl Default for StateMachine
impl Default for StateMachine
Source§impl RaftSnapshotBuilder<TypeConfig> for StateMachine
impl RaftSnapshotBuilder<TypeConfig> for StateMachine
Source§async fn build_snapshot(&mut self) -> Result<RaftSnapshot, StorageError<NodeId>>
async fn build_snapshot(&mut self) -> Result<RaftSnapshot, StorageError<NodeId>>
Build snapshot Read more
Source§impl RaftStateMachine<TypeConfig> for StateMachine
impl RaftStateMachine<TypeConfig> for StateMachine
Source§type SnapshotBuilder = StateMachine
type SnapshotBuilder = StateMachine
Snapshot builder type.
Source§async fn applied_state(
&mut self,
) -> Result<(Option<RaftLogId>, RaftStoredMembership), StorageError<NodeId>>
async fn applied_state( &mut self, ) -> Result<(Option<RaftLogId>, RaftStoredMembership), StorageError<NodeId>>
Returns the last applied log id which is recorded in state machine, and the last applied
membership config. Read more
Source§async fn apply<I>(
&mut self,
entries: I,
) -> Result<Vec<RaftResponse>, StorageError<NodeId>>
async fn apply<I>( &mut self, entries: I, ) -> Result<Vec<RaftResponse>, StorageError<NodeId>>
Apply the given payload of entries to the state machine. Read more
Source§async fn begin_receiving_snapshot(
&mut self,
) -> Result<Box<File>, StorageError<NodeId>>
async fn begin_receiving_snapshot( &mut self, ) -> Result<Box<File>, StorageError<NodeId>>
Create a new blank snapshot, returning a writable handle to the snapshot object. Read more
Source§async fn install_snapshot(
&mut self,
meta: &RaftSnapshotMeta,
snapshot: Box<File>,
) -> Result<(), StorageError<NodeId>>
async fn install_snapshot( &mut self, meta: &RaftSnapshotMeta, snapshot: Box<File>, ) -> Result<(), StorageError<NodeId>>
Install a snapshot which has finished streaming from the leader. Read more
Source§async fn get_current_snapshot(
&mut self,
) -> Result<Option<RaftSnapshot>, StorageError<NodeId>>
async fn get_current_snapshot( &mut self, ) -> Result<Option<RaftSnapshot>, StorageError<NodeId>>
Get a readable handle to the current snapshot. Read more
Source§async fn get_snapshot_builder(&mut self) -> Self::SnapshotBuilder
async fn get_snapshot_builder(&mut self) -> Self::SnapshotBuilder
Get the snapshot builder for the state machine. Read more
Auto Trait Implementations§
impl !Freeze for StateMachine
impl !RefUnwindSafe for StateMachine
impl Send for StateMachine
impl Sync for StateMachine
impl Unpin for StateMachine
impl UnsafeUnpin for StateMachine
impl !UnwindSafe for StateMachine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more