Struct raft::RaftLog [−][src]
Raft log implementation
Fields
store: T
Contains all stable entries since the last snapshot.
unstable: Unstable
Contains all unstable entries and snapshot. they will be saved into storage.
committed: u64
The highest log position that is known to be in stable storage on a quorum of nodes.
Invariant: applied <= committed
persisted: u64
The highest log position that is known to be persisted in stable storage. It’s used for limiting the upper bound of committed and persisted entries.
Invariant: persisted < unstable.offset && applied <= persisted
applied: u64
The highest log position that the application has been instructed to apply to its state machine.
Invariant: applied <= min(committed, persisted)
Implementations
impl<T: Storage> RaftLog<T>
[src]
pub fn new(store: T, logger: Logger) -> RaftLog<T>
[src]
Creates a new raft log with a given storage and tag.
pub fn last_term(&self) -> u64
[src]
Grabs the term from the last entry.
Panics
Panics if there are entries but the last term has been discarded.
pub fn store(&self) -> &T
[src]
Grab a read-only reference to the underlying storage.
pub fn mut_store(&mut self) -> &mut T
[src]
Grab a mutable reference to the underlying storage.
pub fn term(&self, idx: u64) -> Result<u64>
[src]
For a given index, finds the term associated with it.
pub fn first_index(&self) -> u64
[src]
Returns th first index in the store that is available via entries
Panics
Panics if the store doesn’t have a first index.
pub fn last_index(&self) -> u64
[src]
Returns the last index in the store that is available via entries.
Panics
Panics if the store doesn’t have a last index.
pub fn find_conflict(&self, ents: &[Entry]) -> u64
[src]
Finds the index of the conflict.
It returns the first index of conflicting entries between the existing entries and the given entries, if there are any.
If there are no conflicting entries, and the existing entries contain all the given entries, zero will be returned.
If there are no conflicting entries, but the given entries contains new entries, the index of the first new entry will be returned.
An entry is considered to be conflicting if it has the same index but a different term.
The first entry MUST have an index equal to the argument ‘from’. The index of the given entries MUST be continuously increasing.
pub fn find_conflict_by_term(&self, index: u64, term: u64) -> (u64, Option<u64>)
[src]
find_conflict_by_term takes an (index
, term
) pair (indicating a conflicting log
entry on a leader/follower during an append) and finds the largest index in
log with log.term <= term
and log.index <= index
. If no such index exists
in the log, the log’s first index is returned.
The index provided MUST be equal to or less than self.last_index(). Invalid inputs log a warning and the input index is returned.
Return (index, term)
pub fn match_term(&self, idx: u64, term: u64) -> bool
[src]
Answers the question: Does this index belong to this term?
pub fn maybe_append(
&mut self,
idx: u64,
term: u64,
committed: u64,
ents: &[Entry]
) -> Option<(u64, u64)>
[src]
&mut self,
idx: u64,
term: u64,
committed: u64,
ents: &[Entry]
) -> Option<(u64, u64)>
Returns None if the entries cannot be appended. Otherwise, it returns Some((conflict_index, last_index)).
Panics
Panics if it finds a conflicting index less than committed index.
pub fn commit_to(&mut self, to_commit: u64)
[src]
Sets the last committed value to the passed in value.
Panics
Panics if the index goes past the last index.
pub fn applied_to(&mut self, idx: u64)
[src]
Call raft::commit_apply(idx) instead. Joint Consensus requires an on-apply hook to finalize a configuration change. This will become internal API in future versions.
Advance the applied index to the passed in value.
Panics
Panics if the value passed in is not new or known.
pub fn applied(&self) -> u64
[src]
Returns the last applied index.
pub fn stable_entries(&mut self, index: u64, term: u64)
[src]
Clears the unstable entries and moves the stable offset up to the last index, if there is any.
pub fn stable_snap(&mut self, index: u64)
[src]
Clears the unstable snapshot.
pub fn unstable(&self) -> &Unstable
[src]
Returns a reference to the unstable log.
pub fn unstable_entries(&self) -> &[Entry]
[src]
Returns slice of entries that are not persisted.
pub fn unstable_snapshot(&self) -> &Option<Snapshot>
[src]
Returns the snapshot that are not persisted.
pub fn append(&mut self, ents: &[Entry]) -> u64
[src]
Appends a set of entries to the unstable list.
pub fn entries(
&self,
idx: u64,
max_size: impl Into<Option<u64>>
) -> Result<Vec<Entry>>
[src]
&self,
idx: u64,
max_size: impl Into<Option<u64>>
) -> Result<Vec<Entry>>
Returns entries starting from a particular index and not exceeding a bytesize.
pub fn all_entries(&self) -> Vec<Entry>
[src]
Returns all the entries.
pub fn is_up_to_date(&self, last_index: u64, term: u64) -> bool
[src]
Determines if the given (lastIndex,term) log is more up-to-date by comparing the index and term of the last entry in the existing logs. If the logs have last entry with different terms, then the log with the later term is more up-to-date. If the logs end with the same term, then whichever log has the larger last_index is more up-to-date. If the logs are the same, the given log is up-to-date.
pub fn next_entries_since(&self, since_idx: u64) -> Option<Vec<Entry>>
[src]
Returns committed and persisted entries since max(since_idx
+ 1, first_index).
pub fn next_entries(&self) -> Option<Vec<Entry>>
[src]
Returns all the available entries for execution. If applied is smaller than the index of snapshot, it returns all committed entries after the index of snapshot.
pub fn has_next_entries_since(&self, since_idx: u64) -> bool
[src]
Returns whether there are committed and persisted entries since
max(since_idx
+ 1, first_index).
pub fn has_next_entries(&self) -> bool
[src]
Returns whether there are new entries.
pub fn snapshot(&self, request_index: u64) -> Result<Snapshot>
[src]
Returns the current snapshot
pub fn maybe_commit(&mut self, max_index: u64, term: u64) -> bool
[src]
Attempts to commit the index and term and returns whether it did.
pub fn maybe_persist(&mut self, index: u64, term: u64) -> bool
[src]
Attempts to persist the index and term and returns whether it did.
pub fn maybe_persist_snap(&mut self, index: u64) -> bool
[src]
Attempts to persist the snapshot and returns whether it did.
pub fn slice(
&self,
low: u64,
high: u64,
max_size: impl Into<Option<u64>>
) -> Result<Vec<Entry>>
[src]
&self,
low: u64,
high: u64,
max_size: impl Into<Option<u64>>
) -> Result<Vec<Entry>>
Grabs a slice of entries from the raft. Unlike a rust slice pointer, these are returned by value. The result is truncated to the max_size in bytes.
pub fn restore(&mut self, snapshot: Snapshot)
[src]
Restores the current log from a snapshot.
pub fn commit_info(&self) -> (u64, u64)
[src]
Returns the committed index and its term.
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for RaftLog<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for RaftLog<T> where
T: Send,
T: Send,
impl<T> Sync for RaftLog<T> where
T: Sync,
T: Sync,
impl<T> Unpin for RaftLog<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for RaftLog<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> SendSyncUnwindSafe for T where
T: Send + Sync + UnwindSafe + ?Sized,
[src]
T: Send + Sync + UnwindSafe + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
[src]
V: MultiLane<T>,