Skip to content

Commit

Permalink
rename proposedTerm_ to votedTerm_
Browse files Browse the repository at this point in the history
  • Loading branch information
critical27 committed Nov 18, 2021
1 parent 1e95430 commit ea84821
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
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
6 changes: 3 additions & 3 deletions src/kvstore/raftex/RaftPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1323,8 +1323,8 @@ void RaftPart::processAskForVoteRequest(const cpp2::AskForVoteRequest& req,
* not enough votes: the candidate will trigger another round election
* majority votes: the candidate will be leader
*/
if (proposedTerm_ == req.get_term() && votedAddr_ != candidate) {
LOG(INFO) << idStr_ << "We have voted " << votedAddr_ << " on term " << proposedTerm_
if (votedTerm_ == req.get_term() && votedAddr_ != candidate) {
LOG(INFO) << idStr_ << "We have voted " << votedAddr_ << " on term " << votedTerm_
<< ", so we should reject the candidate " << candidate << " request on term "
<< req.get_term();
resp.set_error_code(cpp2::ErrorCode::E_TERM_OUT_OF_DATE);
Expand All @@ -1351,7 +1351,7 @@ void RaftPart::processAskForVoteRequest(const cpp2::AskForVoteRequest& req,
}
role_ = Role::FOLLOWER;
votedAddr_ = candidate;
proposedTerm_ = req.get_term();
votedTerm_ = req.get_term();
leader_ = HostAddr("", 0);

// Reset the last message time
Expand Down
8 changes: 3 additions & 5 deletions src/kvstore/raftex/RaftPart.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,17 +515,15 @@ class RaftPart : public std::enable_shared_from_this<RaftPart> {
HostAddr leader_;

// After voted for somebody, it will not be empty anymore.
// And it will be reset to empty after current election finished.
HostAddr votedAddr_;

// The current term id
// the term id proposed by that candidate
TermID term_{0};

// If voted for somebody, the proposeTerm will be reset to the candidate
// propose term. So we could use it to prevent revote if someone else ask for
// vote for current proposedTerm.
TermID proposedTerm_{0};
// Once we have voted some one in formal election, we will set votedTerm_ and votedAddr_.
// To prevent we have voted more than once in a same term
TermID votedTerm_{0};

// The id and term of the last-sent log
LogID lastLogId_{0};
Expand Down

0 comments on commit ea84821

Please sign in to comment.