Search in sources :

Example 16 with Message

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

the class RawAsyncHBaseAdmin method coprocessorService.

@Override
public <S, R> CompletableFuture<R> coprocessorService(Function<RpcChannel, S> stubMaker, ServiceCaller<S, R> callable, ServerName serverName) {
    RegionServerCoprocessorRpcChannelImpl channel = new RegionServerCoprocessorRpcChannelImpl(this.<Message>newServerCaller().serverName(serverName));
    S stub = stubMaker.apply(channel);
    CompletableFuture<R> future = new CompletableFuture<>();
    ClientCoprocessorRpcController controller = new ClientCoprocessorRpcController();
    callable.call(stub, controller, resp -> {
        if (controller.failed()) {
            future.completeExceptionally(controller.getFailed());
        } else {
            future.complete(resp);
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) HIGH_QOS(org.apache.hadoop.hbase.HConstants.HIGH_QOS) Message(org.apache.hbase.thirdparty.com.google.protobuf.Message)

Example 17 with Message

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

the class RegionServerCoprocessorRpcChannelImpl method rpcCall.

private CompletableFuture<Message> rpcCall(MethodDescriptor method, Message request, Message responsePrototype, HBaseRpcController controller, ClientService.Interface stub) {
    CompletableFuture<Message> future = new CompletableFuture<>();
    CoprocessorServiceRequest csr = CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request);
    stub.execRegionServerService(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 {
                try {
                    future.complete(CoprocessorRpcUtils.getResponse(resp, responsePrototype));
                } catch (IOException e) {
                    future.completeExceptionally(e);
                }
            }
        }
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) CoprocessorServiceRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceRequest) Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) CoprocessorServiceResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceResponse) IOException(java.io.IOException)

Example 18 with Message

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

the class ServerRpcConnection method processRequest.

/**
 * @param buf
 *          Has the request header and the request param and optionally
 *          encoded data buffer all in this one array.
 * @throws IOException
 * @throws InterruptedException
 */
protected void processRequest(ByteBuff buf) throws IOException, InterruptedException {
    long totalRequestSize = buf.limit();
    int offset = 0;
    // Here we read in the header. We avoid having pb
    // do its default 4k allocation for CodedInputStream. We force it to use
    // backing array.
    CodedInputStream cis;
    if (buf.hasArray()) {
        cis = UnsafeByteOperations.unsafeWrap(buf.array(), 0, buf.limit()).newCodedInput();
    } else {
        cis = UnsafeByteOperations.unsafeWrap(new ByteBuffByteInput(buf, 0, buf.limit()), 0, buf.limit()).newCodedInput();
    }
    cis.enableAliasing(true);
    int headerSize = cis.readRawVarint32();
    offset = cis.getTotalBytesRead();
    Message.Builder builder = RequestHeader.newBuilder();
    ProtobufUtil.mergeFrom(builder, cis, headerSize);
    RequestHeader header = (RequestHeader) builder.build();
    offset += headerSize;
    TextMapGetter<RPCTInfo> getter = new TextMapGetter<RPCTInfo>() {

        @Override
        public Iterable<String> keys(RPCTInfo carrier) {
            return carrier.getHeadersMap().keySet();
        }

        @Override
        public String get(RPCTInfo carrier, String key) {
            return carrier.getHeadersMap().get(key);
        }
    };
    Context traceCtx = GlobalOpenTelemetry.getPropagators().getTextMapPropagator().extract(Context.current(), header.getTraceInfo(), getter);
    Span span = TraceUtil.createRemoteSpan("RpcServer.process", traceCtx);
    try (Scope scope = span.makeCurrent()) {
        int id = header.getCallId();
        if (RpcServer.LOG.isTraceEnabled()) {
            RpcServer.LOG.trace("RequestHeader " + TextFormat.shortDebugString(header) + " totalRequestSize: " + totalRequestSize + " bytes");
        }
        // total request.
        if ((totalRequestSize + this.rpcServer.callQueueSizeInBytes.sum()) > this.rpcServer.maxQueueSizeInBytes) {
            final ServerCall<?> callTooBig = createCall(id, this.service, null, null, null, null, totalRequestSize, null, 0, this.callCleanup);
            this.rpcServer.metrics.exception(RpcServer.CALL_QUEUE_TOO_BIG_EXCEPTION);
            callTooBig.setResponse(null, null, RpcServer.CALL_QUEUE_TOO_BIG_EXCEPTION, "Call queue is full on " + this.rpcServer.server.getServerName() + ", is hbase.ipc.server.max.callqueue.size too small?");
            callTooBig.sendResponseIfReady();
            return;
        }
        MethodDescriptor md = null;
        Message param = null;
        CellScanner cellScanner = null;
        try {
            if (header.hasRequestParam() && header.getRequestParam()) {
                md = this.service.getDescriptorForType().findMethodByName(header.getMethodName());
                if (md == null) {
                    throw new UnsupportedOperationException(header.getMethodName());
                }
                builder = this.service.getRequestPrototype(md).newBuilderForType();
                cis.resetSizeCounter();
                int paramSize = cis.readRawVarint32();
                offset += cis.getTotalBytesRead();
                if (builder != null) {
                    ProtobufUtil.mergeFrom(builder, cis, paramSize);
                    param = builder.build();
                }
                offset += paramSize;
            } else {
                // currently header must have request param, so we directly throw
                // exception here
                String msg = "Invalid request header: " + TextFormat.shortDebugString(header) + ", should have param set in it";
                RpcServer.LOG.warn(msg);
                throw new DoNotRetryIOException(msg);
            }
            if (header.hasCellBlockMeta()) {
                buf.position(offset);
                ByteBuff dup = buf.duplicate();
                dup.limit(offset + header.getCellBlockMeta().getLength());
                cellScanner = this.rpcServer.cellBlockBuilder.createCellScannerReusingBuffers(this.codec, this.compressionCodec, dup);
            }
        } catch (Throwable t) {
            InetSocketAddress address = this.rpcServer.getListenerAddress();
            String msg = (address != null ? address : "(channel closed)") + " is unable to read call parameter from client " + getHostAddress();
            RpcServer.LOG.warn(msg, t);
            this.rpcServer.metrics.exception(t);
            // version
            if (t instanceof LinkageError) {
                t = new DoNotRetryIOException(t);
            }
            // If the method is not present on the server, do not retry.
            if (t instanceof UnsupportedOperationException) {
                t = new DoNotRetryIOException(t);
            }
            ServerCall<?> readParamsFailedCall = createCall(id, this.service, null, null, null, null, totalRequestSize, null, 0, this.callCleanup);
            readParamsFailedCall.setResponse(null, null, t, msg + "; " + t.getMessage());
            readParamsFailedCall.sendResponseIfReady();
            return;
        }
        int timeout = 0;
        if (header.hasTimeout() && header.getTimeout() > 0) {
            timeout = Math.max(this.rpcServer.minClientRequestTimeout, header.getTimeout());
        }
        ServerCall<?> call = createCall(id, this.service, md, header, param, cellScanner, totalRequestSize, this.addr, timeout, this.callCleanup);
        if (!this.rpcServer.scheduler.dispatch(new CallRunner(this.rpcServer, call))) {
            this.rpcServer.callQueueSizeInBytes.add(-1 * call.getSize());
            this.rpcServer.metrics.exception(RpcServer.CALL_QUEUE_TOO_BIG_EXCEPTION);
            call.setResponse(null, null, RpcServer.CALL_QUEUE_TOO_BIG_EXCEPTION, "Call queue is full on " + this.rpcServer.server.getServerName() + ", too many items queued ?");
            call.sendResponseIfReady();
        }
    }
}
Also used : Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) CodedInputStream(org.apache.hbase.thirdparty.com.google.protobuf.CodedInputStream) InetSocketAddress(java.net.InetSocketAddress) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) Span(io.opentelemetry.api.trace.Span) CellScanner(org.apache.hadoop.hbase.CellScanner) RPCTInfo(org.apache.hadoop.hbase.shaded.protobuf.generated.TracingProtos.RPCTInfo) SingleByteBuff(org.apache.hadoop.hbase.nio.SingleByteBuff) ByteBuff(org.apache.hadoop.hbase.nio.ByteBuff) Context(io.opentelemetry.context.Context) TextMapGetter(io.opentelemetry.context.propagation.TextMapGetter) MethodDescriptor(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.MethodDescriptor) Scope(io.opentelemetry.context.Scope) RequestHeader(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.RequestHeader)

Example 19 with Message

use of org.apache.hbase.thirdparty.com.google.protobuf.Message 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)

Example 20 with Message

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

the class HRegionServer method execRegionServerService.

CoprocessorServiceResponse execRegionServerService(@SuppressWarnings("UnusedParameters") final RpcController controller, final CoprocessorServiceRequest serviceRequest) throws ServiceException {
    try {
        ServerRpcController serviceController = new ServerRpcController();
        CoprocessorServiceCall call = serviceRequest.getCall();
        String serviceName = call.getServiceName();
        Service service = coprocessorServiceHandlers.get(serviceName);
        if (service == null) {
            throw new UnknownProtocolException(null, "No registered coprocessor executorService found for " + serviceName);
        }
        ServiceDescriptor serviceDesc = service.getDescriptorForType();
        String methodName = call.getMethodName();
        MethodDescriptor methodDesc = serviceDesc.findMethodByName(methodName);
        if (methodDesc == null) {
            throw new UnknownProtocolException(service.getClass(), "Unknown method " + methodName + " called on executorService " + serviceName);
        }
        Message request = CoprocessorRpcUtils.getRequest(service, methodDesc, call.getRequest());
        final Message.Builder responseBuilder = service.getResponsePrototype(methodDesc).newBuilderForType();
        service.callMethod(methodDesc, serviceController, request, message -> {
            if (message != null) {
                responseBuilder.mergeFrom(message);
            }
        });
        IOException exception = CoprocessorRpcUtils.getControllerException(serviceController);
        if (exception != null) {
            throw exception;
        }
        return CoprocessorRpcUtils.getResponse(responseBuilder.build(), HConstants.EMPTY_BYTE_ARRAY);
    } catch (IOException ie) {
        throw new ServiceException(ie);
    }
}
Also used : CoprocessorServiceCall(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceCall) Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) ServiceDescriptor(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.ServiceDescriptor) LockService(org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockService) Service(org.apache.hbase.thirdparty.com.google.protobuf.Service) RegionServerStatusService(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStatusService) UnknownProtocolException(org.apache.hadoop.hbase.exceptions.UnknownProtocolException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ServerRpcController(org.apache.hadoop.hbase.ipc.ServerRpcController) MethodDescriptor(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.MethodDescriptor)

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