Trait simple_raft::log::RaftLog [−][src]
pub trait RaftLog { type Error; fn append(&mut self, entry: LogEntry) -> Result<(), Self::Error>; fn cancel_from(
&mut self,
from_index: LogIndex
) -> Result<usize, Self::Error>; fn entry_len(&self, entry: &LogEntry) -> usize; fn get(&mut self, index: LogIndex) -> Option<LogEntry>; fn get_term(&mut self, index: LogIndex) -> Option<TermId>; fn last_taken_index(&self) -> LogIndex; fn last_index(&self) -> LogIndex; fn last_term(&self) -> TermId; fn prev_index(&self) -> LogIndex; fn prev_term(&self) -> TermId; fn take_next(&mut self) -> Option<LogEntry>; fn get_len(&mut self, index: LogIndex) -> Option<usize> { ... } }
Expand description
An interface for storage of the Raft log of a RaftNode
.
Initial state
A Raft log is initialized as empty, with both prev_index
and last_index
returning
LogIndex::default()
. The index of the first appended log entry is 1
and all
indices are contiguous.
Log truncation
A Raft log of bounded size may discard old entries previously taken from the beginning of the log via take_next
if, for example, it runs out of space. However, the term of the last discarded entry is preserved to be returned
from prev_term
if requested. The log can also be truncated explicitly from the end via cancel_from
.
Associated Types
Required methods
Appends an entry to the end of the log.
Errors
If there was any error modifying the log, an error is returned.
Cancels all entries including and after the entry at index from_index
, removing them from the log. Returns the
number of entries removed.
Errors
If there was any error modifying the log, or if the entries did not exist, an error is returned.
Returns the approximate serialized length in bytes of a given log entry.
Returns the entry at a given index, or None
if the index is greater than the length of the log or if the entry
has been discarded.
Returns the term of the entry at a given index, or None
if the index is greater than the length of the log or
if the entry has been discarded.
fn last_taken_index(&self) -> LogIndex
fn last_taken_index(&self) -> LogIndex
Returns the index of the last entry which has been returned by take_next
, or
LogIndex::default()
if none have been.
fn last_index(&self) -> LogIndex
fn last_index(&self) -> LogIndex
Returns the index of the last entry in the log, or LogIndex::default()
if
empty.
Returns the term of the last entry in the log, or TermId::default()
if
empty.
fn prev_index(&self) -> LogIndex
fn prev_index(&self) -> LogIndex
Returns the index immediately before the index of the first undiscarded entry in the log (see “Log Truncation”).
Returns the term of the entry immediately preceding the first undiscarded entry in the log (see “Log Truncation”).
Returns the next entry in the log not previously returned by this function, marking the returned entry eligible
for future discard (see “Log Truncation”). Returns None
if there is no such entry.