HBASE-16880 Reduce garbage in BufferChain (binlijin)

Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/ce493642
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/ce493642
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/ce493642

Branch: refs/heads/hbase-14439
Commit: ce493642c0e295a08701cdcfe3ddc6755cdd7718
Parents: 2ff2c0b
Author: Ashish Singhi <ashishsin...@apache.org>
Authored: Thu Sep 22 13:59:18 2016 +0530
Committer: Ashish Singhi <ashishsin...@apache.org>
Committed: Thu Sep 22 13:59:18 2016 +0530

----------------------------------------------------------------------
 .../apache/hadoop/hbase/ipc/BufferChain.java    | 17 ++----------
 .../org/apache/hadoop/hbase/ipc/RpcServer.java  | 29 ++++++++++++++------
 2 files changed, 23 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/ce493642/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BufferChain.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BufferChain.java 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BufferChain.java
index 7adc94d..26bc56c 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BufferChain.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/BufferChain.java
@@ -20,8 +20,6 @@ package org.apache.hadoop.hbase.ipc;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.channels.GatheringByteChannel;
-import java.util.ArrayList;
-import java.util.List;
 
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
 
@@ -35,22 +33,11 @@ class BufferChain {
   private int remaining = 0;
   private int bufferOffset = 0;
 
-  BufferChain(ByteBuffer ... buffers) {
-    // Some of the incoming buffers can be null
-    List<ByteBuffer> bbs = new ArrayList<ByteBuffer>(buffers.length);
+  BufferChain(ByteBuffer[] buffers) {
     for (ByteBuffer b : buffers) {
-      if (b == null) continue;
-      bbs.add(b);
       this.remaining += b.remaining();
     }
-    this.buffers = bbs.toArray(new ByteBuffer[bbs.size()]);
-  }
-
-  BufferChain(List<ByteBuffer> buffers) {
-    for (ByteBuffer b : buffers) {
-      this.remaining += b.remaining();
-    }
-    this.buffers = buffers.toArray(new ByteBuffer[buffers.size()]);
+    this.buffers = buffers;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hbase/blob/ce493642/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java
index 12c21d9..0dbaf04 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java
@@ -411,7 +411,9 @@ public class RpcServer implements RpcServerInterface, 
ConfigurationObserver {
     }
 
     protected synchronized void setSaslTokenResponse(ByteBuffer response) {
-      this.response = new BufferChain(response);
+      ByteBuffer[] responseBufs = new ByteBuffer[1];
+      responseBufs[0] = response;
+      this.response = new BufferChain(responseBufs);
     }
 
     protected synchronized void setResponse(Object m, final CellScanner cells,
@@ -458,10 +460,20 @@ public class RpcServer implements RpcServerInterface, 
ConfigurationObserver {
         }
         Message header = headerBuilder.build();
         byte[] b = createHeaderAndMessageBytes(result, header, cellBlockSize);
-        List<ByteBuffer> responseBufs = new ArrayList<ByteBuffer>(
-            (cellBlock == null ? 1 : cellBlock.size()) + 1);
-        responseBufs.add(ByteBuffer.wrap(b));
-        if (cellBlock != null) responseBufs.addAll(cellBlock);
+        ByteBuffer[] responseBufs = null;
+        int cellBlockBufferSize = 0;
+        if (cellBlock != null) {
+          cellBlockBufferSize = cellBlock.size();
+          responseBufs = new ByteBuffer[1 + cellBlockBufferSize];
+        } else {
+          responseBufs = new ByteBuffer[1];
+        }
+        responseBufs[0] = ByteBuffer.wrap(b);
+        if (cellBlock != null) {
+          for (int i = 0; i < cellBlockBufferSize; i++) {
+            responseBufs[i + 1] = cellBlock.get(i);
+          }
+        }
         bc = new BufferChain(responseBufs);
         if (connection.useWrap) {
           bc = wrapWithSasl(bc);
@@ -555,9 +567,10 @@ public class RpcServer implements RpcServerInterface, 
ConfigurationObserver {
             + " as call response.");
       }
 
-      ByteBuffer bbTokenLength = ByteBuffer.wrap(Bytes.toBytes(token.length));
-      ByteBuffer bbTokenBytes = ByteBuffer.wrap(token);
-      return new BufferChain(bbTokenLength, bbTokenBytes);
+      ByteBuffer[] responseBufs = new ByteBuffer[2];
+      responseBufs[0] = ByteBuffer.wrap(Bytes.toBytes(token.length));
+      responseBufs[1] = ByteBuffer.wrap(token);
+      return new BufferChain(responseBufs);
     }
 
     @Override

Reply via email to