-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Raft] Add prevote to make it better #3322
Conversation
please fix the conflict thanks ~ |
|
||
// The method returns the partition's role after the election | ||
Role processElectionResponses(const ElectionResponses& results, | ||
// Return true if I have been granted majority votes on proposedTerm, no matter isPreVote or not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments of this method is exact the same as the above one...
if (needToStartElection()) { | ||
if (leaderElection().get()) { | ||
VLOG(2) << idStr_ << "Stop the election"; | ||
if (leaderElection(true).get() && leaderElection(false).get()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call leaderElection
twice in a row 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is looks simpler
Wait @kikimo to do a final test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM , it's time to merge and I'll retest all these raft PRs later.
Reference
See $9.6 in https://web.stanford.edu/~ouster/cgi-bin/papers/OngaroPhD.pdf, my implementation is almost same in https://www.openlife.cc/sites/default/files/4-modifications-for-Raft-consensus.pdf
Change notes:
current_term + 1
to start a prevote, if I get majority votes, then start a formal election with++current_term
(which is the same term in prevote). I believe most of the election logic is same as paper after this PR. Many scenario when we failed to get a leader will be eliminated.wal_->rollbackToLog(lastLogId_);
is added, because if term changed during sending logs, thelastLogId_
won't be updated. However, since we have write some logs into wal, if we don't rollback those logs, we can't write any logs anymore because the logId inconsistency in wal.Close #3108
@kikimo and I will do some test first, but ready to review.