Revert "HBASE-16880 Reduce garbage in BufferChain (binlijin)" to fix JIRA number
This reverts commit ce493642c0
.
This commit is contained in:
parent
07ed15598b
commit
96c5a02217
|
@ -20,6 +20,8 @@ package org.apache.hadoop.hbase.ipc;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.GatheringByteChannel;
|
import java.nio.channels.GatheringByteChannel;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.classification.InterfaceAudience;
|
import org.apache.hadoop.hbase.classification.InterfaceAudience;
|
||||||
|
|
||||||
|
@ -33,11 +35,22 @@ class BufferChain {
|
||||||
private int remaining = 0;
|
private int remaining = 0;
|
||||||
private int bufferOffset = 0;
|
private int bufferOffset = 0;
|
||||||
|
|
||||||
BufferChain(ByteBuffer[] buffers) {
|
BufferChain(ByteBuffer ... buffers) {
|
||||||
|
// Some of the incoming buffers can be null
|
||||||
|
List<ByteBuffer> bbs = new ArrayList<ByteBuffer>(buffers.length);
|
||||||
|
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) {
|
for (ByteBuffer b : buffers) {
|
||||||
this.remaining += b.remaining();
|
this.remaining += b.remaining();
|
||||||
}
|
}
|
||||||
this.buffers = buffers;
|
this.buffers = buffers.toArray(new ByteBuffer[buffers.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -411,9 +411,7 @@ public class RpcServer implements RpcServerInterface, ConfigurationObserver {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected synchronized void setSaslTokenResponse(ByteBuffer response) {
|
protected synchronized void setSaslTokenResponse(ByteBuffer response) {
|
||||||
ByteBuffer[] responseBufs = new ByteBuffer[1];
|
this.response = new BufferChain(response);
|
||||||
responseBufs[0] = response;
|
|
||||||
this.response = new BufferChain(responseBufs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected synchronized void setResponse(Object m, final CellScanner cells,
|
protected synchronized void setResponse(Object m, final CellScanner cells,
|
||||||
|
@ -460,20 +458,10 @@ public class RpcServer implements RpcServerInterface, ConfigurationObserver {
|
||||||
}
|
}
|
||||||
Message header = headerBuilder.build();
|
Message header = headerBuilder.build();
|
||||||
byte[] b = createHeaderAndMessageBytes(result, header, cellBlockSize);
|
byte[] b = createHeaderAndMessageBytes(result, header, cellBlockSize);
|
||||||
ByteBuffer[] responseBufs = null;
|
List<ByteBuffer> responseBufs = new ArrayList<ByteBuffer>(
|
||||||
int cellBlockBufferSize = 0;
|
(cellBlock == null ? 1 : cellBlock.size()) + 1);
|
||||||
if (cellBlock != null) {
|
responseBufs.add(ByteBuffer.wrap(b));
|
||||||
cellBlockBufferSize = cellBlock.size();
|
if (cellBlock != null) responseBufs.addAll(cellBlock);
|
||||||
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);
|
bc = new BufferChain(responseBufs);
|
||||||
if (connection.useWrap) {
|
if (connection.useWrap) {
|
||||||
bc = wrapWithSasl(bc);
|
bc = wrapWithSasl(bc);
|
||||||
|
@ -567,10 +555,9 @@ public class RpcServer implements RpcServerInterface, ConfigurationObserver {
|
||||||
+ " as call response.");
|
+ " as call response.");
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer[] responseBufs = new ByteBuffer[2];
|
ByteBuffer bbTokenLength = ByteBuffer.wrap(Bytes.toBytes(token.length));
|
||||||
responseBufs[0] = ByteBuffer.wrap(Bytes.toBytes(token.length));
|
ByteBuffer bbTokenBytes = ByteBuffer.wrap(token);
|
||||||
responseBufs[1] = ByteBuffer.wrap(token);
|
return new BufferChain(bbTokenLength, bbTokenBytes);
|
||||||
return new BufferChain(responseBufs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue