Skip to content

Commit d4a8512

Browse files
author
LintianShi
committed
Interface of querying the information of progress
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>
1 parent 4f7147c commit d4a8512

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

src/raft.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,4 +3045,52 @@ impl<T: Storage> Raft<T> {
30453045
pr.ins.set_cap(cap);
30463046
}
30473047
}
3048+
3049+
/// Whether this RawNode is active recently.
3050+
pub fn is_recent_active(&self, id: u64) -> bool {
3051+
if let Some(pr) = self.prs().get(id) {
3052+
if pr.recent_active {
3053+
return true;
3054+
}
3055+
}
3056+
false
3057+
}
3058+
3059+
/// Get the next idx of peer.
3060+
#[inline]
3061+
pub fn get_next_idx(&self, id: u64) -> Option<u64> {
3062+
self.prs().get(id).map(|pr| pr.next_idx)
3063+
}
3064+
3065+
/// Get the matched of peer.
3066+
#[inline]
3067+
pub fn get_matched(&self, id: u64) -> Option<u64> {
3068+
self.prs().get(id).map(|pr| pr.matched)
3069+
}
3070+
3071+
/// Determine whether a progress is in Replicate state.
3072+
pub fn is_replicate_state(&self, id: u64) -> bool {
3073+
if let Some(pr) = self.prs().get(id) {
3074+
if pr.is_replicate_state() {
3075+
return true;
3076+
}
3077+
}
3078+
false
3079+
}
3080+
3081+
/// Determine whether a progress lags.
3082+
pub fn is_lag(&self, id: u64) -> bool {
3083+
if let Some(pr) = self.prs().get(id) {
3084+
if pr.lag {
3085+
return true;
3086+
}
3087+
}
3088+
false
3089+
}
3090+
3091+
/// Determine whether this is the leader.
3092+
#[inline]
3093+
pub fn is_leader(&self) -> bool {
3094+
self.id == self.leader_id
3095+
}
30483096
}

src/raw_node.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -786,12 +786,6 @@ impl<T: Storage> RawNode<T> {
786786
pub fn skip_bcast_commit(&mut self, skip: bool) {
787787
self.raft.skip_bcast_commit(skip)
788788
}
789-
790-
/// Set whether to batch append msg at runtime.
791-
#[inline]
792-
pub fn set_batch_append(&mut self, batch_append: bool) {
793-
self.raft.set_batch_append(batch_append)
794-
}
795789
}
796790

797791
#[cfg(test)]

src/tracker/progress.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ impl Progress {
212212
true
213213
}
214214

215+
/// Determine whether progress is in the Replicate state;
216+
#[inline]
217+
pub fn is_replicate_state(&self) -> bool {
218+
self.state == ProgressState::Replicate
219+
}
220+
215221
/// Determine whether progress is paused.
216222
#[inline]
217223
pub fn is_paused(&self) -> bool {

0 commit comments

Comments
 (0)