Struct raft::RaftLog[][src]

pub struct RaftLog<T: Storage> {
    pub store: T,
    pub unstable: Unstable,
    pub committed: u64,
    pub persisted: u64,
    pub applied: u64,
}
Expand description

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

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

Grabs the term from the last entry.

Panics

Panics if there are entries but the last term has been discarded.

Grab a read-only reference to the underlying storage.

Grab a mutable reference to the underlying storage.

For a given index, finds the term associated with it.

Returns th first index in the store that is available via entries

Panics

Panics if the store doesn’t have a first index.

Returns the last index in the store that is available via entries.

Panics

Panics if the store doesn’t have a last index.

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.

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)

Answers the question: Does this index belong to this term?

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.

Sets the last committed value to the passed in value.

Panics

Panics if the index goes past the last index.

👎 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.

Returns the last applied index.

Clears the unstable entries and moves the stable offset up to the last index, if there is any.

Clears the unstable snapshot.

Returns a reference to the unstable log.

Returns slice of entries that are not persisted.

Returns the snapshot that are not persisted.

Appends a set of entries to the unstable list.

Returns entries starting from a particular index and not exceeding a bytesize.

Returns all the entries.

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.

Returns committed and persisted entries since max(since_idx + 1, first_index).

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.

Returns whether there are committed and persisted entries since max(since_idx + 1, first_index).

Returns whether there are new entries.

Returns the current snapshot

Attempts to commit the index and term and returns whether it did.

Attempts to persist the index and term and returns whether it did.

Attempts to persist the snapshot and returns whether it did.

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.

Restores the current log from a snapshot.

Returns the committed index and its term.

Trait Implementations

Converts the given value to a String. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.