Struct RaftLog

Source
pub struct RaftLog<T: Storage> {
    pub storage: T,
    pub unstable: Unstable,
    pub committed: u64,
    pub applied: u64,
    pub tag: String,
}

Fields§

§storage: T

storage contains all stable entries since the last snapshot.

§unstable: Unstable

unstable contains all unstable entries and snapshot. they will be saved into storage.

§committed: u64

committed is the highest log position that is known to be in stable storage on a quorum of nodes.

§applied: u64

applied is the highest log position that the application has been instructed to apply to its state machine. Invariant: applied <= committed

§tag: String

tag only used for logger.

Implementations§

Source§

impl<T: Storage> RaftLog<T>

Source

pub fn new(storage: T, tag: String) -> RaftLog<T>

Source

pub fn last_index(&self) -> u64

Source

pub fn first_index(&self) -> u64

Source

pub fn applied_to(&mut self, i: u64)

Source

pub fn last_term(&self) -> u64

Source

pub fn term(&self, i: u64) -> Result<u64>

Source

pub fn get_applied(&self) -> u64

Source

pub fn get_storage(&self) -> &T

Source

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

Source

pub fn maybe_commit(&mut self, max_index: u64, term: u64) -> bool

Source

pub fn commit_to(&mut self, tocommit: u64)

Source

pub fn zero_term_on_err_compacted(&self, t: Result<u64>) -> u64

Source

pub fn must_check_out_of_bounds(&self, low: u64, hight: u64) -> Result<()>

Source

pub fn slice(&self, lo: u64, hi: u64, max_size: u64) -> Result<Vec<Entry>>

Source

pub fn entries(&self, i: u64, max_size: u64) -> Result<Vec<Entry>>

Source

pub fn is_up_to_date(&self, index: u64, term: u64) -> bool

is_up_to_date determines if the given (last_index,term) log is more up-to-date by comparing the index and term of the last entries in the existing logs. If the logs have last entries 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.

Source

pub fn match_term(&self, i: u64, term: u64) -> bool

Source

pub fn maybe_append( &mut self, index: u64, log_term: u64, committed: u64, ents: &[Entry], ) -> Option<u64>

Source

pub fn restore(&mut self, s: Snapshot)

Source

pub fn snapshot(&self) -> Result<Snapshot>

Source

pub fn unstable_entries(&self) -> Vec<Entry>

Source

pub fn next_ents(&self) -> Vec<Entry>

Source

pub fn has_next_ents(&self) -> bool

Source

pub fn stable_to(&mut self, index: u64, term: u64)

Source

pub fn stable_snap_to(&mut self, index: u64)

Source

pub fn all_entries(&self) -> Vec<Entry>

Trait Implementations§

Source§

impl<T: Debug + Storage> Debug for RaftLog<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default + Storage> Default for RaftLog<T>

Source§

fn default() -> RaftLog<T>

Returns the “default value” for a type. Read more
Source§

impl<T: Storage> ToString for RaftLog<T>

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for RaftLog<T>

§

impl<T> !RefUnwindSafe for RaftLog<T>

§

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

§

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

§

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

§

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

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.