BewareMyPower opened a new pull request #13883:
URL: https://github.com/apache/pulsar/pull/13883


   ### Motivation
   
   In C++ client, there is a corner case that when a reader's start message ID 
is the last message of a topic, `hasMessageAvailable` returns true. However, it 
should return false because the start message ID is exclusive and in this case 
`readNext` would never return a message unless new messages arrived.
   
   ### Modifications
   
   The current C++ implementation of `hasMessageAvailable` is from long days 
ago and has many problems. So this PR migrates the Java implementation of 
`hasMessageAvailable` to C++ client.
   
   Since after the modifications we need to access `startMessageId` in 
`hasMessageAvailable`, which is called in a different thread from 
`connectionOpened` that might modify `startMessageId`. We use a common mutex 
`mutexForMessageIds` to protect the access to `lastDequedMessageId_` and 
`lastMessageIdInBroker_`.
   
   To fix the original tests when `startMessageId` is latest, this PR adds a 
`GetLastMessageIdResponse` as the response of `GetLastMessageId` request. The  
`GetLastMessageIdResponse` contains the `consumer_mark_delete_position` 
introduced from https://github.com/apache/pulsar/pull/9652 to compare with 
`last_message_id` when `startMessageId` is latest.
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   This change added tests `ReaderTest#testHasMessageAvailableWhenCreated` and 
`MessageIdTest# testCompareLedgerAndEntryId`.


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