diff --git a/src/raft.rs b/src/raft.rs index d11c697b..19162d76 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -3043,4 +3043,52 @@ impl Raft { pr.ins.set_cap(cap); } } + + /// Whether this RawNode is active recently. + pub fn is_recent_active(&self, id: u64) -> bool { + if let Some(pr) = self.prs().get(id) { + if pr.recent_active { + return true; + } + } + false + } + + /// Get the next idx of peer. + #[inline] + pub fn get_next_idx(&self, id: u64) -> Option { + self.prs().get(id).map(|pr| pr.next_idx) + } + + /// Get the matched of peer. + #[inline] + pub fn get_matched(&self, id: u64) -> Option { + self.prs().get(id).map(|pr| pr.matched) + } + + /// Determine whether a progress is in Replicate state. + pub fn is_replicate_state(&self, id: u64) -> bool { + if let Some(pr) = self.prs().get(id) { + if pr.is_replicate_state() { + return true; + } + } + false + } + + /// Determine whether a progress lags. + pub fn is_lag(&self, id: u64) -> bool { + if let Some(pr) = self.prs().get(id) { + if pr.lag { + return true; + } + } + false + } + + /// Determine whether this is the leader. + #[inline] + pub fn is_leader(&self) -> bool { + self.id == self.leader_id + } } diff --git a/src/raw_node.rs b/src/raw_node.rs index a15a1489..bd41d146 100644 --- a/src/raw_node.rs +++ b/src/raw_node.rs @@ -786,12 +786,6 @@ impl RawNode { pub fn skip_bcast_commit(&mut self, skip: bool) { self.raft.skip_bcast_commit(skip) } - - /// Set whether to batch append msg at runtime. - #[inline] - pub fn set_batch_append(&mut self, batch_append: bool) { - self.raft.set_batch_append(batch_append) - } } #[cfg(test)] diff --git a/src/tracker/progress.rs b/src/tracker/progress.rs index ddba2974..19e73ceb 100644 --- a/src/tracker/progress.rs +++ b/src/tracker/progress.rs @@ -212,6 +212,12 @@ impl Progress { true } + /// Determine whether progress is in the Replicate state; + #[inline] + pub fn is_replicate_state(&self) -> bool { + self.state == ProgressState::Replicate + } + /// Determine whether progress is paused. #[inline] pub fn is_paused(&self) -> bool {