[Branch-2.7][Cherry-pick] Return message ID from compacted ledger while the compaction cursor reach the end of the topic. #16395
+10
−1
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.
Cherry-pick #13533
Motivation
The problem happens when the compaction cursor reaches the end of the topic but the tail messages
of the topic have been removed by producer writes null value messages during the topic compaction.
For example:
After the compaction task complete,
At this moment, if the reader tries to get the last message ID of the topic,
we should return
1:2
not1:4
, because the reader is not able to read the messagewith keys
3
and4
from the compacted topic, otherwise, thereader.readNext()
methodwill be blocked until a new message written to the topic.
Modifications
The fix is straightforward, when the broker receives a get last message ID request,
the broker will check if the compaction cursor reaches the end of the original topic.
If yes, respond last message ID from the compacted ledger.
Verifying this change
New test added
testHasMessageAvailableWithNullValueMessage
which ensure thehasMessageAvailable()
return false no more messages from the compacted topic if the compaction cursor reaches the end of the topic.
Does this pull request potentially affect one of the following parts:
If
yes
was chosen, please highlight the changesDocumentation
Check the box below and label this PR (if you have committer privilege).
Need to update docs?
doc-required
(If you need help on updating docs, create a doc issue)
no-need-doc
(Please explain why)
doc
(If this PR contains doc changes)