Search in sources :

Example 1 with RpcLogDetails

use of org.apache.hadoop.hbase.namequeues.RpcLogDetails in project hbase by apache.

the class RpcServer method call.

/**
 * This is a server side method, which is invoked over RPC. On success
 * the return response has protobuf response payload. On failure, the
 * exception name and the stack trace are returned in the protobuf response.
 */
@Override
public Pair<Message, CellScanner> call(RpcCall call, MonitoredRPCHandler status) throws IOException {
    try {
        MethodDescriptor md = call.getMethod();
        Message param = call.getParam();
        status.setRPC(md.getName(), new Object[] { param }, call.getReceiveTime());
        // TODO: Review after we add in encoded data blocks.
        status.setRPCPacket(param);
        status.resume("Servicing call");
        // get an instance of the method arg type
        HBaseRpcController controller = new HBaseRpcControllerImpl(call.getCellScanner());
        controller.setCallTimeout(call.getTimeout());
        Message result = call.getService().callBlockingMethod(md, controller, param);
        long receiveTime = call.getReceiveTime();
        long startTime = call.getStartTime();
        long endTime = EnvironmentEdgeManager.currentTime();
        int processingTime = (int) (endTime - startTime);
        int qTime = (int) (startTime - receiveTime);
        int totalTime = (int) (endTime - receiveTime);
        if (LOG.isTraceEnabled()) {
            LOG.trace(CurCall.get().toString() + ", response " + TextFormat.shortDebugString(result) + " queueTime: " + qTime + " processingTime: " + processingTime + " totalTime: " + totalTime);
        }
        // Use the raw request call size for now.
        long requestSize = call.getSize();
        long responseSize = result.getSerializedSize();
        if (call.isClientCellBlockSupported()) {
            // Include the payload size in HBaseRpcController
            responseSize += call.getResponseCellSize();
        }
        metrics.dequeuedCall(qTime);
        metrics.processedCall(processingTime);
        metrics.totalCall(totalTime);
        metrics.receivedRequest(requestSize);
        metrics.sentResponse(responseSize);
        // log any RPC responses that are slower than the configured warn
        // response time or larger than configured warning size
        boolean tooSlow = (processingTime > warnResponseTime && warnResponseTime > -1);
        boolean tooLarge = (responseSize > warnResponseSize && warnResponseSize > -1);
        if (tooSlow || tooLarge) {
            final String userName = call.getRequestUserName().orElse(StringUtils.EMPTY);
            // when tagging, we let TooLarge trump TooSmall to keep output simple
            // note that large responses will often also be slow.
            logResponse(param, md.getName(), md.getName() + "(" + param.getClass().getName() + ")", tooLarge, tooSlow, status.getClient(), startTime, processingTime, qTime, responseSize, userName);
            if (this.namedQueueRecorder != null && this.isOnlineLogProviderEnabled) {
                // send logs to ring buffer owned by slowLogRecorder
                final String className = server == null ? StringUtils.EMPTY : server.getClass().getSimpleName();
                this.namedQueueRecorder.addRecord(new RpcLogDetails(call, param, status.getClient(), responseSize, className, tooSlow, tooLarge));
            }
        }
        return new Pair<>(result, controller.cellScanner());
    } catch (Throwable e) {
        // need to pass it over the wire.
        if (e instanceof ServiceException) {
            if (e.getCause() == null) {
                LOG.debug("Caught a ServiceException with null cause", e);
            } else {
                e = e.getCause();
            }
        }
        // increment the number of requests that were exceptions.
        metrics.exception(e);
        if (e instanceof LinkageError)
            throw new DoNotRetryIOException(e);
        if (e instanceof IOException)
            throw (IOException) e;
        LOG.error("Unexpected throwable object ", e);
        throw new IOException(e.getMessage(), e);
    }
}
Also used : Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) RpcLogDetails(org.apache.hadoop.hbase.namequeues.RpcLogDetails) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) MethodDescriptor(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.MethodDescriptor) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) Pair(org.apache.hadoop.hbase.util.Pair)

Example 2 with RpcLogDetails

use of org.apache.hadoop.hbase.namequeues.RpcLogDetails 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)

Aggregations

RpcLogDetails (org.apache.hadoop.hbase.namequeues.RpcLogDetails)2 Message (org.apache.hbase.thirdparty.com.google.protobuf.Message)2 IOException (java.io.IOException)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 SlowLogParams (org.apache.hadoop.hbase.client.SlowLogParams)1 RpcCall (org.apache.hadoop.hbase.ipc.RpcCall)1 ClientProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)1 TooSlowLog (org.apache.hadoop.hbase.shaded.protobuf.generated.TooSlowLog)1 Pair (org.apache.hadoop.hbase.util.Pair)1 Descriptors (org.apache.hbase.thirdparty.com.google.protobuf.Descriptors)1 MethodDescriptor (org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.MethodDescriptor)1 ServiceException (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException)1