From 66c729da663e81c3302b67aa6c5fe296984792a7 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Sat, 27 Feb 2021 17:35:04 +0300 Subject: [PATCH] raft: set the current leader upon getting InstallSnapshot If the current leader is set, the follower will not vote for another candidate. This is also known as "sticky leadership" rule. Before this change, the rule was enacted only upon receiving AppendEntries RPC from the leader. Turn it on also upon receiving InstallSnapshot RPC. --- raft/fsm.hh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/raft/fsm.hh b/raft/fsm.hh index ba222dbcf3..191f2d9f74 100644 --- a/raft/fsm.hh +++ b/raft/fsm.hh @@ -386,7 +386,8 @@ void fsm::step(server_id from, Message&& msg) { logger.trace("{} [term: {}] received a message with higher term from {} [term: {}]", _my_id, _current_term, from, msg.current_term); - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v || + std::is_same_v) { leader = from; } else { if constexpr (std::is_same_v) {