-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix][broker] Fix NPE in MessageDeduplication. #15820
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
Conversation
|
@Technoboy-:Thanks for your contribution. For this PR, do we need to update docs? |
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.
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() {cc75c95 to
a977d87
Compare
Method |
a977d87 to
78ca9f3
Compare
78ca9f3 to
418ac82
Compare
(cherry picked from commit 01d7bfa)
(cherry picked from commit 01d7bfa)
(cherry picked from commit 01d7bfa)
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)