From 1fcdb475c3fd29b5ad88a391401c8a851a5ddb6f 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 | 26 ++++++++++++++++++++++++++ src/tracker/progress.rs | 6 ++++++ 2 files changed, 32 insertions(+) diff --git a/src/raft.rs b/src/raft.rs index acee1bc5..df0e807e 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -3036,4 +3036,30 @@ 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_replicate_state(&self, id: u64) -> bool { + self.prs() + .get(id) + .map_or(false, |pr| pr.is_replicate_state()) + } } diff --git a/src/tracker/progress.rs b/src/tracker/progress.rs index 2f86f5a7..16b6697d 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_replicate_state(&self) -> bool { + self.state == ProgressState::Replicate + } + /// Determine whether progress is paused. #[inline] pub fn is_paused(&self) -> bool {