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§
Sourcefn get_applied_index(&self) -> Index
fn get_applied_index(&self) -> Index
返回状态机中最后已应用的日志索引。
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".