[−][src]Trait raft::storage::Storage
Storage saves all the information about the current Raft implementation, including Raft Log, commit index, the leader to vote for, etc.
Pay attention to what is returned when there is no Log but it needs to get the term
at index first_index() - 1
. To solve this, you can use a dummy Log entry to keep the last truncated Log entry. See entries: vec![Entry::new()]
as a reference.
If any Storage method returns an error, the raft instance will become inoperable and refuse to paticipate in elections; the application is responsible for cleanup and recovery in this case.
Required methods
fn initial_state(&self) -> Result<RaftState>
initial_state
is called when Raft is initialized. This interface will return a RaftState
which contains HardState
and ConfState
;
fn entries(&self, low: u64, high: u64, max_size: u64) -> Result<Vec<Entry>>
Returns a slice of log entries in the range [low, high)
.
max_size limits the total size of the log entries returned, but
entries returns at least one entry if any.
fn term(&self, idx: u64) -> Result<u64>
Returns the term of entry idx, which must be in the range [first_index()-1, last_index()]. The term of the entry before first_index is retained for matching purpose even though the rest of that entry may not be available.
fn first_index(&self) -> Result<u64>
Returns the index of the first log entry that is possible available via entries (older entries have been incorporated into the latest snapshot; if storage only contains the dummy entry the first log entry is not available).
fn last_index(&self) -> Result<u64>
The index of the last entry in the log.
fn snapshot(&self) -> Result<Snapshot>
Returns the most recent snapshot.
If snapshot is temporarily unavailable, it should return SnapshotTemporarilyUnavailable, so raft state machine could know that Storage needs some time to prepare snapshot and call snapshot later.
Implementors
impl Storage for MemStorage
[src]
fn initial_state(&self) -> Result<RaftState>
[src]
Implements the Storage trait.
fn entries(&self, low: u64, high: u64, max_size: u64) -> Result<Vec<Entry>>
[src]
Implements the Storage trait.
fn term(&self, idx: u64) -> Result<u64>
[src]
Implements the Storage trait.
fn first_index(&self) -> Result<u64>
[src]
Implements the Storage trait.
fn last_index(&self) -> Result<u64>
[src]
Implements the Storage trait.
fn snapshot(&self) -> Result<Snapshot>
[src]
Implements the Storage trait.