Search in sources :

Example 11 with ByteBuf

use of org.apache.hbase.thirdparty.io.netty.buffer.ByteBuf in project hbase by apache.

the class SaslChallengeDecoder method decode.

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    int readableBytes = in.readableBytes();
    if (readableBytes < 4) {
        return;
    }
    int offset = in.readerIndex();
    int status = in.getInt(offset);
    if (status == SaslStatus.SUCCESS.state) {
        ByteBuf challenge = tryDecodeChallenge(in, offset + 4, readableBytes - 4);
        if (challenge != null) {
            out.add(challenge);
        }
    } else {
        tryDecodeError(in, offset + 4, readableBytes - 4);
    }
}
Also used : ByteBuf(org.apache.hbase.thirdparty.io.netty.buffer.ByteBuf)

Example 12 with ByteBuf

use of org.apache.hbase.thirdparty.io.netty.buffer.ByteBuf 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

ByteBuf (org.apache.hbase.thirdparty.io.netty.buffer.ByteBuf)12 IOException (java.io.IOException)5 InterruptedIOException (java.io.InterruptedIOException)4 ChannelPromise (org.apache.hbase.thirdparty.io.netty.channel.ChannelPromise)3 PromiseCombiner (org.apache.hbase.thirdparty.io.netty.util.concurrent.PromiseCombiner)3 ExecutionException (java.util.concurrent.ExecutionException)2 CellBlockMeta (org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.CellBlockMeta)2 RequestHeader (org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.RequestHeader)2 PacketHeader (org.apache.hadoop.hdfs.protocol.datatransfer.PacketHeader)2 ByteBufOutputStream (org.apache.hbase.thirdparty.io.netty.buffer.ByteBufOutputStream)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 IPCUtil.buildRequestHeader (org.apache.hadoop.hbase.ipc.IPCUtil.buildRequestHeader)1 DataNodeProperties (org.apache.hadoop.hdfs.MiniDFSCluster.DataNodeProperties)1 DatanodeInfo (org.apache.hadoop.hdfs.protocol.DatanodeInfo)1 OpWriteBlockProto (org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.OpWriteBlockProto)1 Channel (org.apache.hbase.thirdparty.io.netty.channel.Channel)1