[][src]Struct raft::RaftLog

pub struct RaftLog<T: Storage> {
    pub store: T,
    pub unstable: Unstable,
    pub committed: u64,
    pub applied: u64,
    pub tag: String,
    // some fields omitted
}

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.

applied: u64

The highest log position that the application has been instructed to apply to its state machine.

Invariant: applied <= committed

tag: String

A tag associated with this raft for logging purposes.

Methods

impl<T: Storage> RaftLog<T>[src]

pub fn new(store: T, tag: String) -> RaftLog<T>[src]

Creates a new raft log with a given storage and tag.

pub fn with_logger(self, logger: &Logger) -> Self[src]

Set a logger.

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 get_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 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>
[src]

Returns None if the entries cannot be appended. Otherwise, it returns Some(last index of new entries).

Panics

Panics if it finds a conflicting 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]

Deprecated:

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 get_applied(&self) -> u64[src]

Returns the last applied index.

pub fn stable_to(&mut self, idx: u64, term: u64)[src]

Attempts to set the stable up to a given index.

pub fn stable_snap_to(&mut self, idx: u64)[src]

Snaps the unstable up to a current index.

pub fn get_unstable(&self) -> &Unstable[src]

Returns a reference to the unstable log.

pub fn append(&mut self, ents: &[Entry]) -> u64[src]

Appends a set of entries to the unstable list.

pub fn unstable_entries(&self) -> Option<&[Entry]>[src]

Returns slice of entries that are not committed.

pub fn entries(
    &self,
    idx: u64,
    max_size: impl Into<Option<u64>>
) -> Result<Vec<Entry>>
[src]

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 any entries since the a particular 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 entries since a particular 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 slice(
    &self,
    low: u64,
    high: u64,
    max_size: impl Into<Option<u64>>
) -> Result<Vec<Entry>>
[src]

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.

Trait Implementations

impl<T> Default for RaftLog<T> where
    T: Storage + Default
[src]

impl<T> ToString for RaftLog<T> where
    T: Storage
[src]

Auto Trait Implementations

impl<T> Sync for RaftLog<T> where
    T: Sync

impl<T> Send for RaftLog<T> where
    T: Send

impl<T> Unpin for RaftLog<T> where
    T: Unpin

impl<T> RefUnwindSafe for RaftLog<T> where
    T: RefUnwindSafe

impl<T> UnwindSafe for RaftLog<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> SendSyncUnwindSafe for T where
    T: Send + Sync + UnwindSafe + ?Sized
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,