From 8e25ea536aab69ed07de862583d4d081e10dd2ed Mon Sep 17 00:00:00 2001 From: tedyu Date: Tue, 13 Sep 2016 09:49:13 -0700 Subject: [PATCH] HBASE-16613 Return the unused ByteBuffer to BoundedByteBufferPool when no cell is retrieved from the CellScanner (ChiaPing Tsai) --- .../main/java/org/apache/hadoop/hbase/ipc/IPCUtil.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/IPCUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/IPCUtil.java index 22c5cc1d075..c238adbd56e 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/IPCUtil.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/IPCUtil.java @@ -122,8 +122,9 @@ public class IPCUtil { if (codec == null) throw new CellScannerButNoCodecException(); int bufferSize = this.cellBlockBuildingInitialBufferSize; ByteBufferOutputStream baos = null; + ByteBuffer bb = null; if (pool != null) { - ByteBuffer bb = pool.getBuffer(); + bb = pool.getBuffer(); bufferSize = bb.capacity(); baos = new ByteBufferOutputStream(bb); } else { @@ -155,7 +156,12 @@ public class IPCUtil { encoder.flush(); // If no cells, don't mess around. Just return null (could be a bunch of existence checking // gets or something -- stuff that does not return a cell). - if (count == 0) return null; + if (count == 0) { + if (pool != null && bb != null) { + pool.putBuffer(bb); + } + return null; + } } catch (BufferOverflowException e) { throw new DoNotRetryIOException(e); } finally {