pub struct MemStateMachine<C, S, F>where
C: RaftTypeConfig<NodeId = NodeId>,
S: Default + Clone + Serialize + DeserializeOwned + Send + Sync + 'static,
F: Fn(&mut S, &C::D) -> C::R + Send + Sync + 'static,{ /* private fields */ }Expand description
In-memory Raft state machine (v2 API).
Generic over:
C: openraftRaftTypeConfigS: application state typeF: a functionfn(&mut S, &C::D) -> C::Rthat applies a log entry to the state.
The apply_fn approach keeps the state machine generic: the application provides
a closure that knows how to mutate S given a log entry payload of type C::D.
Implementations§
Source§impl<C, S, F> MemStateMachine<C, S, F>
impl<C, S, F> MemStateMachine<C, S, F>
Trait Implementations§
Source§impl<C, S, F> Clone for MemStateMachine<C, S, F>
impl<C, S, F> Clone for MemStateMachine<C, S, F>
Source§impl<C, S, F> RaftStateMachine<C> for MemStateMachine<C, S, F>
impl<C, S, F> RaftStateMachine<C> for MemStateMachine<C, S, F>
Source§type SnapshotBuilder = MemSnapshotBuilder<C, S, F>
type SnapshotBuilder = MemSnapshotBuilder<C, S, F>
Snapshot builder type.
Source§async fn applied_state(
&mut self,
) -> Result<(Option<LogId<NodeId>>, StoredMembership<NodeId, C::Node>), StorageError<NodeId>>
async fn applied_state( &mut self, ) -> Result<(Option<LogId<NodeId>>, StoredMembership<NodeId, C::Node>), 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<C::R>, StorageError<NodeId>>
async fn apply<I>( &mut self, entries: I, ) -> Result<Vec<C::R>, StorageError<NodeId>>
Apply the given payload of entries to the state machine. 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
Source§async fn begin_receiving_snapshot(
&mut self,
) -> Result<Box<Cursor<Vec<u8>>>, StorageError<NodeId>>
async fn begin_receiving_snapshot( &mut self, ) -> Result<Box<Cursor<Vec<u8>>>, 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: &SnapshotMeta<NodeId, C::Node>,
snapshot: Box<Cursor<Vec<u8>>>,
) -> Result<(), StorageError<NodeId>>
async fn install_snapshot( &mut self, meta: &SnapshotMeta<NodeId, C::Node>, snapshot: Box<Cursor<Vec<u8>>>, ) -> 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<Snapshot<C>>, StorageError<NodeId>>
async fn get_current_snapshot( &mut self, ) -> Result<Option<Snapshot<C>>, StorageError<NodeId>>
Get a readable handle to the current snapshot. Read more
Auto Trait Implementations§
impl<C, S, F> Freeze for MemStateMachine<C, S, F>
impl<C, S, F> !RefUnwindSafe for MemStateMachine<C, S, F>
impl<C, S, F> Send for MemStateMachine<C, S, F>
impl<C, S, F> Sync for MemStateMachine<C, S, F>
impl<C, S, F> Unpin for MemStateMachine<C, S, F>
impl<C, S, F> UnsafeUnpin for MemStateMachine<C, S, F>
impl<C, S, F> !UnwindSafe for MemStateMachine<C, S, F>
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