-
Notifications
You must be signed in to change notification settings - Fork 995
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
base: main
Are you sure you want to change the base?
Conversation
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 |
There was a problem hiding this comment.
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.
Would you appreciate any help on the test failure, don't immediately see how it could be related to this change. |
Looks like a racy test, passes now. Any input on this PR? |
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.