You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/12/26 07:40:00 UTC

[GitHub] [pulsar] poorbarcode commented on a diff in pull request #19031: [fix][client] Fix deserialized BatchMessageIdImpl acknowledgment failure

poorbarcode commented on code in PR #19031:
URL: https://github.com/apache/pulsar/pull/19031#discussion_r1057114168


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java:
##########
@@ -529,6 +534,51 @@ protected CompletableFuture<Messages<T>> internalBatchReceiveAsync() {
         return result;
     }
 
+    private void processMessageIdBeforeAcknowledge(MessageIdImpl messageId, AckType ackType, int numMessages) {
+        if (ackType == AckType.Individual) {
+            stats.incrementNumAcksSent(numMessages);
+            unAckedMessageTracker.remove(messageId);
+            if (possibleSendToDeadLetterTopicMessages != null) {
+                possibleSendToDeadLetterTopicMessages.remove(messageId);
+            }
+        } else {
+            stats.incrementNumAcksSent(unAckedMessageTracker.removeMessagesTill(messageId));
+        }
+    }
+
+    private @Nullable MessageIdImpl getMessageIdToAcknowledge(BatchMessageIdImpl messageId, AckType ackType) {
+        final BatchMessageAcker acker;
+        if (messageId.getAcker() instanceof BatchMessageAckerDisabled) {
+            acker = batchMessageToAcker.computeIfAbsent(
+                    Pair.of(messageId.getLedgerId(), messageId.getEntryId()),
+                    __ -> BatchMessageAcker.newAcker(messageId.getBatchSize()));

Review Comment:
   Possible memory leak here. E.g:
   
   ```java
   // deserialized message id {batchSize = 2, batchIndex = 1}
   // and { batchIndex = 0 } already has been acked before.
   MessageId msgId = MessageId.fromByteArray(msgId.toByteArray());
   consumer.acknowledge(msgId);
   // then the acker in the map will no longer be released.
   ```



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