[fix][broker] Fix NPE in MessageDeduplication. - #15820
Merged
Merged
Conversation
Technoboy-
marked this pull request as ready for review
May 28, 2022 02:37
|
@Technoboy-:Thanks for your contribution. For this PR, do we need to update docs? |
codelipenghui
approved these changes
May 28, 2022
codelipenghui
requested review from
315157973,
BewareMyPower,
RobertIndie,
aloyszhang,
eolivelli,
gaoran10,
gaozhangmin,
hangc0276,
hezhangjian,
mattisonchao,
merlimat and
zymap
May 28, 2022 05:07
coderzc
approved these changes
May 28, 2022
Demogorgon314
approved these changes
May 28, 2022
Contributor
There was a problem hiding this comment.
I'm not sure if it could solve the NPE. Is there a race condition like the following code snippet I commented?
if (hasInactive && isEnabled()) { // 1. isEnabled() returns true, managedCursor is not null
// during 1 and 2, some other methods changed `managedCursor` to null
takeSnapshot(getManagedCursor().getMarkDeletedPosition()); // 2. managedCursor might be nullI'd prefer the following way.
final ManagedCursor cursor = managedCursor;
if (hasInactive && cursor != null) {
takeSnapshot(cursor.getMarkDeletedPosition(), cursor);
} private void takeSnapshot(Position position) {
takeSnapshot(position, getManagedCursor());
}
private void takeSnapshot(Position position, ManagedCursor cursor) {
/* ... */
cursor.asyncMarkDelete(position, snapshot, new MarkDeleteCallback() {
Technoboy-
force-pushed
the
fix-msg-dup-npe
branch
from
May 30, 2022 01:19
cc75c95 to
a977d87
Compare
Contributor
Author
Method |
Technoboy-
force-pushed
the
fix-msg-dup-npe
branch
from
May 30, 2022 01:22
a977d87 to
78ca9f3
Compare
BewareMyPower
approved these changes
May 30, 2022
hangc0276
approved these changes
May 30, 2022
HQebupt
approved these changes
May 30, 2022
Technoboy-
force-pushed
the
fix-msg-dup-npe
branch
from
June 1, 2022 01:36
78ca9f3 to
418ac82
Compare
hangc0276
pushed a commit
that referenced
this pull request
Jun 7, 2022
(cherry picked from commit 01d7bfa)
codelipenghui
pushed a commit
to codelipenghui/incubator-pulsar
that referenced
this pull request
Jun 7, 2022
(cherry picked from commit 01d7bfa)
codelipenghui
pushed a commit
that referenced
this pull request
Jun 10, 2022
(cherry picked from commit 01d7bfa)
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
When MessageDeduplication#purgeInactiveProducers:
pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/MessageDeduplication.java
Lines 455 to 477 in d09c6eb
If MessageDeduplication status is not
Enabled, the cursor will be null. and cause to be NPE at line 475.See cursor initializes:
pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/MessageDeduplication.java
Lines 272 to 292 in a439811
StackTrace
Documentation
doc-not-needed(Please explain why)