Search in sources :

Example 1 with Builder

use of org.apache.hadoop.hbase.shaded.com.google.protobuf.Message.Builder in project hbase by apache.

the class BlockingRpcConnection method readResponse.

/*
   * Receive a response. Because only one receiver, so no synchronization on in.
   */
private void readResponse() {
    Call call = null;
    boolean expectedCall = false;
    try {
        // See HBaseServer.Call.setResponse for where we write out the response.
        // Total size of the response. Unused. But have to read it in anyways.
        int totalSize = in.readInt();
        // Read the header
        ResponseHeader responseHeader = ResponseHeader.parseDelimitedFrom(in);
        int id = responseHeader.getCallId();
        // call.done have to be set before leaving this method
        call = calls.remove(id);
        expectedCall = (call != null && !call.isDone());
        if (!expectedCall) {
            // So we got a response for which we have no corresponding 'call' here on the client-side.
            // We probably timed out waiting, cleaned up all references, and now the server decides
            // to return a response. There is nothing we can do w/ the response at this stage. Clean
            // out the wire of the response so its out of the way and we can get other responses on
            // this connection.
            int readSoFar = getTotalSizeWhenWrittenDelimited(responseHeader);
            int whatIsLeftToRead = totalSize - readSoFar;
            IOUtils.skipFully(in, whatIsLeftToRead);
            if (call != null) {
                call.callStats.setResponseSizeBytes(totalSize);
                call.callStats.setCallTimeMs(EnvironmentEdgeManager.currentTime() - call.callStats.getStartTime());
            }
            return;
        }
        if (responseHeader.hasException()) {
            ExceptionResponse exceptionResponse = responseHeader.getException();
            RemoteException re = createRemoteException(exceptionResponse);
            call.setException(re);
            call.callStats.setResponseSizeBytes(totalSize);
            call.callStats.setCallTimeMs(EnvironmentEdgeManager.currentTime() - call.callStats.getStartTime());
            if (isFatalConnectionException(exceptionResponse)) {
                synchronized (this) {
                    closeConn(re);
                }
            }
        } else {
            Message value = null;
            if (call.responseDefaultType != null) {
                Builder builder = call.responseDefaultType.newBuilderForType();
                ProtobufUtil.mergeDelimitedFrom(builder, in);
                value = builder.build();
            }
            CellScanner cellBlockScanner = null;
            if (responseHeader.hasCellBlockMeta()) {
                int size = responseHeader.getCellBlockMeta().getLength();
                byte[] cellBlock = new byte[size];
                IOUtils.readFully(this.in, cellBlock, 0, cellBlock.length);
                cellBlockScanner = this.rpcClient.cellBlockBuilder.createCellScanner(this.codec, this.compressor, cellBlock);
            }
            call.setResponse(value, cellBlockScanner);
            call.callStats.setResponseSizeBytes(totalSize);
            call.callStats.setCallTimeMs(EnvironmentEdgeManager.currentTime() - call.callStats.getStartTime());
        }
    } catch (IOException e) {
        if (expectedCall) {
            call.setException(e);
        }
        if (e instanceof SocketTimeoutException) {
            // {@link ConnectionId#rpcTimeout}.
            if (LOG.isTraceEnabled()) {
                LOG.trace("ignored", e);
            }
        } else {
            synchronized (this) {
                closeConn(e);
            }
        }
    }
}
Also used : ResponseHeader(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.ResponseHeader) ExceptionResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.ExceptionResponse) SocketTimeoutException(java.net.SocketTimeoutException) Message(org.apache.hadoop.hbase.shaded.com.google.protobuf.Message) Builder(org.apache.hadoop.hbase.shaded.com.google.protobuf.Message.Builder) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) IPCUtil.createRemoteException(org.apache.hadoop.hbase.ipc.IPCUtil.createRemoteException) RemoteException(org.apache.hadoop.ipc.RemoteException) CellScanner(org.apache.hadoop.hbase.CellScanner)

Example 2 with Builder

use of org.apache.hadoop.hbase.shaded.com.google.protobuf.Message.Builder 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) {
        // So we got a response for which we have no corresponding 'call' here on the client-side.
        // We probably timed out waiting, cleaned up all references, and now the server decides
        // to return a response. There is nothing we can do w/ the response at this stage. Clean
        // out the wire of the response so its out of the way and we can get other responses on
        // this connection.
        int readSoFar = IPCUtil.getTotalSizeWhenWrittenDelimited(responseHeader);
        int whatIsLeftToRead = totalSize - readSoFar;
        if (LOG.isDebugEnabled()) {
            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.hadoop.hbase.shaded.com.google.protobuf.Message) Builder(org.apache.hadoop.hbase.shaded.com.google.protobuf.Message.Builder) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) RemoteException(org.apache.hadoop.ipc.RemoteException) CellScanner(org.apache.hadoop.hbase.CellScanner)

Aggregations

CellScanner (org.apache.hadoop.hbase.CellScanner)2 Message (org.apache.hadoop.hbase.shaded.com.google.protobuf.Message)2 Builder (org.apache.hadoop.hbase.shaded.com.google.protobuf.Message.Builder)2 ExceptionResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.ExceptionResponse)2 ResponseHeader (org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.ResponseHeader)2 RemoteException (org.apache.hadoop.ipc.RemoteException)2 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 IPCUtil.createRemoteException (org.apache.hadoop.hbase.ipc.IPCUtil.createRemoteException)1