Search in sources :

Example 11 with Message

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

the class ServerCall method setResponse.

@Override
public synchronized void setResponse(Message m, final CellScanner cells, Throwable t, String errorMsg) {
    if (this.isError) {
        return;
    }
    if (t != null) {
        this.isError = true;
        TraceUtil.setError(span, t);
    } else {
        span.setStatus(StatusCode.OK);
    }
    BufferChain bc = null;
    try {
        ResponseHeader.Builder headerBuilder = ResponseHeader.newBuilder();
        // Call id.
        headerBuilder.setCallId(this.id);
        if (t != null) {
            setExceptionResponse(t, errorMsg, headerBuilder);
        }
        // Pass reservoir to buildCellBlock. Keep reference to returne so can add it back to the
        // reservoir when finished. This is hacky and the hack is not contained but benefits are
        // high when we can avoid a big buffer allocation on each rpc.
        List<ByteBuffer> cellBlock = null;
        int cellBlockSize = 0;
        if (bbAllocator.isReservoirEnabled()) {
            this.cellBlockStream = this.cellBlockBuilder.buildCellBlockStream(this.connection.codec, this.connection.compressionCodec, cells, bbAllocator);
            if (this.cellBlockStream != null) {
                cellBlock = this.cellBlockStream.getByteBuffers();
                cellBlockSize = this.cellBlockStream.size();
            }
        } else {
            ByteBuffer b = this.cellBlockBuilder.buildCellBlock(this.connection.codec, this.connection.compressionCodec, cells);
            if (b != null) {
                cellBlockSize = b.remaining();
                cellBlock = new ArrayList<>(1);
                cellBlock.add(b);
            }
        }
        if (cellBlockSize > 0) {
            CellBlockMeta.Builder cellBlockBuilder = CellBlockMeta.newBuilder();
            // Presumes the cellBlock bytebuffer has been flipped so limit has total size in it.
            cellBlockBuilder.setLength(cellBlockSize);
            headerBuilder.setCellBlockMeta(cellBlockBuilder.build());
        }
        Message header = headerBuilder.build();
        ByteBuffer headerBuf = createHeaderAndMessageBytes(m, header, cellBlockSize, cellBlock);
        ByteBuffer[] responseBufs = null;
        int cellBlockBufferSize = 0;
        if (cellBlock != null) {
            cellBlockBufferSize = cellBlock.size();
            responseBufs = new ByteBuffer[1 + cellBlockBufferSize];
        } else {
            responseBufs = new ByteBuffer[1];
        }
        responseBufs[0] = headerBuf;
        if (cellBlock != null) {
            for (int i = 0; i < cellBlockBufferSize; i++) {
                responseBufs[i + 1] = cellBlock.get(i);
            }
        }
        bc = new BufferChain(responseBufs);
    } catch (IOException e) {
        RpcServer.LOG.warn("Exception while creating response " + e);
    }
    this.response = bc;
    // done. The Responder thread will do the n/w write of this message back to client.
    if (this.rpcCallback != null) {
        try {
            this.rpcCallback.run();
        } catch (Exception e) {
            // Don't allow any exception here to kill this handler thread.
            RpcServer.LOG.warn("Exception while running the Rpc Callback.", e);
        }
    }
}
Also used : ResponseHeader(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.ResponseHeader) Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) RegionMovedException(org.apache.hadoop.hbase.exceptions.RegionMovedException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) CellBlockMeta(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.CellBlockMeta)

Example 12 with Message

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

the class SlowLogQueueService method consumeEventFromDisruptor.

/**
 * This implementation is specific to slowLog event. This consumes slowLog event from
 * disruptor and inserts records to EvictingQueue.
 *
 * @param namedQueuePayload namedQueue payload from disruptor ring buffer
 */
@Override
public void consumeEventFromDisruptor(NamedQueuePayload namedQueuePayload) {
    if (!isOnlineLogProviderEnabled) {
        return;
    }
    if (!(namedQueuePayload instanceof RpcLogDetails)) {
        LOG.warn("SlowLogQueueService: NamedQueuePayload is not of type RpcLogDetails.");
        return;
    }
    final RpcLogDetails rpcLogDetails = (RpcLogDetails) namedQueuePayload;
    final RpcCall rpcCall = rpcLogDetails.getRpcCall();
    final String clientAddress = rpcLogDetails.getClientAddress();
    final long responseSize = rpcLogDetails.getResponseSize();
    final String className = rpcLogDetails.getClassName();
    final TooSlowLog.SlowLogPayload.Type type = getLogType(rpcLogDetails);
    if (type == null) {
        return;
    }
    Descriptors.MethodDescriptor methodDescriptor = rpcCall.getMethod();
    Message param = rpcLogDetails.getParam();
    long receiveTime = rpcCall.getReceiveTime();
    long startTime = rpcCall.getStartTime();
    long endTime = EnvironmentEdgeManager.currentTime();
    int processingTime = (int) (endTime - startTime);
    int qTime = (int) (startTime - receiveTime);
    final SlowLogParams slowLogParams = ProtobufUtil.getSlowLogParams(param);
    int numGets = 0;
    int numMutations = 0;
    int numServiceCalls = 0;
    if (param instanceof ClientProtos.MultiRequest) {
        ClientProtos.MultiRequest multi = (ClientProtos.MultiRequest) param;
        for (ClientProtos.RegionAction regionAction : multi.getRegionActionList()) {
            for (ClientProtos.Action action : regionAction.getActionList()) {
                if (action.hasMutation()) {
                    numMutations++;
                }
                if (action.hasGet()) {
                    numGets++;
                }
                if (action.hasServiceCall()) {
                    numServiceCalls++;
                }
            }
        }
    }
    final String userName = rpcCall.getRequestUserName().orElse(StringUtils.EMPTY);
    final String methodDescriptorName = methodDescriptor != null ? methodDescriptor.getName() : StringUtils.EMPTY;
    TooSlowLog.SlowLogPayload slowLogPayload = TooSlowLog.SlowLogPayload.newBuilder().setCallDetails(methodDescriptorName + "(" + param.getClass().getName() + ")").setClientAddress(clientAddress).setMethodName(methodDescriptorName).setMultiGets(numGets).setMultiMutations(numMutations).setMultiServiceCalls(numServiceCalls).setParam(slowLogParams != null ? slowLogParams.getParams() : StringUtils.EMPTY).setProcessingTime(processingTime).setQueueTime(qTime).setRegionName(slowLogParams != null ? slowLogParams.getRegionName() : StringUtils.EMPTY).setResponseSize(responseSize).setServerClass(className).setStartTime(startTime).setType(type).setUserName(userName).build();
    slowLogQueue.add(slowLogPayload);
    if (isSlowLogTableEnabled) {
        if (!slowLogPayload.getRegionName().startsWith("hbase:slowlog")) {
            slowLogPersistentService.addToQueueForSysTable(slowLogPayload);
        }
    }
}
Also used : Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) TooSlowLog(org.apache.hadoop.hbase.shaded.protobuf.generated.TooSlowLog) RpcLogDetails(org.apache.hadoop.hbase.namequeues.RpcLogDetails) RpcCall(org.apache.hadoop.hbase.ipc.RpcCall) SlowLogParams(org.apache.hadoop.hbase.client.SlowLogParams) Descriptors(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)

Example 13 with Message

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

the class TestNamedQueueRecorder method getMessage.

private static Message getMessage() {
    i = (i + 1) % 3;
    Message message = null;
    switch(i) {
        case 0:
            {
                message = ClientProtos.ScanRequest.newBuilder().setRegion(HBaseProtos.RegionSpecifier.newBuilder().setValue(ByteString.copyFromUtf8("region1")).setType(HBaseProtos.RegionSpecifier.RegionSpecifierType.REGION_NAME).build()).build();
                break;
            }
        case 1:
            {
                message = ClientProtos.MutateRequest.newBuilder().setRegion(HBaseProtos.RegionSpecifier.newBuilder().setValue(ByteString.copyFromUtf8("region2")).setType(HBaseProtos.RegionSpecifier.RegionSpecifierType.REGION_NAME)).setMutation(ClientProtos.MutationProto.newBuilder().setRow(ByteString.copyFromUtf8("row123")).build()).build();
                break;
            }
        case 2:
            {
                message = ClientProtos.GetRequest.newBuilder().setRegion(HBaseProtos.RegionSpecifier.newBuilder().setValue(ByteString.copyFromUtf8("region2")).setType(HBaseProtos.RegionSpecifier.RegionSpecifierType.REGION_NAME)).setGet(ClientProtos.Get.newBuilder().setRow(ByteString.copyFromUtf8("row123")).build()).build();
                break;
            }
        default:
            throw new RuntimeException("Not supposed to get here?");
    }
    return message;
}
Also used : Message(org.apache.hbase.thirdparty.com.google.protobuf.Message)

Example 14 with Message

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

the class HRegion method execService.

/**
 * Executes a single protocol buffer coprocessor endpoint {@link Service} method using
 * the registered protocol handlers.  {@link Service} implementations must be registered via the
 * {@link #registerService(Service)}
 * method before they are available.
 *
 * @param controller an {@code RpcContoller} implementation to pass to the invoked service
 * @param call a {@code CoprocessorServiceCall} instance identifying the service, method,
 *     and parameters for the method invocation
 * @return a protocol buffer {@code Message} instance containing the method's result
 * @throws IOException if no registered service handler is found or an error
 *     occurs during the invocation
 * @see #registerService(Service)
 */
public Message execService(RpcController controller, CoprocessorServiceCall call) throws IOException {
    String serviceName = call.getServiceName();
    Service service = coprocessorServiceHandlers.get(serviceName);
    if (service == null) {
        throw new UnknownProtocolException(null, "No registered coprocessor service found for " + serviceName + " in region " + Bytes.toStringBinary(getRegionInfo().getRegionName()));
    }
    ServiceDescriptor serviceDesc = service.getDescriptorForType();
    cpRequestsCount.increment();
    String methodName = call.getMethodName();
    MethodDescriptor methodDesc = CoprocessorRpcUtils.getMethodDescriptor(methodName, serviceDesc);
    Message.Builder builder = service.getRequestPrototype(methodDesc).newBuilderForType();
    ProtobufUtil.mergeFrom(builder, call.getRequest().toByteArray());
    Message request = CoprocessorRpcUtils.getRequest(service, methodDesc, call.getRequest());
    if (coprocessorHost != null) {
        request = coprocessorHost.preEndpointInvocation(service, methodName, request);
    }
    final Message.Builder responseBuilder = service.getResponsePrototype(methodDesc).newBuilderForType();
    service.callMethod(methodDesc, controller, request, new RpcCallback<Message>() {

        @Override
        public void run(Message message) {
            if (message != null) {
                responseBuilder.mergeFrom(message);
            }
        }
    });
    if (coprocessorHost != null) {
        coprocessorHost.postEndpointInvocation(service, methodName, request, responseBuilder);
    }
    IOException exception = org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils.getControllerException(controller);
    if (exception != null) {
        throw exception;
    }
    return responseBuilder.build();
}
Also used : Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) ServiceDescriptor(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.ServiceDescriptor) Service(org.apache.hbase.thirdparty.com.google.protobuf.Service) CompletionService(java.util.concurrent.CompletionService) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) UnknownProtocolException(org.apache.hadoop.hbase.exceptions.UnknownProtocolException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) TimeoutIOException(org.apache.hadoop.hbase.exceptions.TimeoutIOException) InterruptedIOException(java.io.InterruptedIOException) MethodDescriptor(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.MethodDescriptor)

Example 15 with Message

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

the class RegionCoprocessorRpcChannelImpl method rpcCall.

private CompletableFuture<Message> rpcCall(MethodDescriptor method, Message request, Message responsePrototype, HBaseRpcController controller, HRegionLocation loc, ClientService.Interface stub) {
    CompletableFuture<Message> future = new CompletableFuture<>();
    if (region != null && !Bytes.equals(loc.getRegion().getRegionName(), region.getRegionName())) {
        future.completeExceptionally(new DoNotRetryIOException("Region name is changed, expected " + region.getRegionNameAsString() + ", actual " + loc.getRegion().getRegionNameAsString()));
        return future;
    }
    CoprocessorServiceRequest csr = CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request, row, loc.getRegion().getRegionName());
    stub.execService(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 {
                lastRegion = resp.getRegion().getValue().toByteArray();
                try {
                    future.complete(CoprocessorRpcUtils.getResponse(resp, responsePrototype));
                } catch (IOException e) {
                    future.completeExceptionally(e);
                }
            }
        }
    });
    return future;
}
Also used : Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) CoprocessorServiceRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceRequest) CoprocessorServiceResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceResponse)

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