From d0834f56412aa642b05f598f0c61c664ba3bd05d Mon Sep 17 00:00:00 2001 From: LintianShi Date: Wed, 10 Aug 2022 14:47:24 +0800 Subject: [PATCH] Interface of querying the information of progress which supports agent selection Signed-off-by: LintianShi --- src/raft.rs | 24 ++++++++++++++++++++++++ src/tracker/progress.rs | 6 ++++++ 2 files changed, 30 insertions(+) diff --git a/src/raft.rs b/src/raft.rs index acee1bc5..58f359d7 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -3036,4 +3036,28 @@ impl Raft { pr.ins.set_cap(cap); } } + + /// Whether this RawNode is active recently. + #[inline] + pub fn is_recent_active(&self, id: u64) -> bool { + self.prs().get(id).map_or(false, |pr| pr.recent_active) + } + + /// 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. + #[inline] + pub fn is_replicating(&self, id: u64) -> bool { + self.prs().get(id).map_or(false, |pr| pr.is_replicating()) + } } diff --git a/src/tracker/progress.rs b/src/tracker/progress.rs index 2f86f5a7..432e0d55 100644 --- a/src/tracker/progress.rs +++ b/src/tracker/progress.rs @@ -203,6 +203,12 @@ impl Progress { true } + /// Determine whether progress is in the Replicate state; + #[inline] + pub fn is_replicating(&self) -> bool { + self.state == ProgressState::Replicate + } + /// Determine whether progress is paused. #[inline] pub fn is_paused(&self) -> bool {