-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[FIXED] (2.11) Replicated consumer skipped redeliveries #6566
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c704b35
[FIXED] Replicated consumer skipped redeliveries
MauriceVanVeen 5342ba9
De-flake TestJetStreamSuperClusterConsumerDeliverNewBug
MauriceVanVeen d3e9e79
Fix consumer DeliverLast policy
MauriceVanVeen 0971e09
Correct TestJetStreamClusterConsumerDeliveredSyncReporting
MauriceVanVeen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1373,8 +1373,14 @@ func (o *consumer) setLeader(isLeader bool) { | |
o.rdq = nil | ||
o.rdqi.Empty() | ||
|
||
// Restore our saved state. During non-leader status we just update our underlying store. | ||
o.readStoredState(lseq) | ||
// Restore our saved state. | ||
// During non-leader status we just update our underlying store when not clustered. | ||
// If clustered we need to propose our initial (possibly skipped ahead) o.sseq to the group. | ||
if o.node == nil || o.dseq > 1 || (o.store != nil && o.store.HasState()) { | ||
o.readStoredState(lseq) | ||
} else if o.node != nil && o.sseq >= 1 { | ||
o.updateSkipped(o.sseq) | ||
} | ||
|
||
// Setup initial num pending. | ||
o.streamNumPending() | ||
|
@@ -1384,11 +1390,6 @@ func (o *consumer) setLeader(isLeader bool) { | |
o.lss = nil | ||
} | ||
|
||
// Update the group on the our starting sequence if we are starting but we skipped some in the stream. | ||
if o.dseq == 1 && o.sseq > 1 { | ||
o.updateSkipped(o.sseq) | ||
} | ||
|
||
// Do info sub. | ||
if o.infoSub == nil && jsa != nil { | ||
isubj := fmt.Sprintf(clusterConsumerInfoT, jsa.acc(), stream, o.name) | ||
|
@@ -2811,10 +2812,7 @@ func (o *consumer) applyState(state *ConsumerState) { | |
return | ||
} | ||
|
||
// If o.sseq is greater don't update. Don't go backwards on o.sseq if leader. | ||
if !o.isLeader() || o.sseq <= state.Delivered.Stream { | ||
o.sseq = state.Delivered.Stream + 1 | ||
} | ||
o.sseq = state.Delivered.Stream + 1 | ||
o.dseq = state.Delivered.Consumer + 1 | ||
o.adflr = state.AckFloor.Consumer | ||
o.asflr = state.AckFloor.Stream | ||
|
@@ -2972,9 +2970,13 @@ func (o *consumer) infoWithSnapAndReply(snap bool, reply string) *ConsumerInfo { | |
} | ||
// If we are the leader we could have o.sseq that is skipped ahead. | ||
// To maintain consistency in reporting (e.g. jsz) we always take the state for our delivered/ackfloor stream sequence. | ||
info.Delivered.Consumer, info.Delivered.Stream = state.Delivered.Consumer, state.Delivered.Stream | ||
// Only use skipped ahead o.sseq if we're a new consumer and have not yet replicated this state yet. | ||
leader := o.isLeader() | ||
if !leader || o.store.HasState() { | ||
info.Delivered.Consumer, info.Delivered.Stream = state.Delivered.Consumer, state.Delivered.Stream | ||
} | ||
info.AckFloor.Consumer, info.AckFloor.Stream = state.AckFloor.Consumer, state.AckFloor.Stream | ||
if !o.isLeader() { | ||
if !leader { | ||
info.NumAckPending = len(state.Pending) | ||
info.NumRedelivered = len(state.Redelivered) | ||
} | ||
|
@@ -4821,16 +4823,16 @@ func (o *consumer) deliverMsg(dsubj, ackReply string, pmsg *jsPubMsg, dc uint64, | |
// Update delivered first. | ||
o.updateDelivered(dseq, seq, dc, ts) | ||
|
||
// Send message. | ||
o.outq.send(pmsg) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could send a message to the client before |
||
|
||
if ap == AckExplicit || ap == AckAll { | ||
o.trackPending(seq, dseq) | ||
} else if ap == AckNone { | ||
o.adflr = dseq | ||
o.asflr = seq | ||
} | ||
|
||
// Send message. | ||
o.outq.send(pmsg) | ||
|
||
// Flow control. | ||
if o.maxpb > 0 && o.needFlowControl(psz) { | ||
o.sendFlowControl() | ||
|
@@ -5291,13 +5293,13 @@ func (o *consumer) selectStartingSeqNo() { | |
} else if o.cfg.DeliverPolicy == DeliverLast { | ||
if o.subjf == nil { | ||
o.sseq = state.LastSeq | ||
return | ||
} | ||
// If we are partitioned here this will be properly set when we become leader. | ||
for _, filter := range o.subjf { | ||
ss := o.mset.store.FilteredState(1, filter.subject) | ||
if ss.Last > o.sseq { | ||
o.sseq = ss.Last | ||
} else { | ||
// If we are partitioned here this will be properly set when we become leader. | ||
for _, filter := range o.subjf { | ||
ss := o.mset.store.FilteredState(1, filter.subject) | ||
if ss.Last > o.sseq { | ||
o.sseq = ss.Last | ||
} | ||
} | ||
} | ||
} else if o.cfg.DeliverPolicy == DeliverLastPerSubject { | ||
|
@@ -5397,7 +5399,8 @@ func (o *consumer) selectStartingSeqNo() { | |
// Set ack store floor to store-1 | ||
o.asflr = o.sseq - 1 | ||
// Set our starting sequence state. | ||
if o.store != nil && o.sseq > 0 { | ||
// But only if we're not clustered, if clustered we propose upon becoming leader. | ||
if o.store != nil && o.sseq > 0 && o.cfg.replicas(&o.mset.cfg) == 1 { | ||
o.store.SetStarting(o.sseq - 1) | ||
} | ||
} | ||
|
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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.
This is replaced by the change above ^.