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 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
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