Search in sources :

Example 1 with ByteBufInputStream

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

the class NettyRpcDuplexHandler method readResponse.

private void readResponse(ChannelHandlerContext ctx, ByteBuf buf) throws IOException {
    int totalSize = buf.readInt();
    ByteBufInputStream in = new ByteBufInputStream(buf);
    ResponseHeader responseHeader = ResponseHeader.parseDelimitedFrom(in);
    int id = responseHeader.getCallId();
    if (LOG.isTraceEnabled()) {
        LOG.trace("got response header " + TextFormat.shortDebugString(responseHeader) + ", totalSize: " + totalSize + " bytes");
    }
    RemoteException remoteExc;
    if (responseHeader.hasException()) {
        ExceptionResponse exceptionResponse = responseHeader.getException();
        remoteExc = IPCUtil.createRemoteException(exceptionResponse);
        if (IPCUtil.isFatalConnectionException(exceptionResponse)) {
            // Here we will cleanup all calls so do not need to fall back, just return.
            exceptionCaught(ctx, remoteExc);
            return;
        }
    } else {
        remoteExc = null;
    }
    Call call = id2Call.remove(id);
    if (call == null) {
        // this connection.
        if (LOG.isDebugEnabled()) {
            int readSoFar = IPCUtil.getTotalSizeWhenWrittenDelimited(responseHeader);
            int whatIsLeftToRead = totalSize - readSoFar;
            LOG.debug("Unknown callId: " + id + ", skipping over this response of " + whatIsLeftToRead + " bytes");
        }
        return;
    }
    if (remoteExc != null) {
        call.setException(remoteExc);
        return;
    }
    Message value;
    if (call.responseDefaultType != null) {
        Builder builder = call.responseDefaultType.newBuilderForType();
        builder.mergeDelimitedFrom(in);
        value = builder.build();
    } else {
        value = null;
    }
    CellScanner cellBlockScanner;
    if (responseHeader.hasCellBlockMeta()) {
        int size = responseHeader.getCellBlockMeta().getLength();
        // Maybe we could read directly from the ByteBuf.
        // The problem here is that we do not know when to release it.
        byte[] cellBlock = new byte[size];
        buf.readBytes(cellBlock);
        cellBlockScanner = cellBlockBuilder.createCellScanner(this.codec, this.compressor, cellBlock);
    } else {
        cellBlockScanner = null;
    }
    call.setResponse(value, cellBlockScanner);
}
Also used : ResponseHeader(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.ResponseHeader) ExceptionResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.ExceptionResponse) Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) Builder(org.apache.hbase.thirdparty.com.google.protobuf.Message.Builder) ByteBufInputStream(org.apache.hbase.thirdparty.io.netty.buffer.ByteBufInputStream) RemoteException(org.apache.hadoop.ipc.RemoteException) CellScanner(org.apache.hadoop.hbase.CellScanner)

Aggregations

CellScanner (org.apache.hadoop.hbase.CellScanner)1 ExceptionResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.ExceptionResponse)1 ResponseHeader (org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.ResponseHeader)1 RemoteException (org.apache.hadoop.ipc.RemoteException)1 Message (org.apache.hbase.thirdparty.com.google.protobuf.Message)1 Builder (org.apache.hbase.thirdparty.com.google.protobuf.Message.Builder)1 ByteBufInputStream (org.apache.hbase.thirdparty.io.netty.buffer.ByteBufInputStream)1