Skip to content

Commit

Permalink
[Raft] Add prevote to make it better (#3322)
Browse files Browse the repository at this point in the history
* prevote

* remove term in AskForVoteResp

* address @kikimo's comments

* rename proposedTerm_ to votedTerm_

* fix leader can't work when term changed during sending logs

Co-authored-by: yaphet <[email protected]>
  • Loading branch information
critical27 and darionyaphet authored Nov 25, 2021
1 parent 6a8a5f7 commit c6d1046
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 166 deletions.
1 change: 1 addition & 0 deletions src/interface/raftex.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct AskForVoteRequest {
5: TermID term; // Proposed term
6: LogID last_log_id; // The last received log id
7: TermID last_log_term; // The term receiving the last log
8: bool is_pre_vote; // Is pre vote or not
}


Expand Down
5 changes: 2 additions & 3 deletions src/kvstore/Listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void Listener::start(std::vector<HostAddr>&& peers, bool) {

lastLogId_ = wal_->lastLogId();
lastLogTerm_ = wal_->lastLogTerm();
term_ = proposedTerm_ = lastLogTerm_;
term_ = lastLogTerm_;

// Set the quorum number
quorum_ = (peers.size() + 1) / 2;
Expand Down Expand Up @@ -273,10 +273,9 @@ void Listener::resetListener() {
reset();
VLOG(1) << folly::sformat(
"The listener has been reset : leaderCommitId={},"
"proposedTerm={}, lastLogTerm={}, term={},"
"lastLogTerm={}, term={},"
"lastApplyLogId={}",
leaderCommitId_,
proposedTerm_,
lastLogTerm_,
term_,
lastApplyLogId_);
Expand Down
Loading

0 comments on commit c6d1046

Please sign in to comment.