Skip to main content

VecProgress

Struct VecProgress 

Source
pub struct VecProgress<Entry, QS>
where Entry: VecProgressEntry, QS: QuorumSet<Id = Entry::Id>,
{ /* private fields */ }
Expand description

Tracks per-node progress and the greatest value accepted by a quorum.

Entry stores a node ID, an ordered progress value, and optional application-owned data. QS decides which node IDs constitute a quorum. In Raft terms, this is a compact map from node ID to replicated log ID plus any follower state the application keeps beside it.

Internally this type uses a vector and keeps only the voter prefix above the current quorum-accepted value sorted. Normal updates may only keep or increase progress; explicit resets may move an entry backward without lowering the recorded quorum-accepted value. This makes the type a good fit for small consensus memberships.

Implementations§

Source§

impl<Entry, QS> VecProgress<Entry, QS>
where Entry: VecProgressEntry, Entry::Id: Ord + Clone + Debug, Entry::Progress: Debug, QS: QuorumSet<Id = Entry::Id>,

Source

pub fn new( quorum_set: QS, learner_ids: impl IntoIterator<Item = Entry::Id>, default_entry: impl FnMut(Entry::Id) -> Entry, ) -> Self

Create a progress tracker from a quorum set and learner IDs.

Voters are created from quorum_set.ids(). Learners are tracked after voters and never contribute to quorum acceptance. default_entry builds the initial entry for every voter and learner ID.

Source

pub fn iter_mut_without_reorder(&mut self) -> IterMut<'_, Entry>

Return mutable entries without maintaining the progress ordering.

Mutating progress values through this iterator can leave the internal ordering and quorum-accepted value stale. Normal progress updates must use Self::update_progress() or Self::update_entry_with() instead. Mutating entry IDs can corrupt membership lookup.

Source

pub fn display_with<Fmt>( &self, f: Fmt, ) -> DisplayVecProgress<'_, Entry, QS, Fmt>
where Fmt: Fn(&mut Formatter<'_>, &Entry) -> Result,

Return a display adapter that formats entries with a caller-provided formatter.

Source§

impl<Entry, QS> VecProgress<Entry, QS>
where Entry: VecProgressEntry, Entry::Id: Ord + Clone + Debug, Entry::Progress: Debug, QS: QuorumSet<Id = Entry::Id>,

Source

pub fn update_entry_with<F>( &mut self, id: &Entry::Id, f: F, ) -> Option<&Entry::Progress>
where F: FnOnce(&mut Entry),

Update an entry and recalculate the quorum-accepted value.

Use this when application-owned fields must change together with the progress value. The progress update must not lower progress, and the entry ID must not change.

It returns None if the id is not found. Otherwise, it returns the current quorum-accepted value.

Source

pub fn update_data_with<F>( &mut self, id: &Entry::Id, f: F, ) -> Option<&Entry::Data>
where Entry: VecProgressEntryData, F: FnOnce(&mut Entry::Data),

Update application-owned data without recalculating quorum-accepted progress.

This method only exposes VecProgressEntryData::Data, so it cannot change progress or invalidate the ordering maintained by VecProgress.

Returns the updated data when id is found, otherwise returns None.

Source

pub fn reset_entry_with<F>(&mut self, id: &Entry::Id, f: F) -> Option<&Entry>
where F: FnOnce(&mut Entry),

Update an entry whose progress value may move backward, for example when replication progress is reset upon log reversion.

If the progress value is lowered, the entry is moved down to keep the values greater than quorum_accepted sorted. The recorded quorum-accepted value is deliberately not recalculated: a value accepted by a quorum must never be withdrawn. The entry ID must not be changed.

It returns the updated entry if the id is found, otherwise returns None.

Source

pub fn update_progress( &mut self, id: &Entry::Id, value: Entry::Progress, ) -> Option<&Entry::Progress>

Set one node’s progress and recalculate the quorum-accepted value.

The new value must be greater than or equal to the current progress. Use Self::reset_entry_with() for an explicit backward move.

It returns None if the id is not found. Otherwise, it returns the current quorum-accepted value.

Source

pub fn increase_to( &mut self, id: &Entry::Id, value: Entry::Progress, ) -> Option<&Entry::Progress>

Increase one node’s progress if value is greater than its current value.

It returns None if the id is not found. Otherwise, it returns the current quorum-accepted value.

Source

pub fn get(&self, id: &Entry::Id) -> Option<&Entry>

Return the tracked entry for id.

Source

pub fn quorum_accepted(&self) -> &Entry::Progress

Return the greatest progress value accepted by the quorum set.

In Raft, this is the replication progress reached by enough voters to be considered committed once the term-specific commit rule also allows it.

Source

pub fn iter(&self) -> Iter<'_, Entry>

Iterate over all entries, with voters first and learners after them.

Source

pub fn collect_mapped<F, T, C>(&self, f: F) -> C
where F: Fn(&Entry) -> T, C: FromIterator<T>,

Map every entry and collect the mapped values.

Source

pub fn upgrade_quorum_set( self, quorum_set: QS, learner_ids: impl IntoIterator<Item = Entry::Id>, default_entry: impl FnMut(Entry::Id) -> Entry, ) -> Self

Build a tracker for a new quorum set while preserving progress for shared IDs.

Entries whose IDs still exist in the new voter or learner set keep their previous progress and application data. New IDs are initialized through default_entry.

Source

pub fn is_voter(&self, id: &Entry::Id) -> Option<bool>

Return whether the given ID is a voter.

A voter is a node in the quorum set that can grant a value. A learner’s progress is also tracked, but it will never grant a value.

If the given id is not in this VecProgress, it returns None.

Trait Implementations§

Source§

impl<Entry, QS> Clone for VecProgress<Entry, QS>
where Entry: VecProgressEntry + Clone, QS: QuorumSet<Id = Entry::Id> + Clone, Entry::Progress: Clone,

Source§

fn clone(&self) -> VecProgress<Entry, QS>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Entry, QS> Debug for VecProgress<Entry, QS>
where Entry: VecProgressEntry + Debug, QS: QuorumSet<Id = Entry::Id> + Debug, Entry::Progress: Debug,

Source§

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

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

impl<Entry, QS> Display for VecProgress<Entry, QS>
where Entry: VecProgressEntry + Display, QS: QuorumSet<Id = Entry::Id> + 'static,

Source§

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

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

impl<Entry, QS> IntoIterator for VecProgress<Entry, QS>
where Entry: VecProgressEntry, QS: QuorumSet<Id = Entry::Id>,

Source§

type Item = Entry

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<Entry>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<Entry, QS> Validate for VecProgress<Entry, QS>
where Entry: VecProgressEntry, Entry::Id: Ord + Clone + Debug, Entry::Progress: Debug, QS: QuorumSet<Id = Entry::Id>,

Source§

fn validate(&self) -> Result<(), Box<dyn Error>>

Validates the voter-order invariant maintained after progress updates.

Auto Trait Implementations§

§

impl<Entry, QS> Freeze for VecProgress<Entry, QS>
where QS: Freeze, <Entry as VecProgressEntry>::Progress: Freeze,

§

impl<Entry, QS> RefUnwindSafe for VecProgress<Entry, QS>

§

impl<Entry, QS> Send for VecProgress<Entry, QS>
where QS: Send, <Entry as VecProgressEntry>::Progress: Send, Entry: Send,

§

impl<Entry, QS> Sync for VecProgress<Entry, QS>
where QS: Sync, <Entry as VecProgressEntry>::Progress: Sync, Entry: Sync,

§

impl<Entry, QS> Unpin for VecProgress<Entry, QS>
where QS: Unpin, <Entry as VecProgressEntry>::Progress: Unpin, Entry: Unpin,

§

impl<Entry, QS> UnsafeUnpin for VecProgress<Entry, QS>

§

impl<Entry, QS> UnwindSafe for VecProgress<Entry, QS>
where QS: UnwindSafe, <Entry as VecProgressEntry>::Progress: UnwindSafe, Entry: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<T> ValidateExt for T
where T: Validate,

Source§

fn valid(self) -> Valid<T>
where T: Sized,

Return an always valid instance Valid<Self> that enables internal state validation.