From 158f7f1b9ea3a2457f21b07db107be4871fef8a6 Mon Sep 17 00:00:00 2001 From: Jay Lee Date: Sun, 7 Mar 2021 22:25:50 +0800 Subject: [PATCH] reject prevote explicitly when in lease Signed-off-by: Jay Lee --- src/raft.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/raft.rs b/src/raft.rs index 8a539f114..55d7b3ec5 100644 --- a/src/raft.rs +++ b/src/raft.rs @@ -1289,6 +1289,18 @@ impl Raft { "msg type" => ?m.get_msg_type(), ); + // When judge_split_prevote, reject explicitly to make candidate exit PreCandiate early + // so it will vote for other peer later. + if self.judge_split_prevote + && m.get_msg_type() == MessageType::MsgRequestPreVote + { + let mut to_send = + new_message(m.from, MessageType::MsgRequestPreVoteResponse, None); + to_send.term = m.term; + to_send.reject = true; + self.r.send(to_send, &mut self.msgs); + } + return Ok(()); } }