aloyszhang opened a new pull request, #20750:
URL: https://github.com/apache/pulsar/pull/20750
### Motivation
When calling the `negativeAcknowledge` method, the message is supposed to be
re-delivered only one time.
But, actually, it may be re-delivered twice.
There are two problems:
1. For `MultiTopicsConsumerImpl`, when calling `negativeAcknowledge`, we
didn't remove the message from `UnAckedMessageTracker`, so this message will be
re-delivery by both `UnAckedMessageTracker` and `NegativeAcksTracker`
2. For `ConsumerImpl`, when calling `negativeAcknowledge`, if the message id
is a BatchMessageIdImpl, the messageId will be not removed from the
`UnAckedMessageTracker`, there is because the removing MessageId
type(BatchMessageIdImpl) is not the MessageId type of add(MessageIdImpl).
See:
- add to `UnAckedMessageTracker`
```java
protected void trackMessage(MessageId messageId, int redeliveryCount) {
if (conf.getAckTimeoutMillis() > 0 && messageId instanceof
MessageIdImpl) {
MessageId id = MessageIdAdvUtils.discardBatch(messageId);
```
- remove from `UnAckedMessageTracker`
```java
public void negativeAcknowledge(Message<?> message) {
negativeAcksTracker.add(message);
// Ensure the message is not redelivered for ack-timeout, since we
did receive an "ack"
unAckedMessageTracker.remove(message.getMessageId());
}
```
### Modifications
1. For `MultiTopicsConsumerImpl`, remove the message id from
`UnAckedMessageTracker` when calling `negativeAcknowledge`
2. Keep consistent type for message id adding to and removing from the
`UnAckedMessageTracker`
3. add `UnAckedMessageTracker` size check for `NegativeAcksTest`
4. add log for `NegativeAcksTracker`
### Verifying this change
- [ ] Make sure that the change passes the CI checks.
### Documentation
- [ ] `doc-not-needed` <!-- Your PR changes do not impact docs -->
### Matching PR in forked repository
PR in forked repository: <!-- ENTER URL HERE -->
<!--
After opening this PR, the build in apache/pulsar will fail and instructions
will
be provided for opening a PR in the PR author's forked repository.
apache/pulsar pull requests should be first tested in your own fork since
the
apache/pulsar CI based on GitHub Actions has constrained resources and quota.
GitHub Actions provides separate quota for pull requests that are executed
in
a forked repository.
The tests will be run in the forked repository until all PR review comments
have
been handled, the tests pass and the PR is approved by a reviewer.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]