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

Refactor: respond to client even when leader is switched #973

Merged

Conversation

drmingdrmer
Copy link
Member

@drmingdrmer drmingdrmer commented Dec 19, 2023

Changelog

Refactor: respond to client even when leader is switched

Before this commit, the channels used for sending responses to the
client were dropped whenever a leader stepped down, which was not
necessary.

In the current commit, when a leader quits, we now preserve the channel, ensuring that:

  • An OK response is sent to the client if the log entry the client has
    written is successfully committed;

  • Alternatively, a ForwardToLeader error is sent if the log is
    reverted due to a conflict with the new leader.

In short, OpenRaft now makes a concerted effort to deliver a success
message to the client wherever possible.

Two test cases have been added to cover both successful and erroneous
scenarios.

Special thanks to @tvsfx for proposing this refinement :D


This change is Reviewable

Before this commit, the channels used for sending responses to the
client were dropped whenever a leader stepped down, which was not
necessary.

In the current commit, when a leader quits, we now preserve the channel, ensuring that:

- An OK response is sent to the client if the log entry the client has
  written is successfully committed;

- Alternatively, a `ForwardToLeader` error is sent if the log is
  reverted due to a conflict with the new leader.

In short, OpenRaft now makes a concerted effort to deliver a success
message to the client wherever possible.

Two test cases have been added to cover both successful and erroneous
scenarios.

Special thanks to @tvsfx for proposing this refinement :D

- Fix: databendlabs#963
Copy link
Member Author

@drmingdrmer drmingdrmer left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 6 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ariesdevil and @lichuang)

Copy link
Contributor

@tvsfx tvsfx left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 6 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ariesdevil, @drmingdrmer, and @lichuang)


openraft/src/core/raft_core.rs line 1582 at r1 (raw file):

                    AsyncRuntimeOf::<C>::spawn(async move {
                        for (log_index, tx) in removed.into_iter() {
                            let res = tx.send(Err(ClientWriteError::ForwardToLeader(ForwardToLeader {

This is actually a nice extra benefit of this approach that I did not think of; rather than having an empty ForwardToLeader error like before in QuitLeader, you can now redirect the client to the new leader immediately.

@drmingdrmer drmingdrmer merged commit 3aa6b98 into databendlabs:main Dec 19, 2023
24 of 26 checks passed
@drmingdrmer drmingdrmer deleted the 33-no-client-channel-drop branch December 19, 2023 08:09
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.

Refactor: Move client_resp_channels from LeaderData to new tx_...-field in RaftCore
2 participants