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

raft: set electionElapsed to electionTimeout in defortify() regardless of state #136025

Merged
merged 1 commit into from
Nov 22, 2024

Conversation

iskettaneh
Copy link
Contributor

@iskettaneh iskettaneh commented Nov 22, 2024

Previously, we use to set electionElapsed to electionTimeout inside defortify() only when we are not the leader. We did this as an extra defense because we didn't want to increment the electionTimeout when we are the leader. However, there is no need for this extra complexity since in all cases where we call defortify when we are the leader, we either immediately step down (which resets the electionElapsed to 0), or we are okay performing a checkQuorum (in the case where a leader receive a MsgPreVote from a higher term while it's not in leader-lease)

Epic: None

Release note: None

@iskettaneh iskettaneh requested a review from a team as a code owner November 22, 2024 19:57
@cockroach-teamcity
Copy link
Member

This change is Reviewable

…s of state

Previously, we use to set electionElapsed to electionTimeout inside
defortify() only when we are not the leader. We did this as an extra
defense because we didn't want to increment the electionTimeout when we
are the leader. However, there is no need for this extra complexity
since in all cases where we call defortify when we are the leader, we
either immediately step down (which resets the electionElapsed to 0),
or we are okay performing a checkQuorum (in the case where a leader
receive a MsgPreVote from a higher term while it's not in leader-lease)

Epic: None

Release note: None
Copy link
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 7 of 7 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @iskettaneh)

@iskettaneh
Copy link
Contributor Author

TFTR!

bors r+

@craig craig bot merged commit 646bf4e into cockroachdb:master Nov 22, 2024
22 of 23 checks passed
craig bot pushed a commit that referenced this pull request Nov 25, 2024
134990: raft: forget the leader when stepping down if it's safe r=iskettaneh a=iskettaneh

First commit is based on #136025

This PR makes the leader forget that it was the leader when stepping down if it's safe to do so. The places this PR changes:

1) When stepping down due to CheckQuorum.
2) When stepping down due to leadership transfer.
3) When stepping down due to becoming a learner.
4) After a restart.
5) After a VoteLoss.

Epic: none

Release note: None

Co-authored-by: Ibrahim Kettaneh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants