@Override
    public ByteBuffer tryAllocate(int sizeBytes) {
        if (sizeBytes > batchSize) {
            throw new IllegalArgumentException("Cannot allocate buffers larger than max " +
                "batch size of " + batchSize);
        }

        lock.lock();
        try {
            ByteBuffer buffer = free.poll();
            // Always allocation a new buffer if there are no free buffers
            if (buffer == null) {
                buffer = ByteBuffer.allocate(batchSize);
                numAllocatedBatches += 1;
            }

            return buffer;
        } finally {
            lock.unlock();
        }
    }
Allocate a byte buffer with {@code batchSize} in this pool.

This method should always succeed and never return null. The sizeBytes parameter must be less than
the batchSize used in the constructor.

@param sizeBytes is used to determine if the requested size is exceeding the batchSize
@throws IllegalArgumentException if sizeBytes is greater than batchSize
raft/src/main/java/org/apache/kafka/raft/internals/BatchMemoryPool.java