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());
}
}
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;
});
}
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;
});
}
Aggregations