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.
This commit is contained in:
Konstantin Osipov
2021-02-27 17:35:04 +03:00
parent 32d386d0d8
commit 66c729da66

View File

@@ -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<Message, append_request>) {
if constexpr (std::is_same_v<Message, append_request> ||
std::is_same_v<Message, install_snapshot>) {
leader = from;
} else {
if constexpr (std::is_same_v<Message, vote_request>) {