Search in sources :

Example 1 with IpcServerSpanBuilder

use of org.apache.hadoop.hbase.server.trace.IpcServerSpanBuilder in project hbase by apache.

the class CallRunner method run.

public void run() {
    try {
        if (call.disconnectSince() >= 0) {
            if (RpcServer.LOG.isDebugEnabled()) {
                RpcServer.LOG.debug(Thread.currentThread().getName() + ": skipped " + call);
            }
            return;
        }
        call.setStartTime(EnvironmentEdgeManager.currentTime());
        if (call.getStartTime() > call.getDeadline()) {
            RpcServer.LOG.warn("Dropping timed out call: " + call);
            this.rpcServer.getMetrics().callTimedOut();
            return;
        }
        this.status.setStatus("Setting up call");
        this.status.setConnection(call.getRemoteAddress().getHostAddress(), call.getRemotePort());
        if (RpcServer.LOG.isTraceEnabled()) {
            Optional<User> remoteUser = call.getRequestUser();
            RpcServer.LOG.trace(call.toShortString() + " executing as " + (remoteUser.isPresent() ? remoteUser.get().getName() : "NULL principal"));
        }
        Throwable errorThrowable = null;
        String error = null;
        Pair<Message, CellScanner> resultPair = null;
        RpcServer.CurCall.set(call);
        Span span = new IpcServerSpanBuilder(call).build();
        try (Scope traceScope = span.makeCurrent()) {
            if (!this.rpcServer.isStarted()) {
                InetSocketAddress address = rpcServer.getListenerAddress();
                throw new ServerNotRunningYetException("Server " + (address != null ? address : "(channel closed)") + " is not running yet");
            }
            // make the call
            resultPair = this.rpcServer.call(call, this.status);
        } catch (TimeoutIOException e) {
            RpcServer.LOG.warn("Can not complete this request in time, drop it: " + call);
            TraceUtil.setError(span, e);
            return;
        } catch (Throwable e) {
            TraceUtil.setError(span, e);
            if (e instanceof ServerNotRunningYetException) {
                // If ServerNotRunningYetException, don't spew stack trace.
                if (RpcServer.LOG.isTraceEnabled()) {
                    RpcServer.LOG.trace(call.toShortString(), e);
                }
            } else {
                // Don't dump full exception.. just String version
                RpcServer.LOG.debug(call.toShortString() + ", exception=" + e);
            }
            errorThrowable = e;
            error = StringUtils.stringifyException(e);
            if (e instanceof Error) {
                throw (Error) e;
            }
        } finally {
            RpcServer.CurCall.set(null);
            if (resultPair != null) {
                this.rpcServer.addCallSize(call.getSize() * -1);
                span.setStatus(StatusCode.OK);
                sucessful = true;
            }
            span.end();
        }
        this.status.markComplete("To send response");
        // return back the RPC request read BB we can do here. It is done by now.
        call.cleanup();
        // Set the response
        Message param = resultPair != null ? resultPair.getFirst() : null;
        CellScanner cells = resultPair != null ? resultPair.getSecond() : null;
        call.setResponse(param, cells, errorThrowable, error);
        call.sendResponseIfReady();
    } catch (OutOfMemoryError e) {
        if (this.rpcServer.getErrorHandler() != null) {
            if (this.rpcServer.getErrorHandler().checkOOME(e)) {
                RpcServer.LOG.info(Thread.currentThread().getName() + ": exiting on OutOfMemoryError");
                return;
            }
        } else {
            // rethrow if no handler
            throw e;
        }
    } catch (ClosedChannelException cce) {
        InetSocketAddress address = rpcServer.getListenerAddress();
        RpcServer.LOG.warn(Thread.currentThread().getName() + ": caught a ClosedChannelException, " + "this means that the server " + (address != null ? address : "(channel closed)") + " was processing a request but the client went away. The error message was: " + cce.getMessage());
    } catch (Exception e) {
        RpcServer.LOG.warn(Thread.currentThread().getName() + ": caught: " + StringUtils.stringifyException(e));
    } finally {
        if (!sucessful) {
            this.rpcServer.addCallSize(call.getSize() * -1);
        }
        if (this.status.isRPCRunning()) {
            this.status.markComplete("Call error");
        }
        this.status.pause("Waiting for a call");
        cleanup();
    }
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) User(org.apache.hadoop.hbase.security.User) Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) InetSocketAddress(java.net.InetSocketAddress) TimeoutIOException(org.apache.hadoop.hbase.exceptions.TimeoutIOException) CellScanner(org.apache.hadoop.hbase.CellScanner) Span(io.opentelemetry.api.trace.Span) ClosedChannelException(java.nio.channels.ClosedChannelException) TimeoutIOException(org.apache.hadoop.hbase.exceptions.TimeoutIOException) CallDroppedException(org.apache.hadoop.hbase.CallDroppedException) Scope(io.opentelemetry.context.Scope) IpcServerSpanBuilder(org.apache.hadoop.hbase.server.trace.IpcServerSpanBuilder)

Aggregations

Span (io.opentelemetry.api.trace.Span)1 Scope (io.opentelemetry.context.Scope)1 InetSocketAddress (java.net.InetSocketAddress)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 CallDroppedException (org.apache.hadoop.hbase.CallDroppedException)1 CellScanner (org.apache.hadoop.hbase.CellScanner)1 TimeoutIOException (org.apache.hadoop.hbase.exceptions.TimeoutIOException)1 User (org.apache.hadoop.hbase.security.User)1 IpcServerSpanBuilder (org.apache.hadoop.hbase.server.trace.IpcServerSpanBuilder)1 Message (org.apache.hbase.thirdparty.com.google.protobuf.Message)1