Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
Signed-off-by: gengliqi <[email protected]>
  • Loading branch information
gengliqi committed Dec 17, 2020
1 parent 12949ab commit 147108d
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,27 +974,25 @@ impl<T: Storage> Raft<T> {
/// Notifies that these raft logs or snapshot have been persisted.
pub fn on_persist_entries(&mut self, index: u64, term: u64) {
let update = self.raft_log.maybe_persist(index, term);
// Actually, if it is a leader and persisted index is updated, this term
// must be equal to self.term because the persisted index must be equal to
// the last index of entries from previous leader when it becomes leader
// (see the comments in become_leader), namely, the new persisted entries
// must come from this leader. Here checking the term just for robustness.
if update && self.state == StateRole::Leader {
if term == self.term {
let self_id = self.id;
let pr = self.mut_prs().get_mut(self_id).unwrap();
pr.maybe_update(index);
if self.maybe_commit() && self.should_bcast_commit() {
self.bcast_append();
}
} else {
// Actually, if it is a leader and persisted index is updated, this term
// must be equal to self.term because the persisted index must be equal to
// the last index of entries from previous leader when it becomes leader
// (see the comments in become_leader), namely, the new persisted entries
// must come from this leader.
if term != self.term {
error!(
self.logger,
"persisted index changed but the term {} is not the same as {}",
"leader's persisted index changed but the term {} is not the same as {}",
term,
self.term
);
}
let self_id = self.id;
let pr = self.mut_prs().get_mut(self_id).unwrap();
if pr.maybe_update(index) && self.maybe_commit() && self.should_bcast_commit() {
self.bcast_append();
}
}
}

Expand Down

0 comments on commit 147108d

Please sign in to comment.