-
Notifications
You must be signed in to change notification settings - Fork 579
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
Fixes Raft nodes not to erase their votes on leader step down #14
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,7 @@ ss::future<> vote_stm::vote(bool leadership_transfer) { | |
_ptr->trigger_leadership_notification(); | ||
// 5.2.1.2 | ||
_ptr->_term += model::term_id(1); | ||
_ptr->_voted_for = {}; | ||
|
||
// vote is the only method under _op_sem | ||
_ptr->config().for_each_voter( | ||
|
@@ -186,15 +187,26 @@ ss::future<> vote_stm::wait() { return _vote_bg.close(); } | |
|
||
void vote_stm::update_vote_state(ss::semaphore_units<> u) { | ||
// use reply term to update voter term | ||
bool is_term_behind = false; | ||
|
||
for (auto& [_, r] : _replies) { | ||
if (r.value && r.value->has_value()) { | ||
auto term = r.value->value().term; | ||
if (term > _ptr->_term) { | ||
vlog( | ||
_ctxlog.info, "Vote failed - received larger term: {}", term); | ||
_ptr->_term = term; | ||
_ptr->_voted_for = {}; | ||
is_term_behind = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can simply return here. then we wouldn't need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you also need the vote_state::follower assignment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I'll include it in v2 |
||
} | ||
} | ||
} | ||
|
||
if (is_term_behind) { | ||
_ptr->_vstate = consensus::vote_state::follower; | ||
return; | ||
} | ||
|
||
if (_ptr->_vstate != consensus::vote_state::candidate) { | ||
vlog(_ctxlog.info, "No longer a candidate, ignoring vote replies"); | ||
return; | ||
|
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.
I think we do not need to store
_last_election
this is what the voted_for is for. Vote casting is done under the semaphore even if another fiber requested vote with the same term thevoted_for
would be already set to some value so the vote not be granted.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.
Got it, I haven't noticed the semaphore and wanted to avoid concurrency issues, will send v2