Search in sources :

Example 1 with IpcClientSpanBuilder

use of org.apache.hadoop.hbase.client.trace.IpcClientSpanBuilder in project hbase by apache.

the class AbstractRpcClient method callMethod.

private Call callMethod(final Descriptors.MethodDescriptor md, final HBaseRpcController hrc, final Message param, Message returnType, final User ticket, final Address addr, final RpcCallback<Message> callback) {
    Span span = new IpcClientSpanBuilder().setMethodDescriptor(md).setRemoteAddress(addr).build();
    try (Scope scope = span.makeCurrent()) {
        final MetricsConnection.CallStats cs = MetricsConnection.newCallStats();
        cs.setStartTime(EnvironmentEdgeManager.currentTime());
        if (param instanceof ClientProtos.MultiRequest) {
            ClientProtos.MultiRequest req = (ClientProtos.MultiRequest) param;
            int numActions = 0;
            for (ClientProtos.RegionAction regionAction : req.getRegionActionList()) {
                numActions += regionAction.getActionCount();
            }
            cs.setNumActionsPerServer(numActions);
        }
        final AtomicInteger counter = concurrentCounterCache.getUnchecked(addr);
        Call call = new Call(nextCallId(), md, param, hrc.cellScanner(), returnType, hrc.getCallTimeout(), hrc.getPriority(), new RpcCallback<Call>() {

            @Override
            public void run(Call call) {
                try (Scope scope = call.span.makeCurrent()) {
                    counter.decrementAndGet();
                    onCallFinished(call, hrc, addr, callback);
                } finally {
                    if (hrc.failed()) {
                        TraceUtil.setError(span, hrc.getFailed());
                    } else {
                        span.setStatus(StatusCode.OK);
                    }
                    span.end();
                }
            }
        }, cs);
        ConnectionId remoteId = new ConnectionId(ticket, md.getService().getName(), addr);
        int count = counter.incrementAndGet();
        try {
            if (count > maxConcurrentCallsPerServer) {
                throw new ServerTooBusyException(addr, count);
            }
            cs.setConcurrentCallsPerServer(count);
            T connection = getConnection(remoteId);
            connection.sendRequest(call, hrc);
        } catch (Exception e) {
            call.setException(toIOE(e));
            span.end();
        }
        return call;
    }
}
Also used : Span(io.opentelemetry.api.trace.Span) IPCUtil.wrapException(org.apache.hadoop.hbase.ipc.IPCUtil.wrapException) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) IOException(java.io.IOException) RemoteException(org.apache.hadoop.ipc.RemoteException) IpcClientSpanBuilder(org.apache.hadoop.hbase.client.trace.IpcClientSpanBuilder) Scope(io.opentelemetry.context.Scope) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MetricsConnection(org.apache.hadoop.hbase.client.MetricsConnection) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)

Aggregations

Span (io.opentelemetry.api.trace.Span)1 Scope (io.opentelemetry.context.Scope)1 IOException (java.io.IOException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MetricsConnection (org.apache.hadoop.hbase.client.MetricsConnection)1 IpcClientSpanBuilder (org.apache.hadoop.hbase.client.trace.IpcClientSpanBuilder)1 IPCUtil.wrapException (org.apache.hadoop.hbase.ipc.IPCUtil.wrapException)1 ClientProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)1 RemoteException (org.apache.hadoop.ipc.RemoteException)1 ServiceException (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException)1