pub trait StateMachine: Send + Sync {
// Required methods
fn apply(&mut self, entry: &LogEntry) -> RaftResult<Vec<u8>>;
fn snapshot(&self) -> RaftResult<Vec<u8>>;
fn restore(&mut self, snapshot: &[u8]) -> RaftResult<()>;
}Expand description
Trait for state machines that can be driven by the Raft log.
Implementors receive committed log entries in order and produce deterministic outputs. They must also support snapshotting and restoring from a snapshot so that log compaction is possible.
Required Methods§
Sourcefn apply(&mut self, entry: &LogEntry) -> RaftResult<Vec<u8>>
fn apply(&mut self, entry: &LogEntry) -> RaftResult<Vec<u8>>
Apply a single committed log entry to the state machine.
Returns the output bytes produced by the command, or an error if application fails.
Sourcefn snapshot(&self) -> RaftResult<Vec<u8>>
fn snapshot(&self) -> RaftResult<Vec<u8>>
Capture a point-in-time snapshot of the state machine.
Sourcefn restore(&mut self, snapshot: &[u8]) -> RaftResult<()>
fn restore(&mut self, snapshot: &[u8]) -> RaftResult<()>
Restore the state machine from a previously captured snapshot.