Search in sources :

Example 1 with SlowLogParams

use of org.apache.hadoop.hbase.client.SlowLogParams in project hbase by apache.

the class ProtobufUtil method getSlowLogParams.

/**
 * Return SlowLogParams to maintain recent online slowlog responses
 *
 * @param message Message object {@link Message}
 * @return SlowLogParams with regionName(for filter queries) and params
 */
public static SlowLogParams getSlowLogParams(Message message) {
    if (message == null) {
        return null;
    }
    if (message instanceof ScanRequest) {
        ScanRequest scanRequest = (ScanRequest) message;
        String regionName = getStringForByteString(scanRequest.getRegion().getValue());
        String params = TextFormat.shortDebugString(message);
        return new SlowLogParams(regionName, params);
    } else if (message instanceof MutationProto) {
        MutationProto mutationProto = (MutationProto) message;
        String params = "type= " + mutationProto.getMutateType().toString();
        return new SlowLogParams(params);
    } else if (message instanceof GetRequest) {
        GetRequest getRequest = (GetRequest) message;
        String regionName = getStringForByteString(getRequest.getRegion().getValue());
        String params = "region= " + regionName + ", row= " + getStringForByteString(getRequest.getGet().getRow());
        return new SlowLogParams(regionName, params);
    } else if (message instanceof MultiRequest) {
        MultiRequest multiRequest = (MultiRequest) message;
        int actionsCount = multiRequest.getRegionActionList().stream().mapToInt(ClientProtos.RegionAction::getActionCount).sum();
        RegionAction actions = multiRequest.getRegionActionList().get(0);
        String regionName = getStringForByteString(actions.getRegion().getValue());
        String params = "region= " + regionName + ", for " + actionsCount + " action(s)";
        return new SlowLogParams(regionName, params);
    } else if (message instanceof MutateRequest) {
        MutateRequest mutateRequest = (MutateRequest) message;
        String regionName = getStringForByteString(mutateRequest.getRegion().getValue());
        String params = "region= " + regionName;
        return new SlowLogParams(regionName, params);
    } else if (message instanceof CoprocessorServiceRequest) {
        CoprocessorServiceRequest coprocessorServiceRequest = (CoprocessorServiceRequest) message;
        String params = "coprocessorService= " + coprocessorServiceRequest.getCall().getServiceName() + ":" + coprocessorServiceRequest.getCall().getMethodName();
        return new SlowLogParams(params);
    }
    String params = message.getClass().toString();
    return new SlowLogParams(params);
}
Also used : ScanRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest) CoprocessorServiceRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceRequest) MultiRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiRequest) SlowLogParams(org.apache.hadoop.hbase.client.SlowLogParams) GetRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.GetRequest) MutateRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateRequest) RegionAction(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionAction) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) MutationProto(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto)

Example 2 with SlowLogParams

use of org.apache.hadoop.hbase.client.SlowLogParams 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

SlowLogParams (org.apache.hadoop.hbase.client.SlowLogParams)2 RpcCall (org.apache.hadoop.hbase.ipc.RpcCall)1 RpcLogDetails (org.apache.hadoop.hbase.namequeues.RpcLogDetails)1 ClientProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)1 CoprocessorServiceRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceRequest)1 GetRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.GetRequest)1 MultiRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiRequest)1 MutateRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateRequest)1 MutationProto (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto)1 RegionAction (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionAction)1 ScanRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest)1 TooSlowLog (org.apache.hadoop.hbase.shaded.protobuf.generated.TooSlowLog)1 ByteString (org.apache.hbase.thirdparty.com.google.protobuf.ByteString)1 Descriptors (org.apache.hbase.thirdparty.com.google.protobuf.Descriptors)1 Message (org.apache.hbase.thirdparty.com.google.protobuf.Message)1