-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[fix][broker] Multiple consumer dispatcher stuck when unackedMessages
greater than maxUnackedMessages
#17483
[fix][broker] Multiple consumer dispatcher stuck when unackedMessages
greater than maxUnackedMessages
#17483
Conversation
unackedMessages
greater than maxUnackedMessages
unackedMessages
greater than maxUnackedMessages
which Pulsar version is this stack trace from? Would it be possible to add a test that reproduces the problem using the public APIs? If this happens when there are more unknowledged messages than the defined limit, I'd assume that it's fairly easy to reproduce? |
@mattisonchao I think the issue is introduced by #16718? it should be a blocker for 2.11.0 release. |
@lhotari Test added, Please take a look. |
than `getMaxUnackedMessages`
pulsar-broker/src/test/java/org/apache/pulsar/client/impl/KeySharedSubscriptionTest.java
Outdated
Show resolved
Hide resolved
pulsar-broker/src/test/java/org/apache/pulsar/client/impl/KeySharedSubscriptionTest.java
Show resolved
Hide resolved
pulsar-broker/src/test/java/org/apache/pulsar/client/impl/KeySharedSubscriptionTest.java
Outdated
Show resolved
Hide resolved
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.
The solution makes sense to me, but I'm wondering if there is another bug that we need to fix too? Thanks!
@@ -634,7 +634,9 @@ protected synchronized boolean trySendMessagesToConsumers(ReadType readType, Lis | |||
// round-robin dispatch batch size for this consumer | |||
int availablePermits = c.isWritable() ? c.getAvailablePermits() : 1; | |||
if (c.getMaxUnackedMessages() > 0) { | |||
availablePermits = Math.min(availablePermits, c.getMaxUnackedMessages() - c.getUnackedMessages()); | |||
// Avoid negative number | |||
int remainUnAckedMessages = Math.max(c.getMaxUnackedMessages() - c.getUnackedMessages(), 0); |
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.
Do we understand why c.getUnackedMessages()
is greater than c.getMaxUnackedMessages()
? I read through the test, but I didn't see what is causing the negative availablePermits
.
Based on the names, that seems like there is another bug if c.getMaxUnackedMessages() - c.getUnackedMessages()
is negative. Perhaps the idea that the maxUnackedMessages
is just a soft limit that we shouldn't exceed by too much?
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.
Do we understand why c.getUnackedMessages() is greater than c.getMaxUnackedMessages()?
Because in the current implementation, we will add unackedMessages
after sent messages. if we use batch messages, the unackedMessages
is probably greater than MaxUnackedMessages
.
Plus, #16670 #16718 want to add this check to limit the consumer.
Based on the names, that seems like there is another bug if c.getMaxUnackedMessages() - c.getUnackedMessages() is negative.
Sure, But I find we have two sections using it. And I fix It all in this PR.
Perhaps the idea that the maxUnackedMessages is just a soft limit that we shouldn't exceed by too much?
Yes, maybe we have another method to help more robust support it, but it looks like it is another improvement.
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.
Because in the current implementation, we will add
unackedMessages
after sent messages. if we use batch messages, theunackedMessages
is probably greater thanMaxUnackedMessages
.
This was the detail I was missing, thank you for explaining. I read through the code a bit more, and it makes sense.
unackedMessages
greater than maxUnackedMessages
unackedMessages
greater than maxUnackedMessages
This reverts commit 7673ec2.
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.
If not carry this fix in master, the test for share sub mode can passed
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.
LGTM
…s` greater than `maxUnackedMessages` (apache#17483)
…s` greater than `maxUnackedMessages` (apache#17483) (cherry picked from commit d7943a5) (cherry picked from commit 011e121)
…s` greater than `maxUnackedMessages` (apache#17483)
…release' (merge request !67) branch-2.9-fix-somebug-key-share [fix][broker] Multiple consumer dispatcher stuck when unackedMessages greater than maxUnackedMessages (apache#17483) [fix][broker] Fix consumer does not abide by the max unacks limitation for Key_Shared subscription apache#16718 [fix][broker] Fix consumer does not abide by the max unacks limitation for Shared subscription apache#16670
Motivation
See error stack trace:
Relative code:
pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentStickyKeyDispatcherMultipleConsumers.java
Lines 237 to 262 in cfe95dd
When
unackedMessages
is greater thanmaxUnackedMessages
, becausemessagesForC
is a negative number,ArrayIndexOutOfBoundsException
will be thrown on line 254. Then the exception will cause the message not to be delivered.Modifications
Verifying this change
Documentation
doc-not-needed
(Please explain why)