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

Don't unconditionally send consumer snapshot when becoming leader #4965

Merged
merged 1 commit into from Jan 18, 2024

Conversation

neilalexander
Copy link
Member

Feasibly a Raft node that is keeping up with its peers can become a leader regardless of whether or not the upper layer is caught up with its applies. Since the leader change notification to the upper state machine could interleave with the apply queue, then unconditionally sending a snapshot as a new append entry on consumer leader transitions could cause the rest of the group to revert to an earlier consumer state.

Signed-off-by: Neil Twigg neil@nats.io

@neilalexander neilalexander requested a review from a team as a code owner January 17, 2024 15:00
@@ -4660,16 +4660,6 @@ func (js *jetStream) monitorConsumer(o *consumer, ca *consumerAssignment) {
js.setConsumerAssignmentRecovering(ca)
}

// Synchronize everyone to our state.
Copy link
Member

Choose a reason for hiding this comment

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

Should we remove all together or adjust to make sure our upper state is correct?

It is there for a reason :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you remember what that reason was? I can't find anything written down as to why, the best I can find is from the commit message in cc77d66 which says:

Also sync other consumers when taking over as leader but no need to process snapshots when we are in fact the leader.

As far as I can tell everything should work without this because the Raft machinery would be keeping the ConsumerStore up-to-date on the replicas in the usual way anyway, whereas sending snapshots from the upper layer directly opens up a potential for a race between the committed Raft node state and the applied upper layer state, but I'm not sure if I'm missing something here.

Copy link
Member

Choose a reason for hiding this comment

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

We were experiencing state skew, and I wanted us synched. But could have been from a prior bug that has since been corrected.

@derekcollison derekcollison self-requested a review January 18, 2024 00:42
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

@derekcollison derekcollison merged commit 52b3944 into main Jan 18, 2024
4 checks passed
@derekcollison derekcollison deleted the neil/clusteredstate branch January 18, 2024 00:42
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.

None yet

2 participants