|
35 | 35 | import java.net.Socket; |
36 | 36 | import java.net.SocketTimeoutException; |
37 | 37 | import java.net.UnknownHostException; |
38 | | -import java.nio.ByteBuffer; |
39 | 38 | import java.security.PrivilegedExceptionAction; |
40 | 39 | import java.util.ArrayDeque; |
41 | 40 | import java.util.Locale; |
|
70 | 69 | import org.apache.hbase.thirdparty.com.google.protobuf.Message; |
71 | 70 | import org.apache.hbase.thirdparty.com.google.protobuf.Message.Builder; |
72 | 71 | import org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback; |
| 72 | +import org.apache.hbase.thirdparty.io.netty.buffer.ByteBuf; |
| 73 | +import org.apache.hbase.thirdparty.io.netty.buffer.PooledByteBufAllocator; |
73 | 74 | import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; |
74 | 75 | import org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos; |
75 | 76 | import org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.CellBlockMeta; |
@@ -599,37 +600,44 @@ private void tracedWriteRequest(Call call) throws IOException { |
599 | 600 | * @see #readResponse() |
600 | 601 | */ |
601 | 602 | private void writeRequest(Call call) throws IOException { |
602 | | - ByteBuffer cellBlock = this.rpcClient.cellBlockBuilder.buildCellBlock(this.codec, |
603 | | - this.compressor, call.cells); |
604 | | - CellBlockMeta cellBlockMeta; |
605 | | - if (cellBlock != null) { |
606 | | - cellBlockMeta = CellBlockMeta.newBuilder().setLength(cellBlock.limit()).build(); |
607 | | - } else { |
608 | | - cellBlockMeta = null; |
609 | | - } |
610 | | - RequestHeader requestHeader = buildRequestHeader(call, cellBlockMeta); |
| 603 | + ByteBuf cellBlock = null; |
| 604 | + try { |
| 605 | + cellBlock = this.rpcClient.cellBlockBuilder.buildCellBlock(this.codec, this.compressor, |
| 606 | + call.cells, PooledByteBufAllocator.DEFAULT); |
| 607 | + CellBlockMeta cellBlockMeta; |
| 608 | + if (cellBlock != null) { |
| 609 | + cellBlockMeta = CellBlockMeta.newBuilder().setLength(cellBlock.readableBytes()).build(); |
| 610 | + } else { |
| 611 | + cellBlockMeta = null; |
| 612 | + } |
| 613 | + RequestHeader requestHeader = buildRequestHeader(call, cellBlockMeta); |
611 | 614 |
|
612 | | - setupIOstreams(); |
| 615 | + setupIOstreams(); |
613 | 616 |
|
614 | | - // Now we're going to write the call. We take the lock, then check that the connection |
615 | | - // is still valid, and, if so we do the write to the socket. If the write fails, we don't |
616 | | - // know where we stand, we have to close the connection. |
617 | | - if (Thread.interrupted()) { |
618 | | - throw new InterruptedIOException(); |
619 | | - } |
| 617 | + // Now we're going to write the call. We take the lock, then check that the connection |
| 618 | + // is still valid, and, if so we do the write to the socket. If the write fails, we don't |
| 619 | + // know where we stand, we have to close the connection. |
| 620 | + if (Thread.interrupted()) { |
| 621 | + throw new InterruptedIOException(); |
| 622 | + } |
620 | 623 |
|
621 | | - calls.put(call.id, call); // We put first as we don't want the connection to become idle. |
622 | | - // from here, we do not throw any exception to upper layer as the call has been tracked in the |
623 | | - // pending calls map. |
624 | | - try { |
625 | | - call.callStats.setRequestSizeBytes(write(this.out, requestHeader, call.param, cellBlock)); |
626 | | - } catch (Throwable t) { |
627 | | - if(LOG.isTraceEnabled()) { |
628 | | - LOG.trace("Error while writing call, call_id:" + call.id, t); |
| 624 | + calls.put(call.id, call); // We put first as we don't want the connection to become idle. |
| 625 | + // from here, we do not throw any exception to upper layer as the call has been tracked in |
| 626 | + // the pending calls map. |
| 627 | + try { |
| 628 | + call.callStats.setRequestSizeBytes(write(this.out, requestHeader, call.param, cellBlock)); |
| 629 | + } catch (Throwable t) { |
| 630 | + if(LOG.isTraceEnabled()) { |
| 631 | + LOG.trace("Error while writing call, call_id:" + call.id, t); |
| 632 | + } |
| 633 | + IOException e = IPCUtil.toIOE(t); |
| 634 | + closeConn(e); |
| 635 | + return; |
| 636 | + } |
| 637 | + } finally { |
| 638 | + if (cellBlock != null) { |
| 639 | + cellBlock.release(); |
629 | 640 | } |
630 | | - IOException e = IPCUtil.toIOE(t); |
631 | | - closeConn(e); |
632 | | - return; |
633 | 641 | } |
634 | 642 | notifyAll(); |
635 | 643 | } |
|
0 commit comments