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

Added detection of the node with longest log during leader election process #17915

Merged
merged 4 commits into from
Apr 22, 2024

Conversation

mmaslankaprv
Copy link
Member

@mmaslankaprv mmaslankaprv commented Apr 17, 2024

Making Raft leader election unsuccessful if one of the votes has log which is more up to data than the current candidate. This solution will allow us to minimise the data loss risk when using relaxed consistency writes. With the optimisation included in this PR a candidate will wait up to election timeout for the replies from all of the nodes and will fail the leader election if any of the voters log is more up to date. The solution included in this PR favour the nodes with longest log to become a leader without compromising availability as it is still enough for the majority to vote for the candidate for it to become a leader.

Another way of seeing this solution is that the candidate will use information about voter logs if they are available instead of ignoring the one with longest log and moving on with the majority based decision.

The detection mechanism can be controller in runtime with raft_enable_longest_log_detection cluster configuration flag.

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
  • v23.3.x
  • v23.2.x

Release Notes

Improvements

  • minimising possibility of data loss when using relaxed conistency replication

@mmaslankaprv
Copy link
Member Author

/dt

@mmaslankaprv
Copy link
Member Author

/dt

@mmaslankaprv
Copy link
Member Author

/dt

@mmaslankaprv mmaslankaprv marked this pull request as ready for review April 18, 2024 05:33
@mmaslankaprv mmaslankaprv requested a review from a team as a code owner April 18, 2024 05:33
@mmaslankaprv mmaslankaprv modified the milestone: 24.1.1-GA Apr 18, 2024
src/v/raft/vote_stm.cc Outdated Show resolved Hide resolved
src/v/raft/vote_stm.cc Show resolved Hide resolved
return with_gate(
_vote_bg,
[this] {
return _sem.wait(_ptr->_jit.base_duration(), 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

we can only wait for

(_requests_dispatched_ts + _ptr->_jit.base_duration() - clock_type::now()) ?

Copy link
Member Author

Choose a reason for hiding this comment

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

i think it depends, the vote_request timeout is larger than the election timeout, indeed i can adjust wait timeout here to be dependent from the dispatch timestamp

src/v/raft/vote_stm.h Outdated Show resolved Hide resolved
Signed-off-by: Michał Maślanka <michal@redpanda.com>
Signed-off-by: Michał Maślanka <michal@redpanda.com>
Signed-off-by: Michał Maślanka <michal@redpanda.com>
src/v/raft/group_configuration.h Outdated Show resolved Hide resolved
src/v/raft/vote_stm.cc Show resolved Hide resolved
src/v/raft/vote_stm.h Show resolved Hide resolved
@mmaslankaprv mmaslankaprv force-pushed the vote-improvment branch 2 times, most recently from d274239 to ea08cb6 Compare April 22, 2024 10:58
Signed-off-by: Michał Maślanka <michal@redpanda.com>
@mmaslankaprv
Copy link
Member Author

ci failure: #17847

@mmaslankaprv mmaslankaprv merged commit 5d11fbf into redpanda-data:dev Apr 22, 2024
14 of 17 checks passed
@mmaslankaprv mmaslankaprv deleted the vote-improvment branch April 22, 2024 15:38
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