tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [1/4] tinkerpop git commit: Initialization scripts to gremlin server won't timeout
Date Tue, 18 Jul 2017 16:46:24 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/master 751b6f53e -> a9ee01eca


Initialization scripts to gremlin server won't timeout

Prior to this change the timeout for init scripts was the same as the the timeout configured
for the server. Since init scripts might need to be long run (e.g. a long load script to init
a graph into memory) it would force the user to make their timeout setting really high. A
really high setting might be really bad though for basic request/response. Perhaps in the
future it would be better to make this a configuration but for now this change should suffice.
CTR


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/7c72e51d
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/7c72e51d
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/7c72e51d

Branch: refs/heads/master
Commit: 7c72e51dc7a27204e150232e8bba3eaa4cd91d9e
Parents: 362e772
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Tue Jul 18 12:12:54 2017 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Tue Jul 18 12:12:54 2017 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  3 ++-
 .../gremlin/groovy/engine/GremlinExecutor.java  | 27 +++++++++-----------
 .../server/util/ServerGremlinExecutor.java      |  8 +++---
 3 files changed, 19 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7c72e51d/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 52d289b..573f681 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -28,7 +28,8 @@ TinkerPop 3.2.6 (Release Date: NOT OFFICIALLY RELEASED YET)
 
 This release also includes changes from <<release-3-1-8, 3.1.8>>.
 
-* Added Gremlin.Net as an early preview.
+* Initialization scripts for Gremlin Server will not timeout.
+* Added Gremlin.Net.
 * `ProfileTest` is now less stringent about assertions which will reduce burdens on providers.
 * `GremlinExecutor` begins timeout of script evaluation at the time the script was submitted
and not from the time it began evaluation.
 * `ReferenceFactory` and `DetachedFactory` now detach elements in collections accordingly.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7c72e51d/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java
b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java
index da495e6..962f798 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutor.java
@@ -278,7 +278,7 @@ public class GremlinExecutor implements AutoCloseable {
         // override the timeout if the lifecycle has a value assigned
         final long scriptEvalTimeOut = lifeCycle.getScriptEvaluationTimeoutOverride().orElse(scriptEvaluationTimeout);
 
-        final WeakReference<CompletableFuture<Object>> evaluationFuture = new
WeakReference<>(new CompletableFuture<>());
+        final CompletableFuture<Object> evaluationFuture = new CompletableFuture<>();
         final FutureTask<Void> evalFuture = new FutureTask<>(() -> {
             try {
                 lifeCycle.getBeforeEval().orElse(beforeEval).accept(bindings);
@@ -306,36 +306,33 @@ public class GremlinExecutor implements AutoCloseable {
                 // that must raise as an exception to the caller who has the returned evaluationFuture.
in other words,
                 // if it occurs before this point, then the handle() method won't be called
again if there is an
                 // exception that ends up below trying to completeExceptionally()
-                final CompletableFuture<Object> ef = evaluationFuture.get();
-                if (ef != null) ef.complete(result);
+                evaluationFuture.complete(result);
             } catch (Throwable ex) {
                 final Throwable root = null == ex.getCause() ? ex : ExceptionUtils.getRootCause(ex);
 
                 // thread interruptions will typically come as the result of a timeout, so
in those cases,
                 // check for that situation and convert to TimeoutException
-                final CompletableFuture<Object> ef = evaluationFuture.get();
-                if (ef != null) {
-                    if (root instanceof InterruptedException) {
-                        lifeCycle.getAfterTimeout().orElse(afterTimeout).accept(bindings);
-                        ef.completeExceptionally(new TimeoutException(
-                                String.format("Script evaluation exceeded the configured
'scriptEvaluationTimeout' threshold of %s ms or evaluation was otherwise cancelled directly
for request [%s]: %s", scriptEvalTimeOut, script, root.getMessage())));
-                    } else {
-                        lifeCycle.getAfterFailure().orElse(afterFailure).accept(bindings,
root);
-                        ef.completeExceptionally(root);
-                    }
+                if (root instanceof InterruptedException) {
+                    lifeCycle.getAfterTimeout().orElse(afterTimeout).accept(bindings);
+                    evaluationFuture.completeExceptionally(new TimeoutException(
+                            String.format("Script evaluation exceeded the configured 'scriptEvaluationTimeout'
threshold of %s ms or evaluation was otherwise cancelled directly for request [%s]: %s", scriptEvalTimeOut,
script, root.getMessage())));
+                } else {
+                    lifeCycle.getAfterFailure().orElse(afterFailure).accept(bindings, root);
+                    evaluationFuture.completeExceptionally(root);
                 }
             }
 
             return null;
         });
 
+        final WeakReference<CompletableFuture<Object>> evaluationFutureRef =
new WeakReference<>(evaluationFuture);
         final Future<?> executionFuture = executorService.submit(evalFuture);
         if (scriptEvalTimeOut > 0) {
             // Schedule a timeout in the thread pool for future execution
             scheduledExecutorService.schedule(() -> {
                 if (executionFuture.cancel(true)) {
                     lifeCycle.getAfterTimeout().orElse(afterTimeout).accept(bindings);
-                    final CompletableFuture<Object> ef = evaluationFuture.get();
+                    final CompletableFuture<Object> ef = evaluationFutureRef.get();
                     if (ef != null) {
                         ef.completeExceptionally(new TimeoutException(
                                 String.format("Script evaluation exceeded the configured
'scriptEvaluationTimeout' threshold of %s ms or evaluation was otherwise cancelled directly
for request [%s]", scriptEvalTimeOut, script)));
@@ -344,7 +341,7 @@ public class GremlinExecutor implements AutoCloseable {
             }, scriptEvalTimeOut, TimeUnit.MILLISECONDS);
         }
 
-        return evaluationFuture.get();
+        return evaluationFuture;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7c72e51d/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
index 8398dbb..b878549 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
@@ -18,10 +18,8 @@
  */
 package org.apache.tinkerpop.gremlin.server.util;
 
-import com.codahale.metrics.Gauge;
 import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor;
 import org.apache.tinkerpop.gremlin.groovy.engine.ScriptEngines;
-import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
 import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
 import org.apache.tinkerpop.gremlin.server.Channelizer;
@@ -32,6 +30,7 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.script.SimpleBindings;
 import java.lang.reflect.Constructor;
 import java.util.Collections;
 import java.util.HashSet;
@@ -177,7 +176,10 @@ public class ServerGremlinExecutor<T extends ScheduledExecutorService>
{
         // runs the init scripts when the GremlinScriptEngine is created.
         settings.scriptEngines.keySet().forEach(engineName -> {
             try {
-                gremlinExecutor.eval("1+1", engineName, Collections.emptyMap()).join();
+                // use no timeout on the engine initialization - perhaps this can be a configuration
later
+                final GremlinExecutor.LifeCycle lifeCycle = GremlinExecutor.LifeCycle.build().
+                        scriptEvaluationTimeoutOverride(0L).create();
+                gremlinExecutor.eval("1+1", engineName, new SimpleBindings(Collections.emptyMap()),
lifeCycle).join();
                 registerMetrics(engineName);
                 logger.info("Initialized {} GremlinScriptEngine and registered metrics",
engineName);
             } catch (Exception ex) {


Mime
View raw message