Skip to main content

StateMachine

Trait StateMachine 

Source
pub trait StateMachine<W>
where W: WalTypes,
{ type Error: Error + Debug + 'static; // Required methods fn apply( &mut self, record: &WALRecord<W>, chunk_id: ChunkId, global_segment: Segment, ) -> Result<(), Self::Error>; fn checkpoint(&self) -> W::Checkpoint; }
Expand description

A trait representing a state machine of WAL that can apply records to modify its state.

The Raft-log follows a Write-Ahead Log (WAL) + State Machine pattern. This trait defines the state machine component that processes records persisted in the WAL to build and maintain application state.

§Type Parameters

  • W - The WAL type set that defines records and checkpoints

Required Associated Types§

Source

type Error: Error + Debug + 'static

The type of error that can occur during record application

Required Methods§

Source

fn apply( &mut self, record: &WALRecord<W>, chunk_id: ChunkId, global_segment: Segment, ) -> Result<(), Self::Error>

Applies a record that is already persisted in the WAL to the state machine, potentially modifying its state.

§Arguments
  • record - The record to apply.
  • chunk_id - The identifier of the chunk containing this record.
  • global_segment - The global offset and size of the record in the log file.
Source

fn checkpoint(&self) -> W::Checkpoint

Returns the current checkpoint value for WAL storage.

The WAL stores this value at the beginning of each new chunk. Keep it small because it may be duplicated across chunks. The framework only persists the value; the semantic content belongs to the state-machine implementation.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§