Skip to main content

State

Trait State 

Source
pub trait State: Send {
    // Required methods
    fn get_applied_index(&self) -> Index;
    fn apply(&mut self, entry: Entry) -> Result<Vec<u8>>;
    fn read(&self, command: Vec<u8>) -> Result<Vec<u8>>;

    // Provided methods
    fn snapshot(&self) -> Result<Vec<u8>> { ... }
    fn restore(&mut self, _snapshot: &[u8], _index: Index) -> Result<()> { ... }
}
Expand description

由 Raft 管理的状态机。

写命令经 apply 在所有节点上复制并应用;读命令经 read 只在领导者执行。

Required Methods§

Source

fn get_applied_index(&self) -> Index

返回状态机中最后已应用的日志索引。

Source

fn apply(&mut self, entry: Entry) -> Result<Vec<u8>>

将一条日志条目应用到状态机,并返回客户端结果。

Source

fn read(&self, command: Vec<u8>) -> Result<Vec<u8>>

在状态机中执行读命令,并返回客户端结果。不得修改状态。

Provided Methods§

Source

fn snapshot(&self) -> Result<Vec<u8>>

导出快照字节(含足以恢复的完整状态)。

Source

fn restore(&mut self, _snapshot: &[u8], _index: Index) -> Result<()>

从快照恢复,并将 applied 索引设为 index

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§