You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "poorbarcode (via GitHub)" <gi...@apache.org> on 2025/02/07 07:01:02 UTC
[PR] [fix] [client] call redeliver 1 msg but did 2 msgs [pulsar]
poorbarcode opened a new pull request, #23943:
URL: https://github.com/apache/pulsar/pull/23943
### Motivation
Issue: call redeliver `1` message, but it will redeliver `2` messages
### Modifications
fix the bug
### Documentation
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [ ] `doc` <!-- Your PR contains doc changes. -->
- [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
- [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-complete` <!-- Docs have been already added -->
### Matching PR in forked repository
PR in forked repository: x
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [fix] [client] call redeliver 1 msg but did 2 msgs [pulsar]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #23943:
URL: https://github.com/apache/pulsar/pull/23943#issuecomment-2645752824
## [Codecov](https://app.codecov.io/gh/apache/pulsar/pull/23943?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 74.25%. Comparing base [(`bbc6224`)](https://app.codecov.io/gh/apache/pulsar/commit/bbc62245c5ddba1de4b1e7cee4ab49334bc36277?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`bfa194c`)](https://app.codecov.io/gh/apache/pulsar/commit/bfa194c19fe02b5ecc7ffa16106606279ad84eeb?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
> Report is 886 commits behind head on master.
<details><summary>Additional details and impacted files</summary>
[](https://app.codecov.io/gh/apache/pulsar/pull/23943?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## master #23943 +/- ##
============================================
+ Coverage 73.57% 74.25% +0.68%
+ Complexity 32624 2375 -30249
============================================
Files 1877 1853 -24
Lines 139502 143735 +4233
Branches 15299 16334 +1035
============================================
+ Hits 102638 106730 +4092
+ Misses 28908 28596 -312
- Partials 7956 8409 +453
```
| [Flag](https://app.codecov.io/gh/apache/pulsar/pull/23943/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [inttests](https://app.codecov.io/gh/apache/pulsar/pull/23943/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `26.71% <9.09%> (+2.13%)` | :arrow_up: |
| [systests](https://app.codecov.io/gh/apache/pulsar/pull/23943/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `23.21% <9.09%> (-1.12%)` | :arrow_down: |
| [unittests](https://app.codecov.io/gh/apache/pulsar/pull/23943/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `73.76% <100.00%> (+0.91%)` | :arrow_up: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
| [Files with missing lines](https://app.codecov.io/gh/apache/pulsar/pull/23943?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...va/org/apache/pulsar/client/impl/ConsumerImpl.java](https://app.codecov.io/gh/apache/pulsar/pull/23943?src=pr&el=tree&filepath=pulsar-client%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fclient%2Fimpl%2FConsumerImpl.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWNsaWVudC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2NsaWVudC9pbXBsL0NvbnN1bWVySW1wbC5qYXZh) | `79.44% <100.00%> (+1.87%)` | :arrow_up: |
| [...n/util/collections/GrowableArrayBlockingQueue.java](https://app.codecov.io/gh/apache/pulsar/pull/23943?src=pr&el=tree&filepath=pulsar-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpulsar%2Fcommon%2Futil%2Fcollections%2FGrowableArrayBlockingQueue.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cHVsc2FyLWNvbW1vbi9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcHVsc2FyL2NvbW1vbi91dGlsL2NvbGxlY3Rpb25zL0dyb3dhYmxlQXJyYXlCbG9ja2luZ1F1ZXVlLmphdmE=) | `97.00% <100.00%> (+1.56%)` | :arrow_up: |
... and [1036 files with indirect coverage changes](https://app.codecov.io/gh/apache/pulsar/pull/23943/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [fix] [client] call redeliver 1 msg but did 2 msgs [pulsar]
Posted by "dao-jun (via GitHub)" <gi...@apache.org>.
dao-jun commented on code in PR #23943:
URL: https://github.com/apache/pulsar/pull/23943#discussion_r1957692817
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BatchMessageWithBatchIndexLevelTest.java:
##########
@@ -137,6 +138,67 @@ public void testBatchMessageAck() {
});
}
+ @DataProvider
+ public Object[][] enabledBatchSend() {
+ return new Object[][] {
+ {false},
+ {true}
+ };
+ }
+
+ @Test(dataProvider = "enabledBatchSend")
+ @SneakyThrows
+ public void testBatchMessageNAck(boolean enabledBatchSend) {
+ final String topicName = BrokerTestUtil.newUniqueName("persistent://prop/ns-abc/tp");
+ final String subscriptionName = "s1";
+ ConsumerImpl<byte[]> consumer = (ConsumerImpl<byte[]>) pulsarClient.newConsumer().topic(topicName)
+ .subscriptionName(subscriptionName)
+ .receiverQueueSize(21)
+ .subscriptionType(SubscriptionType.Shared)
+ .enableBatchIndexAcknowledgment(true)
+ .negativeAckRedeliveryDelay(100, TimeUnit.MILLISECONDS)
+ .subscribe();
+ Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName)
+ .batchingMaxMessages(20)
+ .batchingMaxPublishDelay(1, TimeUnit.HOURS)
+ .enableBatching(enabledBatchSend)
+ .create();
+ final PersistentTopic topic = (PersistentTopic) pulsar.getBrokerService().getTopicReference(topicName).get();
+ final AbstractPersistentDispatcherMultipleConsumers dispatcher =
+ (AbstractPersistentDispatcherMultipleConsumers) topic.getSubscription(subscriptionName).getDispatcher();
+
+ // Send messages: 20 * 2.
+ for (int i = 0; i < 40; i++) {
+ byte[] message = ("batch-message-" + i).getBytes();
+ if (i == 19 || i == 39) {
+ producer.newMessage().value(message).send();
+ } else {
+ producer.newMessage().value(message).sendAsync();
+ }
+ }
+ Awaitility.await().untilAsserted(() -> {
+ if (enabledBatchSend) {
+ assertEquals(consumer.numMessagesInQueue(), 40);
+ } else {
+ assertEquals(consumer.numMessagesInQueue(), 21);
+ }
+ });
+
+ // Negative ack and verify result/
+ Message<byte[]> receive1 = consumer.receive();
+ consumer.pause();
Review Comment:
`pause` is for stop receiving msgs from broker
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [fix] [client] call redeliver 1 msg but did 2 msgs [pulsar]
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on code in PR #23943:
URL: https://github.com/apache/pulsar/pull/23943#discussion_r1957668359
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BatchMessageWithBatchIndexLevelTest.java:
##########
@@ -137,6 +138,67 @@ public void testBatchMessageAck() {
});
}
+ @DataProvider
+ public Object[][] enabledBatchSend() {
+ return new Object[][] {
+ {false},
+ {true}
+ };
+ }
+
+ @Test(dataProvider = "enabledBatchSend")
+ @SneakyThrows
+ public void testBatchMessageNAck(boolean enabledBatchSend) {
+ final String topicName = BrokerTestUtil.newUniqueName("persistent://prop/ns-abc/tp");
+ final String subscriptionName = "s1";
+ ConsumerImpl<byte[]> consumer = (ConsumerImpl<byte[]>) pulsarClient.newConsumer().topic(topicName)
+ .subscriptionName(subscriptionName)
+ .receiverQueueSize(21)
+ .subscriptionType(SubscriptionType.Shared)
+ .enableBatchIndexAcknowledgment(true)
+ .negativeAckRedeliveryDelay(100, TimeUnit.MILLISECONDS)
+ .subscribe();
+ Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName)
+ .batchingMaxMessages(20)
+ .batchingMaxPublishDelay(1, TimeUnit.HOURS)
+ .enableBatching(enabledBatchSend)
+ .create();
+ final PersistentTopic topic = (PersistentTopic) pulsar.getBrokerService().getTopicReference(topicName).get();
+ final AbstractPersistentDispatcherMultipleConsumers dispatcher =
+ (AbstractPersistentDispatcherMultipleConsumers) topic.getSubscription(subscriptionName).getDispatcher();
+
+ // Send messages: 20 * 2.
+ for (int i = 0; i < 40; i++) {
+ byte[] message = ("batch-message-" + i).getBytes();
+ if (i == 19 || i == 39) {
+ producer.newMessage().value(message).send();
+ } else {
+ producer.newMessage().value(message).sendAsync();
+ }
+ }
+ Awaitility.await().untilAsserted(() -> {
+ if (enabledBatchSend) {
+ assertEquals(consumer.numMessagesInQueue(), 40);
+ } else {
+ assertEquals(consumer.numMessagesInQueue(), 21);
+ }
+ });
+
+ // Negative ack and verify result/
+ Message<byte[]> receive1 = consumer.receive();
+ consumer.pause();
Review Comment:
In the Java client, `pause()` will pause sending new permits, so it's not specific to message listener.
https://github.com/apache/pulsar/blob/1220951ac74fb4742abbbd331d6e751234c47015/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java#L1867-L1880
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [fix] [client] call redeliver 1 msg but did 2 msgs [pulsar]
Posted by "dao-jun (via GitHub)" <gi...@apache.org>.
dao-jun commented on code in PR #23943:
URL: https://github.com/apache/pulsar/pull/23943#discussion_r1946864489
##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java:
##########
@@ -2831,27 +2831,18 @@ private Optional<EncryptionContext> createEncryptionContext(MessageMetadata msgM
private int removeExpiredMessagesFromQueue(Set<MessageId> messageIds) {
int messagesFromQueue = 0;
- Message<T> peek = incomingMessages.peek();
- if (peek != null) {
- MessageId messageId = NegativeAcksTracker.discardBatchAndPartitionIndex(peek.getMessageId());
- if (!messageIds.contains(messageId)) {
- // first message is not expired, then no message is expired in queue.
- return 0;
- }
-
- // try not to remove elements that are added while we remove
- Message<T> message = incomingMessages.poll();
- while (message != null) {
- decreaseIncomingMessageSize(message);
- messagesFromQueue++;
- MessageId id = NegativeAcksTracker.discardBatchAndPartitionIndex(message.getMessageId());
- if (!messageIds.contains(id)) {
- messageIds.add(id);
- break;
- }
- message.release();
- message = incomingMessages.poll();
+ Message<T> message;
+ while (true) {
+ message = incomingMessages.pollIf(msg -> {
+ MessageId idPoled = NegativeAcksTracker.discardBatchAndPartitionIndex(msg.getMessageId());
Review Comment:
idPolled?
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [fix] [client] call redeliver 1 msg but did 2 msgs [pulsar]
Posted by "poorbarcode (via GitHub)" <gi...@apache.org>.
poorbarcode commented on code in PR #23943:
URL: https://github.com/apache/pulsar/pull/23943#discussion_r1947408252
##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java:
##########
@@ -2831,27 +2831,18 @@ private Optional<EncryptionContext> createEncryptionContext(MessageMetadata msgM
private int removeExpiredMessagesFromQueue(Set<MessageId> messageIds) {
int messagesFromQueue = 0;
- Message<T> peek = incomingMessages.peek();
- if (peek != null) {
- MessageId messageId = NegativeAcksTracker.discardBatchAndPartitionIndex(peek.getMessageId());
- if (!messageIds.contains(messageId)) {
- // first message is not expired, then no message is expired in queue.
- return 0;
- }
-
- // try not to remove elements that are added while we remove
- Message<T> message = incomingMessages.poll();
- while (message != null) {
- decreaseIncomingMessageSize(message);
- messagesFromQueue++;
- MessageId id = NegativeAcksTracker.discardBatchAndPartitionIndex(message.getMessageId());
- if (!messageIds.contains(id)) {
- messageIds.add(id);
- break;
- }
- message.release();
- message = incomingMessages.poll();
+ Message<T> message;
+ while (true) {
+ message = incomingMessages.pollIf(msg -> {
+ MessageId idPoled = NegativeAcksTracker.discardBatchAndPartitionIndex(msg.getMessageId());
Review Comment:
Fixed
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [fix] [client] call redeliver 1 msg but did 2 msgs [pulsar]
Posted by "poorbarcode (via GitHub)" <gi...@apache.org>.
poorbarcode commented on code in PR #23943:
URL: https://github.com/apache/pulsar/pull/23943#discussion_r1957715186
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BatchMessageWithBatchIndexLevelTest.java:
##########
@@ -137,6 +138,67 @@ public void testBatchMessageAck() {
});
}
+ @DataProvider
+ public Object[][] enabledBatchSend() {
+ return new Object[][] {
+ {false},
Review Comment:
Yes, it only affects bacthed messages
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [fix] [client] call redeliver 1 msg but did 2 msgs [pulsar]
Posted by "poorbarcode (via GitHub)" <gi...@apache.org>.
poorbarcode merged PR #23943:
URL: https://github.com/apache/pulsar/pull/23943
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [fix] [client] call redeliver 1 msg but did 2 msgs [pulsar]
Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on code in PR #23943:
URL: https://github.com/apache/pulsar/pull/23943#discussion_r1957527296
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BatchMessageWithBatchIndexLevelTest.java:
##########
@@ -137,6 +138,67 @@ public void testBatchMessageAck() {
});
}
+ @DataProvider
+ public Object[][] enabledBatchSend() {
+ return new Object[][] {
+ {false},
+ {true}
+ };
+ }
+
+ @Test(dataProvider = "enabledBatchSend")
+ @SneakyThrows
+ public void testBatchMessageNAck(boolean enabledBatchSend) {
+ final String topicName = BrokerTestUtil.newUniqueName("persistent://prop/ns-abc/tp");
+ final String subscriptionName = "s1";
+ ConsumerImpl<byte[]> consumer = (ConsumerImpl<byte[]>) pulsarClient.newConsumer().topic(topicName)
+ .subscriptionName(subscriptionName)
+ .receiverQueueSize(21)
+ .subscriptionType(SubscriptionType.Shared)
+ .enableBatchIndexAcknowledgment(true)
+ .negativeAckRedeliveryDelay(100, TimeUnit.MILLISECONDS)
+ .subscribe();
+ Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName)
+ .batchingMaxMessages(20)
+ .batchingMaxPublishDelay(1, TimeUnit.HOURS)
+ .enableBatching(enabledBatchSend)
+ .create();
+ final PersistentTopic topic = (PersistentTopic) pulsar.getBrokerService().getTopicReference(topicName).get();
+ final AbstractPersistentDispatcherMultipleConsumers dispatcher =
+ (AbstractPersistentDispatcherMultipleConsumers) topic.getSubscription(subscriptionName).getDispatcher();
+
+ // Send messages: 20 * 2.
+ for (int i = 0; i < 40; i++) {
+ byte[] message = ("batch-message-" + i).getBytes();
+ if (i == 19 || i == 39) {
+ producer.newMessage().value(message).send();
+ } else {
+ producer.newMessage().value(message).sendAsync();
+ }
+ }
+ Awaitility.await().untilAsserted(() -> {
+ if (enabledBatchSend) {
+ assertEquals(consumer.numMessagesInQueue(), 40);
+ } else {
+ assertEquals(consumer.numMessagesInQueue(), 21);
+ }
+ });
+
+ // Negative ack and verify result/
+ Message<byte[]> receive1 = consumer.receive();
+ consumer.pause();
Review Comment:
It's meaningless here. `pause()` should only affect the message listener
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [fix] [client] call redeliver 1 msg but did 2 msgs [pulsar]
Posted by "nodece (via GitHub)" <gi...@apache.org>.
nodece commented on PR #23943:
URL: https://github.com/apache/pulsar/pull/23943#issuecomment-2653052394
@poorbarcode Could you fix the build error on the branch-3.0?
```
import static com.google.common.base.Preconditions.checkState;
```
This import is not used.
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [fix] [client] call redeliver 1 msg but did 2 msgs [pulsar]
Posted by "Technoboy- (via GitHub)" <gi...@apache.org>.
Technoboy- closed pull request #23943: [fix] [client] call redeliver 1 msg but did 2 msgs
URL: https://github.com/apache/pulsar/pull/23943
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [fix] [client] call redeliver 1 msg but did 2 msgs [pulsar]
Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower commented on code in PR #23943:
URL: https://github.com/apache/pulsar/pull/23943#discussion_r1957526705
##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BatchMessageWithBatchIndexLevelTest.java:
##########
@@ -137,6 +138,67 @@ public void testBatchMessageAck() {
});
}
+ @DataProvider
+ public Object[][] enabledBatchSend() {
+ return new Object[][] {
+ {false},
Review Comment:
When it's false, even without this change, `testBatchMessageNAck` could still pass
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [fix] [client] call redeliver 1 msg but did 2 msgs [pulsar]
Posted by "poorbarcode (via GitHub)" <gi...@apache.org>.
poorbarcode commented on PR #23943:
URL: https://github.com/apache/pulsar/pull/23943#issuecomment-2661490239
@nodece
> Could you fix the build error on the branch-3.0?
> ```
> import static com.google.common.base.Preconditions.checkState;
> ```
> This import is not used.
@lhotari has fixed, Thanks
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org