From 19973a05e4739a26578c6b1e89643e9c75feec08 Mon Sep 17 00:00:00 2001 From: "A. Hobden" Date: Tue, 14 Aug 2018 10:39:46 -0700 Subject: [PATCH] raft: No longer scan raft log when becoming a lead. (#100) --- src/raft.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/raft.rs b/src/raft.rs index e0b681a81..dd2eec435 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -758,17 +758,13 @@ impl Raft { self.reset(term); self.leader_id = self.id; self.state = StateRole::Leader; - let begin = self.raft_log.committed + 1; - let ents = self - .raft_log - .entries(begin, raft_log::NO_LIMIT) - .expect("unexpected error getting uncommitted entries"); + // Conservatively set the pending_conf_index to the last index in the // log. There may or may not be a pending config change, but it's // safe to delay any future proposals until we commit all our // pending log entries, and scanning the entire tail of the log // could be expensive. - self.pending_conf_index = ents.last().map_or(0, |e| e.get_index()); + self.pending_conf_index = self.raft_log.last_index(); self.append_entry(&mut [Entry::new()]); info!("{} became leader at term {}", self.tag, self.term);