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/15 14:34:51 UTC

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

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


##########
pulsar-client/src/main/java/org/apache/pulsar/client/impl/AbstractBatchMessageContainer.java:
##########
@@ -42,6 +42,7 @@ public abstract class AbstractBatchMessageContainer implements BatchMessageConta
     protected int maxBytesInBatch;
     protected int numMessagesInBatch = 0;
     protected long currentBatchSizeBytes = 0;
+    protected int batchAllocatedSize = 0;

Review Comment:
   Mirror comment: `batchAllocatedSizeBytes ` is better, like `currentBatchSizeBytes`



##########
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:
   This delta variable may be less than 0. 



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