tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [1/3] tinkerpop git commit: Re-route a side-effect request to the same host that executed the traversal
Date Mon, 08 Aug 2016 18:06:50 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1278 0803fdc2d -> eb90007fa


Re-route a side-effect request to the same host that executed the traversal

Can't send the request "wherever" because side-effects are not shared in a cluster. They can
only be found on the same machine that originally executed the traversal.


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

Branch: refs/heads/TINKERPOP-1278
Commit: e313405adb597340666c25bf8d5d9f455d1733c3
Parents: e65ff9e
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Mon Aug 8 13:16:06 2016 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Mon Aug 8 13:16:06 2016 -0400

----------------------------------------------------------------------
 .../java/org/apache/tinkerpop/gremlin/driver/Client.java | 11 ++++++++++-
 .../org/apache/tinkerpop/gremlin/driver/Connection.java  |  3 ++-
 .../org/apache/tinkerpop/gremlin/driver/ResultSet.java   |  9 ++++++++-
 .../java/org/apache/tinkerpop/gremlin/driver/Tokens.java |  1 +
 .../gremlin/driver/remote/DriverRemoteTraversal.java     |  5 ++++-
 .../driver/remote/DriverRemoteTraversalSideEffects.java  | 11 ++++++++++-
 .../apache/tinkerpop/gremlin/driver/ResultSetTest.java   |  2 +-
 7 files changed, 36 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e313405a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
index 5183493..88eee18 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
@@ -26,6 +26,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -473,7 +474,15 @@ public abstract class Client {
          */
         @Override
         protected Connection chooseConnection(final RequestMessage msg) throws TimeoutException,
ConnectionException {
-            final Iterator<Host> possibleHosts = this.cluster.loadBalancingStrategy().select(msg);
+            final Iterator<Host> possibleHosts;
+            if (msg.optionalArgs(Tokens.ARGS_HOST).isPresent()) {
+                // TODO: not sure what should be done if unavailable - select new host and
re-submit traversal?
+                final Host host = (Host) msg.getArgs().get(Tokens.ARGS_HOST);
+                msg.getArgs().remove(Tokens.ARGS_HOST);
+                possibleHosts = IteratorUtils.of(host);
+            } else {
+                possibleHosts = this.cluster.loadBalancingStrategy().select(msg);
+            }
 
             // you can get no possible hosts in more than a few situations. perhaps the servers
are just all down.
             // or perhaps the client is not configured properly (disables ssl when ssl is
enabled on the server).

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e313405a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java
index 1fb77f1..92665cf 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java
@@ -230,7 +230,8 @@ final class Connection {
 
                         final ResultQueue handler = new ResultQueue(resultLinkedBlockingQueue,
readCompleted);
                         pending.put(requestMessage.getRequestId(), handler);
-                        future.complete(new ResultSet(handler, cluster.executor(), readCompleted,
requestMessage));
+                        future.complete(new ResultSet(handler, cluster.executor(), readCompleted,
+                                requestMessage, pool.host));
                     }
                 });
         channel.writeAndFlush(requestMessage, promise);

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e313405a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ResultSet.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ResultSet.java
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ResultSet.java
index ed93fa3..b9c8636 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ResultSet.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ResultSet.java
@@ -51,12 +51,15 @@ public final class ResultSet implements Iterable<Result> {
     private final ResultQueue resultQueue;
     private final ExecutorService executor;
     private final RequestMessage originalRequestMessage;
+    private final Host host;
 
     private final CompletableFuture<Void> readCompleted;
 
     public ResultSet(final ResultQueue resultQueue, final ExecutorService executor,
-                     final CompletableFuture<Void> readCompleted, final RequestMessage
originalRequestMessage) {
+                     final CompletableFuture<Void> readCompleted, final RequestMessage
originalRequestMessage,
+                     final Host host) {
         this.executor = executor;
+        this.host = host;
         this.resultQueue = resultQueue;
         this.readCompleted = readCompleted;
         this.originalRequestMessage = originalRequestMessage;
@@ -66,6 +69,10 @@ public final class ResultSet implements Iterable<Result> {
         return originalRequestMessage;
     }
 
+    public Host getHost() {
+        return host;
+    }
+
     /**
      * Determines if all items have been returned to the client.
      */

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e313405a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Tokens.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Tokens.java
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Tokens.java
index 5542f60..acdb2cb 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Tokens.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Tokens.java
@@ -73,6 +73,7 @@ public final class Tokens {
     public static final String ARGS_GREMLIN = "gremlin";
     public static final String ARGS_LANGUAGE = "language";
     public static final String ARGS_SCRIPT_EVAL_TIMEOUT = "scriptEvaluationTimeout";
+    public static final String ARGS_HOST = "host";
     public static final String ARGS_SESSION = "session";
     public static final String ARGS_MANAGE_TRANSACTION = "manageTransaction";
     public static final String ARGS_SASL = "sasl";

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e313405a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversal.java
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversal.java
index 88661cf..71abc77 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversal.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversal.java
@@ -59,7 +59,10 @@ public class DriverRemoteTraversal<S, E> extends AbstractRemoteTraversal<S,
E> {
             this.traversers = new TraverserIterator<>(rs.iterator());
         }
 
-        this.sideEffects = new DriverRemoteTraversalSideEffects(client, rs.getOriginalRequestMessage().getRequestId());
+        this.sideEffects = new DriverRemoteTraversalSideEffects(
+                client,
+                rs.getOriginalRequestMessage().getRequestId(),
+                rs.getHost());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e313405a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversalSideEffects.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversalSideEffects.java
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversalSideEffects.java
index c3c75f7..01c5c16 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversalSideEffects.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/remote/DriverRemoteTraversalSideEffects.java
@@ -19,6 +19,7 @@
 package org.apache.tinkerpop.gremlin.driver.remote;
 
 import org.apache.tinkerpop.gremlin.driver.Client;
+import org.apache.tinkerpop.gremlin.driver.Host;
 import org.apache.tinkerpop.gremlin.driver.Result;
 import org.apache.tinkerpop.gremlin.driver.Tokens;
 import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
@@ -38,20 +39,25 @@ public class DriverRemoteTraversalSideEffects extends AbstractRemoteTraversalSid
     private final Client client;
     private Set<String> keys = null;
     private final UUID serverSideEffect;
+    private final Host host;
 
     private final Map<String, Object> sideEffects = new HashMap<>();
 
-    public DriverRemoteTraversalSideEffects(final Client client, final UUID serverSideEffect)
{
+    public DriverRemoteTraversalSideEffects(final Client client, final UUID serverSideEffect,
final Host host) {
         this.client = client;
         this.serverSideEffect = serverSideEffect;
+        this.host = host;
     }
 
     @Override
     public <V> V get(final String key) throws IllegalArgumentException {
         if (!sideEffects.containsKey(key)) {
+            // specify the ARGS_HOST so that the LoadBalancingStrategy is subverted and the
connection is forced
+            // from the specified host (i.e. the host from the previous request as that host
will hold the side-effects)
             final RequestMessage msg = RequestMessage.build(Tokens.OPS_GATHER)
                     .addArg(Tokens.ARGS_SIDE_EFFECT, serverSideEffect)
                     .addArg(Tokens.ARGS_SIDE_EFFECT_KEY, key)
+                    .addArg(Tokens.ARGS_HOST, host)
                     .processor("traversal").create();
             try {
                 final Result result = client.submitAsync(msg).get().one();
@@ -67,8 +73,11 @@ public class DriverRemoteTraversalSideEffects extends AbstractRemoteTraversalSid
     @Override
     public Set<String> keys() {
         if (null == keys) {
+            // specify the ARGS_HOST so that the LoadBalancingStrategy is subverted and the
connection is forced
+            // from the specified host (i.e. the host from the previous request as that host
will hold the side-effects)
             final RequestMessage msg = RequestMessage.build(Tokens.OPS_KEYS)
                     .addArg(Tokens.ARGS_SIDE_EFFECT, serverSideEffect)
+                    .addArg(Tokens.ARGS_HOST, host)
                     .processor("traversal").create();
             try {
                 keys = client.submitAsync(msg).get().all().get().stream().map(r -> r.getString()).collect(Collectors.toSet());

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e313405a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ResultSetTest.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ResultSetTest.java
b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ResultSetTest.java
index 768ecc1..f33168d 100644
--- a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ResultSetTest.java
+++ b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ResultSetTest.java
@@ -45,7 +45,7 @@ public class ResultSetTest extends AbstractResultQueueTest {
 
     @Before
     public void setupThis() {
-        resultSet = new ResultSet(resultQueue, pool, readCompleted, RequestMessage.build("traversal").create());
+        resultSet = new ResultSet(resultQueue, pool, readCompleted, RequestMessage.build("traversal").create(),
null);
     }
 
     @Test


Mime
View raw message