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

NRG (2.11): Completeness/consistency after leader changes #6485

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

MauriceVanVeen
Copy link
Member

Previously #6194 implemented a way to wait for entries that are stored in the new leader's log but not yet applied, before allowing 'expected per subject' operations to go through. This protected against KV/stream desync.

That protection is now extended to the whole of (clustered) JetStream, and not specific to this one operation anymore. Meaning that if the new leader recognizes it has entries in its log that have not yet been applied, it waits for those to be applied before responding to any read/write operations. In essence it's the 'Leader Completeness Property' as described by the Raft paper. This also brings us closer to 'read-your-writes' when only requesting reads from the leader.

Signed-off-by: Maurice van Veen github@mauricevanveen.com

if n.pindex > n.applied {
n.aflr = n.pindex
} else {
n.aflr = 0
Copy link
Member

Choose a reason for hiding this comment

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

Not entirely clear what 0 means here, I know the comment above says signalling disabled, but is that implying this doesn't track upwards with applied always?

Copy link
Member Author

Choose a reason for hiding this comment

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

We only need to track if we have a log with entries that are not applied. If all our entries are applied we can signal immediately. Resetting n.aflr is just for sanity so we couldn't signal leader twice.

Have added this comment:

// We know we have applied all entries in our log and can signal immediately.
// For sanity reset applied floor back down to 0, so we aren't able to signal twice.

server/raft.go Outdated Show resolved Hide resolved
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
@MauriceVanVeen MauriceVanVeen force-pushed the maurice/nrg-leader-change-consistency branch from 8916405 to 43e7a02 Compare February 10, 2025 14:11
Copy link
Member

@neilalexander neilalexander left a comment

Choose a reason for hiding this comment

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

LGTM

@derekcollison derekcollison merged commit 8ed3361 into main Feb 10, 2025
5 checks passed
@derekcollison derekcollison deleted the maurice/nrg-leader-change-consistency branch February 10, 2025 17:01
derekcollison added a commit that referenced this pull request Feb 10, 2025
Reverts #6415 and
#6426. If duplication would
be deferred to be done by a replica, and that replica was down for at
least 'dupe window+5s', and it would clean up the dedupe map. A message
that was meant to be duplicate could be passed as a genuine message,
resulting in stream desync.

Instead, the dedupe map should be cleared of any staged zero-sequences.
However, that was not possible before as a new leader would not always
be fully up-to-date when it starts responding to new write requests,
which could result in duplicate messages as well.

However, relying on the 'Leader Completeness Property' implemented here:
#6485, we can confidently
clear the dedupe map now of any staged zero-sequences (knowing they were
not proposed). Ensuring both there's no desync, and a failed proposal
for a message would not block subsequent messages with the same dedupe
ID.

Have left the commits as separate, to ease reviewing.

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
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.

3 participants