Skip to content
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

Do not request votes if term changed in prevote phase #18394

Merged
merged 3 commits into from May 14, 2024

Conversation

mmaslankaprv
Copy link
Member

@mmaslankaprv mmaslankaprv commented May 10, 2024

In vote stm we didn't mark the vote replies with greater term as not granted votes. This may lead to unnecessary leader elections and longer recovery after failures. Change the logic in vote_stm to explicitly mark vote responses with greater term as failed. Additional check was added in consensus to recognise if a candidate state changed in between the pre-vote and vote phase.

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v24.1.x
  • v23.3.x
  • v23.2.x

Release Notes

Improvements

  • Made electing a leader faster

@mmaslankaprv
Copy link
Member Author

ci failure: #13275

ztlpn
ztlpn previously approved these changes May 13, 2024
src/v/raft/vote_stm.h Outdated Show resolved Hide resolved
@@ -84,6 +88,10 @@ class vote_stm {
}

if (value->has_value()) {
if (value->value().term != _vote_stm._req.term) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if != should be >? Or is < impossible because the other side will always update its term?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly, it is impossible in geral we should never treat replies coming from different ter as succesfull

src/v/raft/vote_stm.h Outdated Show resolved Hide resolved
In vote stm we didn't mark the vote replies with greater term as not
granted votes. This may lead to unnecessary leader elections and longer
recovery after failures. Change the logic in `vote_stm` to explicitly
mark vote responses with greater term as failed.

Signed-off-by: Michał Maślanka <michal@redpanda.com>
phases

If term changed between pre-vote and actual vote phase a candidate
should not proceed and request votes.

Signed-off-by: Michał Maślanka <michal@redpanda.com>
Added more logging about the start and result of pre-vote election.

Signed-off-by: Michał Maślanka <michal@redpanda.com>
@mmaslankaprv mmaslankaprv merged commit fabba81 into redpanda-data:dev May 14, 2024
13 of 17 checks passed
@mmaslankaprv mmaslankaprv deleted the fix-prevote-term branch May 14, 2024 12:32
@vbotbuildovich
Copy link
Collaborator

/backport v24.1.x

@vbotbuildovich
Copy link
Collaborator

/backport v23.3.x

@vbotbuildovich
Copy link
Collaborator

Failed to create a backport PR to v23.3.x branch. I tried:

git remote add upstream https://github.com/redpanda-data/redpanda.git
git fetch --all
git checkout -b backport-pr-18394-v23.3.x-361 remotes/upstream/v23.3.x
git cherry-pick -x 5adeba30fa53fe696fa5555b46967397fa0547ed 40add5d6bae852bcb5a8c76255522a0fb06a9b71 1f0203fd915d4313614575a690a0a871cf06ff86

Workflow run logs.

@vbotbuildovich
Copy link
Collaborator

Failed to create a backport PR to v24.1.x branch. I tried:

git remote add upstream https://github.com/redpanda-data/redpanda.git
git fetch --all
git checkout -b backport-pr-18394-v24.1.x-0 remotes/upstream/v24.1.x
git cherry-pick -x 5adeba30fa53fe696fa5555b46967397fa0547ed 40add5d6bae852bcb5a8c76255522a0fb06a9b71 1f0203fd915d4313614575a690a0a871cf06ff86

Workflow run logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants