Skip to main content

StateMachineBackend

Trait StateMachineBackend 

Source
pub trait StateMachineBackend: Send + Sync {
    // Required methods
    fn apply(&self, command: &Command, index: u64) -> CommandResult;
    fn get(&self, key: &str) -> Option<Vec<u8>>;
    fn last_applied(&self) -> u64;
    fn version(&self) -> u64;
    fn len(&self) -> usize;
    fn snapshot(&self) -> Snapshot;
    fn restore(&self, snapshot: Snapshot);

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

Trait for pluggable state machine backends. Implementations can delegate to in-memory storage, disk-based storage, or any other backend.

Required Methods§

Source

fn apply(&self, command: &Command, index: u64) -> CommandResult

Apply a command to the state machine at the given log index.

Source

fn get(&self, key: &str) -> Option<Vec<u8>>

Get a value by key.

Source

fn last_applied(&self) -> u64

Get the last applied log index.

Source

fn version(&self) -> u64

Get the current version/sequence number.

Source

fn len(&self) -> usize

Get the number of keys stored.

Source

fn snapshot(&self) -> Snapshot

Take a snapshot of the current state.

Source

fn restore(&self, snapshot: Snapshot)

Restore state from a snapshot.

Provided Methods§

Source

fn is_empty(&self) -> bool

Check if the state machine is empty.

Implementors§