AnonHxy commented on code in PR #17936: URL: https://github.com/apache/pulsar/pull/17936#discussion_r996379903
########## 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; + batchAllocatedSize = encryptedCapacity; + if (delta != 0) { + producer.client.getMemoryLimitController().forceReserveMemory(delta); Review Comment: > Why not use the release method? We couldn't make sure that the value of `delta` is less or greater than 0, here we just need update the `MemoryLimitController#currentUsage` by `forceReserveMemory`. > The current test case does not cover the logic here So the modified test case like `MemoryLimitTest ` and `ProducerMemoryLimitTest ` has cover this logic if you agree the point above:) @HQebupt -- 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-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org