thetumbled opened a new pull request, #23600:
URL: https://github.com/apache/pulsar/pull/23600

   ### Motivation
   
   Currently, 
`org.apache.pulsar.client.impl.NegativeAcksTracker#nackedMessages` map 
`(ledgerId, entryId)` to `timestamp`, which means multiple nacks from messages 
in the same batch share single one timestamp. If we let msg1 redelivered 10s 
later, then let msg2 redelivered later, these two messages are delivered 20s 
later together. msg1 will not be redelivered 10s later as the timestamp 
recorded in `NegativeAcksTracker#nackedMessages` is overrided by the second 
nack call.
   
   we can reproduce this problem with test code below:
   ```
   Consumer consumer = client.newConsumer()
                   .topic("persistent://public/default/testNack")
                   .subscriptionName("sub2")
                   .subscriptionType(SubscriptionType.Shared)
                   .negativeAckRedeliveryDelay(20, TimeUnit.SECONDS) // fixed 
delay with 20s.
                   .subscribe();
           // receive first message and nack it.
           Message msg = consumer.receive();
           MessageIdAdv batchMessageId = (MessageIdAdv) msg.getMessageId();
           int batchIndex = batchMessageId.getBatchIndex();
           log.info("Message received, timestamp:{}, message id:{}, batch 
index:{}", getTime(), batchMessageId, batchIndex);
           consumer.negativeAcknowledge(msg);
           
           // receive the secode message and sleep for 10s, then nack it.
           msg = consumer.receive();
           batchMessageId = (MessageIdAdv) msg.getMessageId();
           batchIndex = batchMessageId.getBatchIndex();
           log.info("Message received, timestamp:{}, message id:{}, batch 
index:{}", getTime(), batchMessageId, batchIndex);
           Thread.sleep(10000);
           consumer.negativeAcknowledge(msg);
   ```
   We expect the second message redelivered 10s later than the first message, 
as it call nack 10s later than the first one.
   However, we will receive two messages together.
   
![image](https://github.com/user-attachments/assets/6a61c34c-aa4c-4055-9746-9f3a12acce5c)
   
   You can also reproduce this problem with the test code in this PR: 
org.apache.pulsar.client.impl.NegativeAcksTest#testNegativeAcksWithBatch
   
   ### Modifications
   Change `org.apache.pulsar.client.impl.NegativeAcksTracker#nackedMessages` 
map `(ledgerId, entryId, batchIndex)` to `timestamp`.
   
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads 
(10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Does this pull request potentially affect one of the following parts:
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   *If the box was checked, please highlight the changes*
   
   - [ ] Dependencies (add or upgrade a dependency)
   - [ ] The public API
   - [ ] The schema
   - [ ] The default values of configurations
   - [ ] The threading model
   - [ ] The binary protocol
   - [ ] The REST endpoints
   - [ ] The admin CLI options
   - [ ] The metrics
   - [ ] Anything that affects deployment
   
   ### 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 -->
   - [ ] `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: 


-- 
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]

Reply via email to