From b0a374060334a35442e7da1f3769599de7a040ed Mon Sep 17 00:00:00 2001 From: GuyLewin Date: Mon, 3 Jul 2023 09:22:29 -0400 Subject: [PATCH] fix: pr comments Signed-off-by: GuyLewin --- src/raft.rs | 2 +- src/tracker.rs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/raft.rs b/src/raft.rs index 17a1bc70..1c3e79a6 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -380,7 +380,7 @@ impl Raft { if raft_state.hard_state != HardState::default() { r.load_state(&raft_state.hard_state); } - if r.term == 0 { + if !r.prs.is_empty() && r.term == 0 { fatal!(r.logger, "Invalid term value: 0"); } if c.applied > 0 { diff --git a/src/tracker.rs b/src/tracker.rs index 4814d381..6d22751c 100644 --- a/src/tracker.rs +++ b/src/tracker.rs @@ -240,6 +240,10 @@ impl ProgressTracker { self.votes.clear(); } + pub(crate) fn is_empty(&self) -> bool { + self.progress.is_empty() && self.votes.is_empty() + } + /// Returns true if (and only if) there is only one voting member /// (i.e. the leader) in the current configuration. pub fn is_singleton(&self) -> bool {