[fix][broker] Fix message loss during topic compaction#20980
[fix][broker] Fix message loss during topic compaction#20980Technoboy- merged 4 commits intoapache:masterfrom
Conversation
e7f35b0 to
2d3b2be
Compare
2d3b2be to
982ea19
Compare
| } | ||
| }); | ||
| if (to.equals(id)) { | ||
| if (lastReadId.equals(id)) { |
There was a problem hiding this comment.
It seems to be a 'return' missing in line-287, we may need to open another PR to fix it.
There was a problem hiding this comment.
Yes, if we don't stop phase two, the next entry may be dropped because it does not exist in the latestForKey.
| } | ||
| }); | ||
| if (to.equals(id)) { | ||
| if (lastReadId.equals(id)) { |
There was a problem hiding this comment.
Yes, if we don't stop phase two, the next entry may be dropped because it does not exist in the latestForKey.
b1854cc to
c90dcd4
Compare
c90dcd4 to
696a6e5
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #20980 +/- ##
=============================================
+ Coverage 33.53% 73.12% +39.59%
- Complexity 12174 32252 +20078
=============================================
Files 1621 1875 +254
Lines 126919 139443 +12524
Branches 13851 15333 +1482
=============================================
+ Hits 42561 101967 +59406
+ Misses 78745 29414 -49331
- Partials 5613 8062 +2449
Flags with carried forward coverage won't be shown. Click here to find out more.
|
codelipenghui
left a comment
There was a problem hiding this comment.
LGTM, left a minor comment.
| boolean singleDeletedMessage = false; | ||
| boolean singleReplaceMessage = false; |
There was a problem hiding this comment.
It looks like we don't need add above 2 variables to make the code more easily to read
for (ImmutableTriple<MessageId, String, Integer> e : extractIdsAndKeysAndSizeFromBatch(m)) {
if (e != null) {
if (e.getRight() > 0) {
MessageId old = latestForKey.put(e.getMiddle(), e.getLeft());
if (old != null) {
mxBean.addCompactionRemovedEvent(reader.getTopic());
}
} else {
latestForKey.remove(e.getMiddle());
deleteCnt++;
mxBean.addCompactionRemovedEvent(reader.getTopic());
}
}
}
Technoboy-
left a comment
There was a problem hiding this comment.
LGTM, just fix the above comment
(cherry picked from commit 3ab420c)
(cherry picked from commit 3ab420c)
(cherry picked from commit 3ab420c)
(cherry picked from commit 3ab420c)
(cherry picked from commit 3ab420c)
(cherry picked from commit 3ab420c)
(cherry picked from commit 3ab420c)
(cherry picked from commit 3ab420c)
(cherry picked from commit 3ab420c)
(cherry picked from commit 3ab420c)
Motivation
If a batch contains a message with a null value (i.e. payloadSize == 0) and
PhaseOneResult.fromhaven't been set, then the compactor may skip the whole batch message according toPhaseOneResult.fromin phase two, which will lead to message loss during the topic compact. The root cause isdeletedMessageof whole batch be markedtruewhen the batch contains one message with a null value.Also,
PhaseOneResult.tohas the same problem, when finding the value of the message is null,PhaseOneResult.towill not be updated.pulsar/pulsar-broker/src/main/java/org/apache/pulsar/compaction/TwoPhaseCompactor.java
Lines 126 to 166 in 9862884
Modifications
Fix
deletedMessagecalculate in the batch message, just when delete times are equal to the number of messages in the batch to markdeletedMessage=true.Don't extract message with null key in phase one, since messages with null keys should be retained intact.
Verifying this change
(Please pick either of the following options)
This change is a trivial rework / code cleanup without any test coverage.
(or)
This change is already covered by existing tests, such as (please describe tests).
(or)
This change added tests and can be verified as follows:
(example:)
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: