BewareMyPower opened a new pull request, #17833: URL: https://github.com/apache/pulsar/pull/17833
### Motivation When I read the acknowledge related code, I found much repeat code and the inconsistent code style. Generally we should handle the following cases for a given message ID: 1. The message ID doesn't contain a valid batch index, i.e. `messageId instanceof BatchMessageIdImpl` returns false. 2. Otherwise, it's a `BatchMessageIdImpl`. The behavior is determined by whether the batch index ACK is enabled. For individual ACKs, the stats and unacked message tracker must be updated according to the type of message ID. Since `MessageIdImpl` is used as the key, for a `BatchMessageIdImpl`, we must create a `MessageIdImpl` from it as the key of these hash maps. The existing methods `modifyBatchMessageIdAndStatesInConsumer` and `modifyMessageIdStatesInConsumer` are confused. So I decide to make the code simple and clear. ### Modifications - Add a `getMessageIdImpl` method to `BatchMessageIdImpl` to create a `MessageIdImpl` object from it. - Add an `addAcknowledgement` overload to accept an extra `BatchMessageIdImpl` argument, which is used to compute the number of ACK commands sent and perform batch related ACKs. The `MessageIdImpl` argument is used to update the DLQ and unacked tracker. - Add a `addIndividualAcknowledgement` method for individual ACKs. This method accept two functions to handle ACK for batch and non-batch message IDs because when a list of message IDs are acknowledeged, `doIndividualAckAsync` and `doIndividualBatchAck` will be called instead of `doIndividualAck` and `doIndividualBatchAck`. ### Documentation - [ ] `doc-required` (Your PR needs to update docs and you will update later) - [x] `doc-not-needed` (Please explain why) - [ ] `doc` (Your PR contains doc changes) - [ ] `doc-complete` (Docs have been already added) ### Matching PR in forked repository PR in forked repository: https://github.com/BewareMyPower/pulsar/pull/4 -- 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]
