Exit early on request vote if already voted
Reviewers: msantl Reviewed By: msantl Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2098
This commit is contained in:
parent
24ae8a759b
commit
d6de4f4295
@ -110,6 +110,14 @@ void RaftServer::Start() {
|
|||||||
if (mode_ != Mode::FOLLOWER) Transition(Mode::FOLLOWER);
|
if (mode_ != Mode::FOLLOWER) Transition(Mode::FOLLOWER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (voted_for_) {
|
||||||
|
bool grant_vote = voted_for_.value() == req.candidate_id;
|
||||||
|
if (grant_vote) SetNextElectionTimePoint();
|
||||||
|
RequestVoteRes res(grant_vote, current_term_);
|
||||||
|
slk::Save(res, res_builder);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// [Raft paper 5.2, 5.4]
|
// [Raft paper 5.2, 5.4]
|
||||||
// "Each server will vote for at most one candidate in a given
|
// "Each server will vote for at most one candidate in a given
|
||||||
// term, on a first-come-first-serve basis with an additional
|
// term, on a first-come-first-serve basis with an additional
|
||||||
@ -118,7 +126,6 @@ void RaftServer::Start() {
|
|||||||
// up-to-date than that of the candidate"
|
// up-to-date than that of the candidate"
|
||||||
auto last_entry_data = LastEntryData();
|
auto last_entry_data = LastEntryData();
|
||||||
bool grant_vote =
|
bool grant_vote =
|
||||||
(!voted_for_ || voted_for_.value() == req.candidate_id) &&
|
|
||||||
AtLeastUpToDate(req.last_log_index, req.last_log_term,
|
AtLeastUpToDate(req.last_log_index, req.last_log_term,
|
||||||
last_entry_data.first, last_entry_data.second);
|
last_entry_data.first, last_entry_data.second);
|
||||||
if (grant_vote) {
|
if (grant_vote) {
|
||||||
|
Loading…
Reference in New Issue
Block a user