Search in sources :

Example 26 with Message

use of org.apache.hbase.thirdparty.com.google.protobuf.Message in project hbase by apache.

the class IPCUtil method getTotalSizeWhenWrittenDelimited.

/**
 * @return Size on the wire when the two messages are written with writeDelimitedTo
 */
public static int getTotalSizeWhenWrittenDelimited(Message... messages) {
    int totalSize = 0;
    for (Message m : messages) {
        if (m == null) {
            continue;
        }
        totalSize += m.getSerializedSize();
        totalSize += CodedOutputStream.computeUInt32SizeNoTag(m.getSerializedSize());
    }
    Preconditions.checkArgument(totalSize < Integer.MAX_VALUE);
    return totalSize;
}
Also used : Message(org.apache.hbase.thirdparty.com.google.protobuf.Message)

Example 27 with Message

use of org.apache.hbase.thirdparty.com.google.protobuf.Message 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)

Example 28 with Message

use of org.apache.hbase.thirdparty.com.google.protobuf.Message in project hbase by apache.

the class MasterCoprocessorRpcChannelImpl method rpcCall.

private CompletableFuture<Message> rpcCall(MethodDescriptor method, Message request, Message responsePrototype, HBaseRpcController controller, MasterService.Interface stub) {
    CompletableFuture<Message> future = new CompletableFuture<>();
    CoprocessorServiceRequest csr = CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request);
    stub.execMasterService(controller, csr, new org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback<CoprocessorServiceResponse>() {

        @Override
        public void run(CoprocessorServiceResponse resp) {
            if (controller.failed()) {
                future.completeExceptionally(controller.getFailed());
            } else {
                try {
                    future.complete(CoprocessorRpcUtils.getResponse(resp, responsePrototype));
                } catch (IOException e) {
                    future.completeExceptionally(e);
                }
            }
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) CoprocessorServiceRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceRequest) Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) CoprocessorServiceResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceResponse) IOException(java.io.IOException)

Aggregations

Message (org.apache.hbase.thirdparty.com.google.protobuf.Message)28 IOException (java.io.IOException)19 CompletableFuture (java.util.concurrent.CompletableFuture)11 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)11 Result (org.apache.hadoop.hbase.client.Result)8 Map (java.util.Map)7 NavigableMap (java.util.NavigableMap)7 NavigableSet (java.util.NavigableSet)7 NoSuchElementException (java.util.NoSuchElementException)7 TreeMap (java.util.TreeMap)7 Cell (org.apache.hadoop.hbase.Cell)7 HConstants (org.apache.hadoop.hbase.HConstants)7 AdvancedScanResultConsumer (org.apache.hadoop.hbase.client.AdvancedScanResultConsumer)7 AsyncTable (org.apache.hadoop.hbase.client.AsyncTable)7 CoprocessorCallback (org.apache.hadoop.hbase.client.AsyncTable.CoprocessorCallback)7 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)7 Scan (org.apache.hadoop.hbase.client.Scan)7 AggregationHelper.getParsedGenericInstance (org.apache.hadoop.hbase.client.coprocessor.AggregationHelper.getParsedGenericInstance)7 AggregationHelper.validateArgAndGetPB (org.apache.hadoop.hbase.client.coprocessor.AggregationHelper.validateArgAndGetPB)7 ColumnInterpreter (org.apache.hadoop.hbase.coprocessor.ColumnInterpreter)7