Search in sources :

Example 1 with TimedInterruptTimeoutException

use of org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException in project GraphScope by alibaba.

the class IrStandardOpProcessor method evalOpInternal.

@Override
protected void evalOpInternal(final Context ctx, final Supplier<GremlinExecutor> gremlinExecutorSupplier, final AbstractEvalOpProcessor.BindingSupplier bindingsSupplier) {
    com.codahale.metrics.Timer.Context timerContext = evalOpTimer.time();
    RequestMessage msg = ctx.getRequestMessage();
    GremlinExecutor gremlinExecutor = gremlinExecutorSupplier.get();
    Map<String, Object> args = msg.getArgs();
    String script = (String) args.get("gremlin");
    // replace with antlr parser
    String language = AntlrToJavaScriptEngineFactory.ENGINE_NAME;
    Bindings bindings = new SimpleBindings();
    GremlinExecutor.LifeCycle lifeCycle = createLifeCycle(ctx, gremlinExecutorSupplier, bindingsSupplier);
    try {
        CompletableFuture<Object> evalFuture = gremlinExecutor.eval(script, language, bindings, lifeCycle);
        evalFuture.handle((v, t) -> {
            long elapsed = timerContext.stop();
            logger.info("query \"{}\" total execution time is {} ms", script, elapsed / 1000000.0f);
            if (t != null) {
                Optional<Throwable> possibleTemporaryException = determineIfTemporaryException(t);
                if (possibleTemporaryException.isPresent()) {
                    ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TEMPORARY).statusMessage(((Throwable) possibleTemporaryException.get()).getMessage()).statusAttributeException((Throwable) possibleTemporaryException.get()).create());
                } else if (t instanceof OpProcessorException) {
                    ctx.writeAndFlush(((OpProcessorException) t).getResponseMessage());
                } else {
                    String errorMessage;
                    if (t instanceof TimedInterruptTimeoutException) {
                        errorMessage = String.format("A timeout occurred within the script during" + " evaluation of [%s] - consider" + " increasing the limit given to" + " TimedInterruptCustomizerProvider", msg);
                        logger.warn(errorMessage);
                        ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT).statusMessage("Timeout during script evaluation" + " triggered by" + " TimedInterruptCustomizerProvider").statusAttributeException(t).create());
                    } else if (t instanceof TimeoutException) {
                        errorMessage = String.format("Script evaluation exceeded the configured" + " threshold for request [%s]", msg);
                        logger.warn(errorMessage, t);
                        ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT).statusMessage(t.getMessage()).statusAttributeException(t).create());
                    } else if (t instanceof MultipleCompilationErrorsException && t.getMessage().contains("Method too large") && ((MultipleCompilationErrorsException) t).getErrorCollector().getErrorCount() == 1) {
                        errorMessage = String.format("The Gremlin statement that was submitted" + " exceeds the maximum compilation size" + " allowed by the JVM, please split it" + " into multiple smaller statements - %s", msg);
                        logger.warn(errorMessage);
                        ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_EVALUATION).statusMessage(errorMessage).statusAttributeException(t).create());
                    } else {
                        errorMessage = t.getMessage() == null ? t.toString() : t.getMessage();
                        logger.warn(String.format("Exception processing a script on request" + " [%s].", msg), t);
                        ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_EVALUATION).statusMessage(errorMessage).statusAttributeException(t).create());
                    }
                }
            }
            return null;
        });
    } catch (RejectedExecutionException var17) {
        ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.TOO_MANY_REQUESTS).statusMessage("Rate limiting").create());
    }
}
Also used : OpProcessorException(org.apache.tinkerpop.gremlin.server.op.OpProcessorException) GremlinExecutor(org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor) Bindings(javax.script.Bindings) SimpleBindings(javax.script.SimpleBindings) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) SimpleBindings(javax.script.SimpleBindings) RequestMessage(org.apache.tinkerpop.gremlin.driver.message.RequestMessage) MultipleCompilationErrorsException(org.codehaus.groovy.control.MultipleCompilationErrorsException) TimedInterruptTimeoutException(org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException) TimedInterruptTimeoutException(org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with TimedInterruptTimeoutException

use of org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException in project GraphScope by alibaba.

the class AbstractMixedOpProcessor method evalOpInternal.

@Override
protected void evalOpInternal(Context context, Supplier<GremlinExecutor> gremlinExecutorSupplier, AbstractEvalOpProcessor.BindingSupplier bindingsSupplier) {
    final Timer.Context timerContext = evalOpTimer.time();
    final ChannelHandlerContext ctx = context.getChannelHandlerContext();
    final RequestMessage msg = context.getRequestMessage();
    final GremlinExecutor gremlinExecutor = gremlinExecutorSupplier.get();
    final Settings settings = context.getSettings();
    final Map<String, Object> args = msg.getArgs();
    final String script = (String) args.get(Tokens.ARGS_GREMLIN);
    final String language = args.containsKey(Tokens.ARGS_LANGUAGE) ? (String) args.get(Tokens.ARGS_LANGUAGE) : null;
    final Bindings bindings = new SimpleBindings();
    // sessionless requests are always transaction managed, but in-session requests are
    // configurable.
    final boolean managedTransactionsForRequest = manageTransactions ? true : (Boolean) args.getOrDefault(Tokens.ARGS_MANAGE_TRANSACTION, false);
    // timeout override
    final long seto = args.containsKey(Tokens.ARGS_EVAL_TIMEOUT) ? Long.parseLong(args.get(Tokens.ARGS_EVAL_TIMEOUT).toString()) : settings.evaluationTimeout;
    logger.info("Receive query=>" + script);
    if (StringUtils.isEmpty(script) || StringUtils.equalsIgnoreCase(script, "''")) {
        logger.info("Finish empty query query=>" + script);
        writeResultList(context, Lists.newArrayList(), ResponseStatusCode.SUCCESS);
        return;
    }
    GremlinExecutor.LifeCycle timelyLifeCycle = createTimelyLifeCycle(timerContext, gremlinExecutor, language, bindings, script, seto, managedTransactionsForRequest, msg, context, settings, bindingsSupplier, ctx);
    CompletableFuture<Object> evalFuture = gremlinExecutor.eval(script, language, bindings, timelyLifeCycle);
    evalFuture.handle((v, t) -> {
        timerContext.stop();
        if (t != null) {
            if (t instanceof RetryGremlinException) {
                queryFromGremlin(timerContext, t, seto, managedTransactionsForRequest, msg, context, settings, bindingsSupplier, ctx, gremlinExecutor, script, language, bindings);
            } else {
                String errorMessage;
                if (t instanceof TimedInterruptTimeoutException) {
                    errorMessage = String.format("A timeout occurred within the script during" + " evaluation of [%s] - consider increasing" + " the limit given to" + " TimedInterruptCustomizerProvider", msg);
                    logger.warn(errorMessage);
                    ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT).statusMessage("Timeout during script evaluation triggered" + " by TimedInterruptCustomizerProvider").create());
                } else if (t instanceof TimeoutException) {
                    errorMessage = String.format("Response evaluation exceeded the configured" + " threshold for request [%s] - %s", msg, t.getMessage());
                    logger.warn(errorMessage, t);
                    ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT).statusMessage(t.getMessage()).create());
                } else {
                    logger.warn(String.format("Exception processing a script on request [%s].", msg), t);
                    ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_EVALUATION).statusMessage(t.getMessage()).create());
                }
            }
        }
        return null;
    });
}
Also used : GremlinExecutor(org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor) RetryGremlinException(com.alibaba.maxgraph.compiler.exception.RetryGremlinException) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Bindings(javax.script.Bindings) SimpleBindings(javax.script.SimpleBindings) Timer(com.codahale.metrics.Timer) SimpleBindings(javax.script.SimpleBindings) RequestMessage(org.apache.tinkerpop.gremlin.driver.message.RequestMessage) Settings(org.apache.tinkerpop.gremlin.server.Settings) TimedInterruptTimeoutException(org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException) TimedInterruptTimeoutException(org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with TimedInterruptTimeoutException

use of org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException in project GraphScope by alibaba.

the class AbstractGraphOpProcessor method evalOpInternal.

@Override
protected void evalOpInternal(Context ctx, Supplier<GremlinExecutor> gremlinExecutorSupplier, BindingSupplier bindingsSupplier) throws OpProcessorException {
    final Timer.Context timerContext = evalOpTimer.time();
    final RequestMessage msg = ctx.getRequestMessage();
    final GremlinExecutor gremlinExecutor = gremlinExecutorSupplier.get();
    final Map<String, Object> args = msg.getArgs();
    final String script = (String) args.get(Tokens.ARGS_GREMLIN);
    logger.info("script is {}", script);
    final String language = args.containsKey(Tokens.ARGS_LANGUAGE) ? (String) args.get(Tokens.ARGS_LANGUAGE) : null;
    final Bindings bindings = new SimpleBindings();
    final GremlinExecutor.LifeCycle lifeCycle = createLifeCycle(ctx, gremlinExecutorSupplier, bindingsSupplier);
    final CompletableFuture<Object> evalFuture = gremlinExecutor.eval(script, language, bindings, lifeCycle);
    evalFuture.handle((v, t) -> {
        long elapsed = timerContext.stop();
        logger.info("query {} total execution time is {} ms", script, elapsed / 1000000.0f);
        ResponseHandlerContext rhc = new ResponseHandlerContext(ctx);
        if (t != null) {
            if (t instanceof OpProcessorException) {
                rhc.writeAndFlush(((OpProcessorException) t).getResponseMessage());
            } else if (t instanceof TimedInterruptTimeoutException) {
                // occurs when the TimedInterruptCustomizerProvider is in play
                final String errorMessage = String.format("A timeout occurred within the script during evaluation" + " of [%s] - consider increasing the limit given" + " to TimedInterruptCustomizerProvider", msg);
                logger.warn(errorMessage);
                rhc.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT).statusMessage("Timeout during script evaluation triggered by" + " TimedInterruptCustomizerProvider").statusAttributeException(t).create());
            } else if (t instanceof TimeoutException) {
                final String errorMessage = String.format("Script evaluation exceeded the configured threshold" + " for request [%s]", msg);
                logger.warn(errorMessage, t);
                rhc.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT).statusMessage(t.getMessage()).statusAttributeException(t).create());
            } else if (t instanceof SchemaNotFoundException) {
                writeResultList(ctx, Collections.EMPTY_LIST, ResponseStatusCode.SUCCESS);
            } else {
                if (t instanceof MultipleCompilationErrorsException && t.getMessage().contains("Method too large") && ((MultipleCompilationErrorsException) t).getErrorCollector().getErrorCount() == 1) {
                    final String errorMessage = String.format("The Gremlin statement that was submitted exceeds" + " the maximum compilation size allowed by the" + " JVM, please split it into multiple smaller" + " statements");
                    logger.warn(errorMessage);
                    rhc.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_SCRIPT_EVALUATION).statusMessage(errorMessage).statusAttributeException(t).create());
                } else {
                    final String errorMessage = (t.getMessage() == null) ? t.toString() : t.getMessage();
                    logger.warn(String.format("Exception processing a script on request [%s].", msg), t);
                    rhc.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_SCRIPT_EVALUATION).statusMessage(errorMessage).statusAttributeException(t).create());
                }
            }
        }
        return null;
    });
}
Also used : ResponseHandlerContext(org.apache.tinkerpop.gremlin.server.ResponseHandlerContext) OpProcessorException(org.apache.tinkerpop.gremlin.server.op.OpProcessorException) GremlinExecutor(org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor) Bindings(javax.script.Bindings) SimpleBindings(javax.script.SimpleBindings) Timer(com.codahale.metrics.Timer) SimpleBindings(javax.script.SimpleBindings) RequestMessage(org.apache.tinkerpop.gremlin.driver.message.RequestMessage) SchemaNotFoundException(com.alibaba.graphscope.gaia.store.SchemaNotFoundException) MultipleCompilationErrorsException(org.codehaus.groovy.control.MultipleCompilationErrorsException) TimedInterruptTimeoutException(org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException) TimedInterruptTimeoutException(org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

TimeoutException (java.util.concurrent.TimeoutException)3 Bindings (javax.script.Bindings)3 SimpleBindings (javax.script.SimpleBindings)3 RequestMessage (org.apache.tinkerpop.gremlin.driver.message.RequestMessage)3 GremlinExecutor (org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor)3 TimedInterruptTimeoutException (org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException)3 Timer (com.codahale.metrics.Timer)2 OpProcessorException (org.apache.tinkerpop.gremlin.server.op.OpProcessorException)2 MultipleCompilationErrorsException (org.codehaus.groovy.control.MultipleCompilationErrorsException)2 SchemaNotFoundException (com.alibaba.graphscope.gaia.store.SchemaNotFoundException)1 RetryGremlinException (com.alibaba.maxgraph.compiler.exception.RetryGremlinException)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ResponseHandlerContext (org.apache.tinkerpop.gremlin.server.ResponseHandlerContext)1 Settings (org.apache.tinkerpop.gremlin.server.Settings)1