ezhou413 commented on code in PR #23483:
URL: https://github.com/apache/kafka/pull/23483#discussion_r4161189043
##########
clients/src/main/java/org/apache/kafka/clients/producer/internals/BufferPool.java:
##########
@@ -296,17 +296,16 @@ public List<ByteBuffer> allocateChunks(int totalSize,
long maxTimeToBlockMs) thr
throw new KafkaException("Producer closed while allocating
memory");
}
try {
- long freeListBytes = (long) free.size() * chunkSize;
- if (this.nonPooledAvailableMemory + freeListBytes >=
memoryRequired) {
- // Enough memory available to allocate the chunks needed
- while (pooled.size() < numChunks && !free.isEmpty())
- pooled.add(free.pollFirst());
- long remainingBytes = memoryRequired - (long) pooled.size() *
chunkSize;
- if (remainingBytes > 0) {
- // remainingBytes > 0 means the free list was fully
drained into `pooled`, so the
- // remainder comes entirely from non-pooled memory
(sufficient per the check above).
- this.nonPooledAvailableMemory -= remainingBytes;
- }
+ if (reserveChunksIfAvailable(pooled, numChunks, chunkSize,
memoryRequired)) {
+ // Enough memory was available; the chunks are reserved.
+ } else if (maxTimeToBlockMs <= 0) {
Review Comment:
Removed
--
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]