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

   ### Motivation
   
   The method `consumer.getLastMessageId` will return the latest message which 
can be received.
   - If disabled `read compacted`, will return the last confirmed position of 
`ManagedLedger`.
   - If enabled `read compacted`, will return the latest message id which can 
be read from the compacted topic.
   
   If we send a batch message like this:
   
   ```java
   producer.newMessage().key("k1").value("v0").sendAsync(); // message-id is 
[3:1,-1:0]
   producer.newMessage().key("k1").value("v1").sendAsync(); // message-id is 
[3:1,-1:1]
   producer.newMessage().key("k1").value("v2").sendAsync(); // message-id is 
[3:1,-1:2]
   producer.newMessage().key("k2").value("v0").sendAsync(); // message-id is 
[3:1,-1:3]
   producer.newMessage().key("k2").value("v1").sendAsync(); // message-id is 
[3:1,-1:4]
   producer.newMessage().key("k2").value(null).sendAsync(); // message-id is 
[3:1,-1:5]
   producer.flush();
   ```
   
   After the compaction task is done, the messages with key `k2` will be 
deleted by the compaction task. Then the latest message that can be received 
will be `[3:1:-1:2]`.
   
   --- 
   When we call `consumer.getLastMessageId`, the expected result is:
   
   ```
   [3:1,-1:2]
   ```
   
   --- 
   But the actual result is:
   
   ```
   [3:1,-1:5]
   ```
   
   ### Modifications
   If enabled `read compacted` and the latest entry of the compacted topic is a 
batched message, extract the entry and calculate all internal messages, then 
return the latest message which is not marked `compacted out`.
   
   ### Documentation
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   - [ ] `doc` <!-- Your PR contains doc changes. Please attach the local 
preview screenshots (run `sh start.sh` at `pulsar/site2/website`) to your PR 
description, or else your PR might not get merged. -->
   - [ ] `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: 
   - https://github.com/poorbarcode/pulsar/pull/49
   


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