You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2019/04/26 16:40:35 UTC

[tinkerpop] 01/01: TINKERPOP-2203 Added console remote timeout to each request

This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch TINKERPOP-2203
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit 7590009fd2b4ccf47f003bbe5c88887bde6b24f1
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Fri Apr 26 11:49:24 2019 -0400

    TINKERPOP-2203 Added console remote timeout to each request
---
 CHANGELOG.asciidoc                                     |  3 ++-
 docs/src/upgrade/release-3.4.x.asciidoc                | 13 +++++++++++++
 .../gremlin/console/jsr223/DriverRemoteAcceptor.java   | 18 +++++++++++++-----
 3 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 47abc87..c221ce0 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -25,7 +25,8 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 
 This release also includes changes from <<release-3-3-7, 3.3.7>>.
 
-* Allow a `Traversal` to know what `TraversalSource` it spawned from.
+* Allowed a `Traversal` to know what `TraversalSource` it spawned from.
+* Changed `:>` in Gremlin Console to submit the client-side timeout on each request.
 
 [[release-3-4-1]]
 === TinkerPop 3.4.1 (Release Date: March 18, 2019)
diff --git a/docs/src/upgrade/release-3.4.x.asciidoc b/docs/src/upgrade/release-3.4.x.asciidoc
index bb9cf43..7f598ea 100644
--- a/docs/src/upgrade/release-3.4.x.asciidoc
+++ b/docs/src/upgrade/release-3.4.x.asciidoc
@@ -35,6 +35,19 @@ Please see the link:https://github.com/apache/tinkerpop/blob/3.4.1/CHANGELOG.asc
 
 === Upgrading for Users
 
+==== Gremlin Console Timeout
+
+The Gremlin Console timeout that is set by `:remote config timeout x` was client-side only in prior versions, which
+meant that if the console timeout was less than the server timeout the client would timeout but the server might still
+be processing the request. Similarly, a longer timeout on the console would not change the server and the timeout
+would occur sooner than expected. These discrepancies often led to confusion.
+
+As of 3.4.0, the Java Driver API allowed for timeout settings to be more easily passed per request, so the console
+was modified for this current version to pass the console timeout for each remote submission thus yielding more
+consistent and intuitive behavior.
+
+link:https://issues.apache.org/jira/browse/TINKERPOP-2203[TINKERPOP-2203]
+
 ==== Mix SPARQL and Gremlin
 
 In the initial release of `sparql-gremlin` it was only possible to execute a SPARQL query and have it translate to
diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/DriverRemoteAcceptor.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/DriverRemoteAcceptor.java
index 9a4bf56..dd0db46 100644
--- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/DriverRemoteAcceptor.java
+++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/DriverRemoteAcceptor.java
@@ -21,6 +21,7 @@ package org.apache.tinkerpop.gremlin.console.jsr223;
 import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.apache.tinkerpop.gremlin.driver.Client;
 import org.apache.tinkerpop.gremlin.driver.Cluster;
+import org.apache.tinkerpop.gremlin.driver.RequestOptions;
 import org.apache.tinkerpop.gremlin.driver.Result;
 import org.apache.tinkerpop.gremlin.driver.ResultSet;
 import org.apache.tinkerpop.gremlin.driver.exception.ResponseException;
@@ -172,7 +173,12 @@ public class DriverRemoteAcceptor implements RemoteAcceptor {
             final Optional<ResponseException> inner = findResponseException(ex);
             if (inner.isPresent()) {
                 final ResponseException responseException = inner.get();
-                if (responseException.getResponseStatusCode() == ResponseStatusCode.SERVER_ERROR_SERIALIZATION)
+                if (responseException.getResponseStatusCode() == ResponseStatusCode.SERVER_ERROR_TIMEOUT) {
+                    if (timeout > NO_TIMEOUT)
+                        throw new RemoteException(String.format("Request timed out at %s ms - increase the timeout with the :remote command", timeout));
+                    else
+                        throw new RemoteException(String.format("Request timed out at %s ms - increase the timeout with the :remote command", timeout));
+                } else if (responseException.getResponseStatusCode() == ResponseStatusCode.SERVER_ERROR_SERIALIZATION)
                     throw new RemoteException(String.format(
                             "Server could not serialize the result requested. Server error - %s. Note that the class must be serializable by the client and server for proper operation.", responseException.getMessage()),
                             responseException.getRemoteStackTrace().orElse(null));
@@ -202,10 +208,12 @@ public class DriverRemoteAcceptor implements RemoteAcceptor {
 
     private List<Result> send(final String gremlin) throws SaslException {
         try {
-            final ResultSet rs = this.currentClient.submitAsync(gremlin, aliases, Collections.emptyMap()).get();
-            return timeout > NO_TIMEOUT ? rs.all().get(timeout, TimeUnit.MILLISECONDS) : rs.all().get();
-        } catch(TimeoutException ignored) {
-            throw new IllegalStateException("Request timed out while processing - increase the timeout with the :remote command");
+            final RequestOptions.Builder options = RequestOptions.build();
+            aliases.forEach(options::addAlias);
+            if (timeout > NO_TIMEOUT)
+                options.timeout(timeout);
+
+            return this.currentClient.submit(gremlin, options.create()).all().get();
         } catch (Exception e) {
             // handle security error as-is and unwrapped
             final Optional<Throwable> throwable  = Stream.of(ExceptionUtils.getThrowables(e)).filter(t -> t instanceof SaslException).findFirst();