GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — [fix][broker] fix delayedMessagesCount error in InMemoryDelayedDeliveryTracker by TakaHiR07 · Pull Request #25076 · apache/pulsar Conversation
Contributor
MotivationOccur a NPE issue in delay message. And then find the reason is in delayedMessagesCount. When InMemoryDelayedDeliveryTracker#addMessage(), it don't judge whether the entryId is exist in roaringbitmap, that result in the delayedMessagesCount of the map size is not correct.
Modifications
Verifying this change
Documentation
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
lhotari
reviewed
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like
Suggested change
The It's unfortunate that
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
|
btw. this code location was discussed in the review: https://github.com/apache/pulsar/pull/24430/changes#r2156278377 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Left some comments.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| updateTimer(); | ||
|
|
||
| checkAndUpdateHighest(deliverAt); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
One thought: should updateTimer() and checkAndUpdateHighest(deliverAt) run only when we actually insert a new entryId?
With the current structure, duplicate addMessage() calls still update highestDeliveryTimeTracked / messagesHaveFixedDelay, which could disable the fixed-delay optimization even though the tracker state didn’t change.”
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Great catch. I have checked the earliest fixed delay implementation in #16609. In the earliest implementation, the issue is already exist. When duplicate addMessage(), highestDeliveryTimeTracked is ok, but messagesHaveFixedDelay would be set to false incorrectly.
I would check why exist duplicate addMessage() later. And I prefer that we open another pr to fix the additional issue.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| log.error("[{}] Delayed message tracker getScheduledMessages should not < 0, number is: {}", | ||
| dispatcher.getName(), n); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
About the new n < 0 branch: this should be unreachable in normal flow. One potential way to hit it is int overflow from int cardinality = (int) entryIds.getLongCardinality().
Would it be better to keep cardinality as long (and compare cardinality <= (long) n) to eliminate overflow, instead of only logging when n < 0?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You are right. I think it is another issue and both use long value is better. Do you think we fix it in this pr or you push another pr to fix?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
|
|
||
|
|
||
| // case2: addMessage() with duplicate entryId, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
In case2 the comment says it enters cardinality > n, but with getScheduledMessages(10) and 4 unique entryIds it should hit the cardinality <= n branch. Could we adjust the comment to match the scenario (case3 seems to be the one exercising cardinality > n)?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes. have changed the comment
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@thetumbled Do you have a chance to review the current PR? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Maybe we should figure out the reason why duplicate entry IDs are added multiple times if this class does not intentionally allow that behavior. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This pull request fixes a bug in the InMemoryDelayedDeliveryTracker where duplicate message entries could cause incorrect delayed message counts, potentially leading to NPE issues. The fix adds a duplicate check before incrementing the counter and improves error handling for edge cases.
Key changes:
addMessage() using Roaring64Bitmap.contains() before adding entriesgetScheduledMessages() to explicitly handle and log the n < 0 caseCopilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/InMemoryDelayedDeliveryTracker.java | Implements duplicate entry check in addMessage() and enhances error handling in getScheduledMessages() |
| pulsar-broker/src/test/java/org/apache/pulsar/broker/delayed/InMemoryDeliveryTrackerTest.java | Adds comprehensive test method testDelayedMessagesCountWithDuplicateEntryId() covering three scenarios: multiple timestamps with duplicates, single timestamp with duplicates, and partial retrieval with duplicates |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
d12846f to
9b562dc
Compare
|
#25681 addresses the same issue |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@thetumbled One reason finally came up to the surface with PR #26012 (reported issue is #25996) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
closing this one since #25681 is merged and addressed the same problem. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.