pub struct LeaderState {
pub next_index: HashMap<NodeId, LogIndex>,
pub match_index: HashMap<NodeId, LogIndex>,
}Expand description
Volatile state on leaders (reinitialized after election)
Fields§
§next_index: HashMap<NodeId, LogIndex>For each server, index of the next log entry to send to that server
match_index: HashMap<NodeId, LogIndex>For each server, index of highest log entry known to be replicated on server
Implementations§
Source§impl LeaderState
impl LeaderState
Sourcepub fn update_success(&mut self, peer: NodeId, match_idx: LogIndex)
pub fn update_success(&mut self, peer: NodeId, match_idx: LogIndex)
Update next_index for a peer after successful replication
Sourcepub fn update_failure(&mut self, peer: NodeId)
pub fn update_failure(&mut self, peer: NodeId)
Update next_index for a peer after failed replication
Sourcepub fn update_failure_with_hint(
&mut self,
peer: NodeId,
conflict_index: Option<LogIndex>,
_conflict_term: Option<Term>,
follower_last_index: LogIndex,
)
pub fn update_failure_with_hint( &mut self, peer: NodeId, conflict_index: Option<LogIndex>, _conflict_term: Option<Term>, follower_last_index: LogIndex, )
Update next_index for a peer after failed replication using conflict hints.
This implements the “fast backup” optimization from the Raft paper: instead of decrementing next_index one at a time, we jump back to the conflict point reported by the follower.
conflict_index: the first index of the conflicting term on the followerconflict_term: the term of the conflicting entryfollower_last_index: the follower’s last log index
If the leader has entries with conflict_term, it sets next_index to
the index after its last entry of that term. Otherwise, it sets
next_index to conflict_index.
Sourcepub fn calculate_commit_index_joint(
&self,
leader_id: NodeId,
current_last_index: LogIndex,
config_state: &ConfigState,
) -> LogIndex
pub fn calculate_commit_index_joint( &self, leader_id: NodeId, current_last_index: LogIndex, config_state: &ConfigState, ) -> LogIndex
Calculate the commit index considering joint consensus.
During joint consensus, an entry must be replicated to a majority of both the old and new configurations. The leader itself counts toward both configs.
Sourcepub fn get_next_index(&self, peer: NodeId) -> LogIndex
pub fn get_next_index(&self, peer: NodeId) -> LogIndex
Get next_index for a peer
Sourcepub fn get_match_index(&self, peer: NodeId) -> LogIndex
pub fn get_match_index(&self, peer: NodeId) -> LogIndex
Get match_index for a peer
Sourcepub fn calculate_commit_index(
&self,
current_index: LogIndex,
quorum_size: usize,
) -> LogIndex
pub fn calculate_commit_index( &self, current_index: LogIndex, quorum_size: usize, ) -> LogIndex
Calculate the commit index based on match_index values Returns the highest index that is replicated on a majority of servers
Trait Implementations§
Source§impl Clone for LeaderState
impl Clone for LeaderState
Source§fn clone(&self) -> LeaderState
fn clone(&self) -> LeaderState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for LeaderState
impl RefUnwindSafe for LeaderState
impl Send for LeaderState
impl Sync for LeaderState
impl Unpin for LeaderState
impl UnsafeUnpin for LeaderState
impl UnwindSafe for LeaderState
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.