pub struct VecProgress<Entry, QS>{ /* 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>
impl<Entry, QS> VecProgress<Entry, QS>
Sourcepub fn new(
quorum_set: QS,
learner_ids: impl IntoIterator<Item = Entry::Id>,
default_entry: impl FnMut(Entry::Id) -> Entry,
) -> Self
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.
Sourcepub fn iter_mut_without_reorder(&mut self) -> IterMut<'_, Entry>
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.
Sourcepub fn display_with<Fmt>(
&self,
f: Fmt,
) -> DisplayVecProgress<'_, Entry, QS, Fmt>
pub fn display_with<Fmt>( &self, f: Fmt, ) -> DisplayVecProgress<'_, Entry, QS, Fmt>
Return a display adapter that formats entries with a caller-provided formatter.
Source§impl<Entry, QS> VecProgress<Entry, QS>
impl<Entry, QS> VecProgress<Entry, QS>
Sourcepub fn update_entry_with<F>(
&mut self,
id: &Entry::Id,
f: F,
) -> Option<&Entry::Progress>where
F: FnOnce(&mut Entry),
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.
Sourcepub fn update_data_with<F>(
&mut self,
id: &Entry::Id,
f: F,
) -> Option<&Entry::Data>
pub fn update_data_with<F>( &mut self, id: &Entry::Id, f: F, ) -> Option<&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.
Sourcepub fn reset_entry_with<F>(&mut self, id: &Entry::Id, f: F) -> Option<&Entry>where
F: FnOnce(&mut Entry),
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.
Sourcepub fn update_progress(
&mut self,
id: &Entry::Id,
value: Entry::Progress,
) -> Option<&Entry::Progress>
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.
Sourcepub fn increase_to(
&mut self,
id: &Entry::Id,
value: Entry::Progress,
) -> Option<&Entry::Progress>
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.
Sourcepub fn quorum_accepted(&self) -> &Entry::Progress
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.
Sourcepub fn iter(&self) -> Iter<'_, Entry>
pub fn iter(&self) -> Iter<'_, Entry>
Iterate over all entries, with voters first and learners after them.
Sourcepub fn collect_mapped<F, T, C>(&self, f: F) -> C
pub fn collect_mapped<F, T, C>(&self, f: F) -> C
Map every entry and collect the mapped values.
Sourcepub fn upgrade_quorum_set(
self,
quorum_set: QS,
learner_ids: impl IntoIterator<Item = Entry::Id>,
default_entry: impl FnMut(Entry::Id) -> Entry,
) -> Self
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.
Trait Implementations§
Source§impl<Entry, QS> Clone for VecProgress<Entry, QS>
impl<Entry, QS> Clone for VecProgress<Entry, QS>
Source§fn clone(&self) -> VecProgress<Entry, QS>
fn clone(&self) -> VecProgress<Entry, QS>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more