Search in sources :

Example 1 with CellBlockMeta

use of org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.CellBlockMeta in project hbase by apache.

the class BlockingRpcConnection method writeRequest.

/**
 * Initiates a call by sending the parameter to the remote server. Note: this is not called from
 * the Connection thread, but by other threads.
 * @see #readResponse()
 */
private void writeRequest(Call call) throws IOException {
    ByteBuf cellBlock = null;
    try {
        cellBlock = this.rpcClient.cellBlockBuilder.buildCellBlock(this.codec, this.compressor, call.cells, PooledByteBufAllocator.DEFAULT);
        CellBlockMeta cellBlockMeta;
        if (cellBlock != null) {
            cellBlockMeta = CellBlockMeta.newBuilder().setLength(cellBlock.readableBytes()).build();
        } else {
            cellBlockMeta = null;
        }
        RequestHeader requestHeader = buildRequestHeader(call, cellBlockMeta);
        setupIOstreams();
        // know where we stand, we have to close the connection.
        if (Thread.interrupted()) {
            throw new InterruptedIOException();
        }
        // We put first as we don't want the connection to become idle.
        calls.put(call.id, call);
        // the pending calls map.
        try {
            call.callStats.setRequestSizeBytes(write(this.out, requestHeader, call.param, cellBlock));
        } catch (Throwable t) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Error while writing {}", call.toShortString());
            }
            IOException e = IPCUtil.toIOE(t);
            closeConn(e);
            return;
        }
    } finally {
        if (cellBlock != null) {
            cellBlock.release();
        }
    }
    notifyAll();
}
Also used : InterruptedIOException(java.io.InterruptedIOException) CellBlockMeta(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.CellBlockMeta) RequestHeader(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.RequestHeader) IPCUtil.buildRequestHeader(org.apache.hadoop.hbase.ipc.IPCUtil.buildRequestHeader) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ByteBuf(org.apache.hbase.thirdparty.io.netty.buffer.ByteBuf)

Example 2 with CellBlockMeta

use of org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.CellBlockMeta in project hbase by apache.

the class NettyRpcDuplexHandler method writeRequest.

private void writeRequest(ChannelHandlerContext ctx, Call call, ChannelPromise promise) throws IOException {
    id2Call.put(call.id, call);
    ByteBuf cellBlock = cellBlockBuilder.buildCellBlock(codec, compressor, call.cells, ctx.alloc());
    CellBlockMeta cellBlockMeta;
    if (cellBlock != null) {
        CellBlockMeta.Builder cellBlockMetaBuilder = CellBlockMeta.newBuilder();
        cellBlockMetaBuilder.setLength(cellBlock.writerIndex());
        cellBlockMeta = cellBlockMetaBuilder.build();
    } else {
        cellBlockMeta = null;
    }
    RequestHeader requestHeader = IPCUtil.buildRequestHeader(call, cellBlockMeta);
    int sizeWithoutCellBlock = IPCUtil.getTotalSizeWhenWrittenDelimited(requestHeader, call.param);
    int totalSize = cellBlock != null ? sizeWithoutCellBlock + cellBlock.writerIndex() : sizeWithoutCellBlock;
    ByteBuf buf = ctx.alloc().buffer(sizeWithoutCellBlock + 4);
    buf.writeInt(totalSize);
    try (ByteBufOutputStream bbos = new ByteBufOutputStream(buf)) {
        requestHeader.writeDelimitedTo(bbos);
        if (call.param != null) {
            call.param.writeDelimitedTo(bbos);
        }
        if (cellBlock != null) {
            ChannelPromise withoutCellBlockPromise = ctx.newPromise();
            ctx.write(buf, withoutCellBlockPromise);
            ChannelPromise cellBlockPromise = ctx.newPromise();
            ctx.write(cellBlock, cellBlockPromise);
            PromiseCombiner combiner = new PromiseCombiner(ctx.executor());
            combiner.addAll((ChannelFuture) withoutCellBlockPromise, cellBlockPromise);
            combiner.finish(promise);
        } else {
            ctx.write(buf, promise);
        }
    }
}
Also used : PromiseCombiner(org.apache.hbase.thirdparty.io.netty.util.concurrent.PromiseCombiner) ByteBufOutputStream(org.apache.hbase.thirdparty.io.netty.buffer.ByteBufOutputStream) CellBlockMeta(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.CellBlockMeta) RequestHeader(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.RequestHeader) ChannelPromise(org.apache.hbase.thirdparty.io.netty.channel.ChannelPromise) ByteBuf(org.apache.hbase.thirdparty.io.netty.buffer.ByteBuf)

Aggregations

CellBlockMeta (org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.CellBlockMeta)2 RequestHeader (org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.RequestHeader)2 ByteBuf (org.apache.hbase.thirdparty.io.netty.buffer.ByteBuf)2 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 IPCUtil.buildRequestHeader (org.apache.hadoop.hbase.ipc.IPCUtil.buildRequestHeader)1 ByteBufOutputStream (org.apache.hbase.thirdparty.io.netty.buffer.ByteBufOutputStream)1 ChannelPromise (org.apache.hbase.thirdparty.io.netty.channel.ChannelPromise)1 PromiseCombiner (org.apache.hbase.thirdparty.io.netty.util.concurrent.PromiseCombiner)1