pub struct Unstable {
pub snapshot: Option<Snapshot>,
pub entries: Vec<Entry>,
pub entries_size: usize,
pub offset: u64,
pub logger: Logger,
}
Expand description
The unstable.entries[i]
has raft log position i+unstable.offset
.
Note that unstable.offset
may be less than the highest log
position in storage; this means that the next write to storage
might need to truncate the log before persisting unstable.entries.
Fields§
§snapshot: Option<Snapshot>
The incoming unstable snapshot, if any.
entries: Vec<Entry>
All entries that have not yet been written to storage.
entries_size: usize
The size of entries
offset: u64
The offset from the vector index.
logger: Logger
The tag to use when logging.
Implementations§
source§impl Unstable
impl Unstable
sourcepub fn maybe_first_index(&self) -> Option<u64>
pub fn maybe_first_index(&self) -> Option<u64>
Returns the index of the first possible entry in entries if it has a snapshot.
sourcepub fn maybe_last_index(&self) -> Option<u64>
pub fn maybe_last_index(&self) -> Option<u64>
Returns the last index if it has at least one unstable entry or snapshot.
sourcepub fn maybe_term(&self, idx: u64) -> Option<u64>
pub fn maybe_term(&self, idx: u64) -> Option<u64>
Returns the term of the entry at index idx, if there is any.
sourcepub fn stable_entries(&mut self, index: u64, term: u64)
pub fn stable_entries(&mut self, index: u64, term: u64)
Clears the unstable entries and moves the stable offset up to the last index, if there is any.
sourcepub fn stable_snap(&mut self, index: u64)
pub fn stable_snap(&mut self, index: u64)
Clears the unstable snapshot.
sourcepub fn restore(&mut self, snap: Snapshot)
pub fn restore(&mut self, snap: Snapshot)
From a given snapshot, restores the snapshot to self, but doesn’t unpack.
sourcepub fn truncate_and_append(&mut self, ents: &[Entry])
pub fn truncate_and_append(&mut self, ents: &[Entry])
Append entries to unstable, truncate local block first if overlapped.
Panics
Panics if truncate logs to the entry before snapshot
sourcepub fn slice(&self, lo: u64, hi: u64) -> &[Entry]
pub fn slice(&self, lo: u64, hi: u64) -> &[Entry]
Returns a slice of entries between the high and low.
Panics
Panics if the lo
or hi
are out of bounds.
Panics if lo > hi
.
sourcepub fn must_check_outofbounds(&self, lo: u64, hi: u64)
pub fn must_check_outofbounds(&self, lo: u64, hi: u64)
Asserts the hi
and lo
values against each other and against the
entries themselves.