Skip to content

Commit

Permalink
Interface of querying the information of progress
Browse files Browse the repository at this point in the history
Signed-off-by: LintianShi <lintian.shi@pingcap.com>

Add interface of query matched of progress

Signed-off-by: LintianShi <lintian.shi@pingcap.com>

Interface of querying last_idx of raft node

Signed-off-by: LintianShi <lintian.shi@pingcap.com>

Interface of query whether a progress lags behind

Signed-off-by: LintianShi <lintian.shi@pingcap.com>
  • Loading branch information
LintianShi committed Sep 15, 2022
1 parent 4f7147c commit d4a8512
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
48 changes: 48 additions & 0 deletions src/raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3045,4 +3045,52 @@ impl<T: Storage> Raft<T> {
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<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.
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
}
}
6 changes: 0 additions & 6 deletions src/raw_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,12 +786,6 @@ impl<T: Storage> RawNode<T> {
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)]
Expand Down
6 changes: 6 additions & 0 deletions src/tracker/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d4a8512

Please sign in to comment.