[fix][broker] Fix NonDurable Subscription msgBackLog incorrect after … #23305
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.
Fixes #23239
Motivation
Briefly describe the issue:
Consumer consumed all messages and then the msgBacklog is 0, but after topic unload, the msgBacklog turned to be 1 instead of 0 which is not what we expected. The detail is in test NonDurableSubscriptionTest#testNonDurableSubscriptionBackLogAfterTopicUnload.
Root cause:
I analysed the related code, and found this issue was introduced by #4331. In the #4331,
if (((BatchMessageIdImpl) msgId).getBatchIndex() >= 0) {
was deleted directly, which cause none batch message will also execute the stepentryId = msgId.getEntryId() - 1;
. Because of this, the entryId reduced by 1, then the msgBacklog turned to be 1 instead of 0.In the #4331, we added
ReaderBuilder#startMessageIdInclusive
interface to allow create Reader which read containes startMessageId, but it has not been implemented correctly. We should add the field resetIncludeHead in CommandSubscribe to implement it.Modifications
(msgId.getBatchIndex() >= 0 || resetIncludeHead)
, entryId -1 will execute Only when msg is batch or the resetIncludeHead is true.Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: