diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/DirectWriter.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/DirectWriter.java index e9ef166c5b8..17466d1e404 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/DirectWriter.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/directentrylogger/DirectWriter.java @@ -113,12 +113,13 @@ public void writeAt(long offset, ByteBuf buf) throws IOException { checkArgument(Buffer.isAligned(buf.readableBytes()), "Buffer must write multiple of alignment bytes (%d), %d is not", Buffer.ALIGNMENT, buf.readableBytes()); - Buffer tmpBuffer = bufferPool.acquire(); + int bytesToWrite = buf.readableBytes(); if (bytesToWrite <= 0) { return; } + Buffer tmpBuffer = bufferPool.acquire(); tmpBuffer.reset(); tmpBuffer.writeByteBuf(buf); Future f = writeExecutor.submit(() -> {