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 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more