Skip to content

[FIXED] Desync after partial catchup from old leader #6943

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

Merged
merged 1 commit into from
Jun 5, 2025

Conversation

MauriceVanVeen
Copy link
Member

When catching up based on a JetStream stream snapshot, the server would not confirm upon receiving EOF that it had received all the data expected by the snapshot. This could result in an old leader responding with EOF too early, the server accepting this as the end of catchup, continuing, and running into last sequence mismatch, resetting replication state.

Receiving catchup messages from any other server, although less than ideal, should not result in issues. All servers should have agreed on the message contents at any given sequence. The server should recognize it was partially caught up, and retry.

Signed-off-by: Maurice van Veen [email protected]

@MauriceVanVeen MauriceVanVeen requested a review from a team as a code owner June 4, 2025 17:25
Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

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

LGTM

mset.mu.RLock()
lseq := mset.lseq
mset.mu.RUnlock()
if lseq == snap.LastSeq {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if it can happen but I'm wondering if >= is safer here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@MauriceVanVeen MauriceVanVeen force-pushed the maurice/catchup-old-leader branch 2 times, most recently from d0f57b3 to 994c846 Compare June 4, 2025 19:26
@MauriceVanVeen
Copy link
Member Author

Had to remove TestJetStreamClusterStreamCatchupWithTruncateAndPriorSnapshot. It does test a situation where the stream leader has an up-to-date log, but a truncated stream. After this PR catchup will never complete. Although this could technically be a bug, the stream honestly has already desynced in a way that's not recoverable at the moment.

@derekcollison
Copy link
Member

This feels like a step backward though. And I am ok with removing tests, but for very good reasons, this feels like we should sort this out before merging this PR.

Had to remove TestJetStreamClusterStreamCatchupWithTruncateAndPriorSnapshot. It does test a situation where the stream leader has an up-to-date log, but a truncated stream. After this PR catchup will never complete. Although this could technically be a bug, the stream honestly has already desynced in a way that's not recoverable at the moment.

@MauriceVanVeen
Copy link
Member Author

Re-added TestJetStreamClusterStreamCatchupWithTruncateAndPriorSnapshot.

The outdated server now doesn't respond at all. And if it's leader still, it steps down. That fixes the above test, because it allows for a new leader to be elected and resolve the desync/make the server current. (This is still assuming a non-desynced leader can be elected.)

That makes our current behavior better, instead of knowingly remove data from the second server. We recognize the current leader has lost upper layer state and needs to step down.

@MauriceVanVeen MauriceVanVeen force-pushed the maurice/catchup-old-leader branch from 994c846 to 97a807e Compare June 4, 2025 20:58
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

@neilalexander neilalexander merged commit 4541eea into main Jun 5, 2025
48 checks passed
@neilalexander neilalexander deleted the maurice/catchup-old-leader branch June 5, 2025 08:34
neilalexander added a commit that referenced this pull request Jun 17, 2025
Includes the following:

- #6922
- #6931
- #6933
- #6934
- #6939
- #6938
- #6940
- #6941
- #6942
- #6943
- #6945
- #6944
- #6947
- #6948
- #6949
- #6956
- #6960
- #6961
- #6951
- #6965
- #6968
- #6981
- #6983
- #6984

Signed-off-by: Neil Twigg <[email protected]>
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