Open
Conversation
5c383ae to
f3a27bb
Compare
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
f3a27bb to
e6ef786
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements leader leases to ensure linearizable reads for parts of the JS API, like MsgGet, but does NOT include APIs like DirectGet currently. Ensuring an old leader (that can't refresh the lease) doesn't answer read requests after its lease expires.
This is safe based on the "LeaseGuard: Raft Leases Done Right" paper describing using the Raft log to renew the leader lease. Although we don't use the 'inherited lease reads' and 'deferred writes' optimizations, since any changes depend on the former ones being applied (especially for a stream).
Although the paper describes needing to take clock uncertainty/skew into account, in "5.3. Leases without bounded-uncertainty clocks" it describes using local timers instead. Since we use Go's monotonic clock with a lease timeout that equals the minimum election timeout, this has minimal to no impact on our current Raft implementation in terms of when elections take place.
This PR adds a "noop-entry" to be able to write and renew the leader lease. Since this entry is otherwise empty, this poses no backward-compatibility issues either. An old server version will know how to handle it without issue, that is: 'do nothing except store it in the log', which is intended.
Relates to nats-io/nats-architecture-and-design#390
Signed-off-by: Maurice van Veen github@mauricevanveen.com