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/10/16 02:21:11 UTC

[GitHub] [pulsar] AnonHxy commented on a diff in pull request #17936: [fix][client]Take into account the buffer allocated by BatchMessageContainer when limiting the memory used

AnonHxy commented on code in PR #17936:
URL: https://github.com/apache/pulsar/pull/17936#discussion_r996377457


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/BatchMessageContainerImpl.java:
##########
@@ -293,14 +301,27 @@ public OpSendMsg createOpSendMsg() throws IOException {
                 messageMetadata.getHighestSequenceId(), numMessagesInBatch, messageMetadata, encryptedPayload);
 
         OpSendMsg op = OpSendMsg.create(messages, cmd, messageMetadata.getSequenceId(),
-                messageMetadata.getHighestSequenceId(), firstCallback);
+                messageMetadata.getHighestSequenceId(), firstCallback, batchAllocatedSize);
 
         op.setNumMessagesInBatch(numMessagesInBatch);
         op.setBatchSizeByte(currentBatchSizeBytes);
         lowestSequenceId = -1L;
         return op;
     }
 
+    private void reserveBatchAllocatedSizeWhenInit(int batchAllocatedInitSize) {
+        batchAllocatedSize = batchAllocatedInitSize;
+        producer.client.getMemoryLimitController().forceReserveMemory(batchAllocatedSize);
+    }
+
+    private void updateBatchAllocatedSizeWhenLeave(int encryptedCapacity) {
+        int delta = encryptedCapacity - batchAllocatedSize;

Review Comment:
   It doesn't matter if `delta`  less than 0 or not.  We could see from below that if `size` less than 0,  this method workd well.
   
   https://github.com/apache/pulsar/blob/09f5eeb0c946ee890483e087f802e30a2a2b60ab/pulsar-client/src/main/java/org/apache/pulsar/client/impl/MemoryLimitController.java#L48-L51



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