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

Support checking assertion of Leadership #625

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

otoolep
Copy link
Contributor

@otoolep otoolep commented Oct 16, 2024

Potential fix for #621

This allows clients of this library to check if the current node, assuming it is the Leader, has explicitly asserted leadership in the current term. "Asserting" is defined has having committed at least one log entry in the current term, as per the Raft paper.

This change adds a new channel, which is only serviced when in Leadership mode. This channel will respond with the asserted status via a Future. Clients are recommended to call this function only until they have confirmed that the leadership has been asserted. Once asserted for a given term the state can be cached until the end of the term.

This code is necessary to properly implement the Read Optimization outlined in the Raft paper and dissertation. The dissertation explains that it is not sufficient to simply check the Leader's commit index. Instead a client must first confirm that the Leader has explicitly asserted leadership by committing a log entry in the current term. Only then is commit index valid.

@otoolep otoolep requested review from a team as code owners October 16, 2024 13:05
@otoolep otoolep requested review from skpratt and removed request for a team October 16, 2024 13:05
@otoolep
Copy link
Contributor Author

otoolep commented Oct 16, 2024

This is a follow up to #560

@@ -788,6 +802,7 @@ func (r *Raft) leaderLoop() {
oldCommitIndex := r.getCommitIndex()
commitIndex := r.leaderState.commitment.getCommitIndex()
r.setCommitIndex(commitIndex)
leadershipAsserted = true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not 100% this is correct, I'd like some advice. What we're really trying to do here is catch when the Noop log entry generated here makes it to this point in the code i.e. when the Noop log entry is committed.

@otoolep
Copy link
Contributor Author

otoolep commented Oct 16, 2024

Would you appreciate any help on the test failure, don't immediately see how it could be related to this change.

@otoolep
Copy link
Contributor Author

otoolep commented Oct 18, 2024

Looks like a racy test, passes now.

Any input on this PR?

@otoolep
Copy link
Contributor Author

otoolep commented Dec 12, 2024

Gentle ping on this PR.

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.

1 participant