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 (initialized to leader last log index + 1)
match_index: HashMap<NodeId, LogIndex>For each server, index of highest log entry known to be replicated (initialized to 0, increases monotonically)
Implementations§
Source§impl LeaderState
impl LeaderState
Sourcepub fn new(cluster_members: &[NodeId], last_log_index: LogIndex) -> Self
pub fn new(cluster_members: &[NodeId], last_log_index: LogIndex) -> Self
Create new leader state for the given cluster members
Sourcepub fn decrement_next_index(&mut self, node_id: &NodeId)
pub fn decrement_next_index(&mut self, node_id: &NodeId)
Update next_index for a follower (decrement on failure)
Sourcepub fn update_replication(&mut self, node_id: &NodeId, match_index: LogIndex)
pub fn update_replication(&mut self, node_id: &NodeId, match_index: LogIndex)
Update both next_index and match_index for successful replication
Sourcepub fn calculate_commit_index(&self) -> LogIndex
pub fn calculate_commit_index(&self) -> LogIndex
Get the median match_index for determining commit_index
Sourcepub fn get_next_index(&self, node_id: &NodeId) -> Option<LogIndex>
pub fn get_next_index(&self, node_id: &NodeId) -> Option<LogIndex>
Get next_index for a specific follower
Sourcepub fn get_match_index(&self, node_id: &NodeId) -> Option<LogIndex>
pub fn get_match_index(&self, node_id: &NodeId) -> Option<LogIndex>
Get match_index for a specific follower
Trait Implementations§
Source§impl Clone for LeaderState
impl Clone for LeaderState
Source§fn clone(&self) -> LeaderState
fn clone(&self) -> LeaderState
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
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 UnwindSafe for LeaderState
Blanket Implementations§
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
Mutably borrows from an owned value. Read more