Skip to content

Commit

Permalink
Interface of querying the information of progress which supports agen…
Browse files Browse the repository at this point in the history
…t selection

Signed-off-by: LintianShi <[email protected]>
  • Loading branch information
LintianShi committed Sep 21, 2022
1 parent 40a8fcd commit 1fcdb47
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3036,4 +3036,30 @@ impl<T: Storage> Raft<T> {
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<u64> {
self.prs().get(id).map(|pr| pr.next_idx)
}

/// Get the matched of peer.
#[inline]
pub fn get_matched(&self, id: u64) -> Option<u64> {
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())
}
}
6 changes: 6 additions & 0 deletions src/tracker/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1fcdb47

Please sign in to comment.