You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2016/12/07 16:17:47 UTC

tinkerpop git commit: TraverserSet can take a backing map in its constructor -- needed for TraverserMailbox which is now backed by a TraverserSet and needs concurrency protection. Added BarrierMessage and BarrierSynchronizationMessage -- barriers now wor

Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1564 7af4f9a18 -> dbadfb935


TraverserSet can take a backing map in its constructor -- needed for TraverserMailbox which is now backed by a TraverserSet and needs concurrency protection. Added BarrierMessage and BarrierSynchronizationMessage -- barriers now work: groupCount(), group(), count(), etc. Added HaltSynchornizationMessage which enables us to know when to halt the actor system (no more thread.sleep on the system thread. TraverserMailbox is the key to this whole system -- its smart about traverser bulking and message ordering such that snyhcnornizations happen AFTER all traversers have been processed.


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

Branch: refs/heads/TINKERPOP-1564
Commit: dbadfb9356ceff8b47a669744025696cda00c91b
Parents: 7af4f9a
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Dec 7 09:17:41 2016 -0700
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Dec 7 09:17:41 2016 -0700

----------------------------------------------------------------------
 .../traversal/traverser/util/TraverserSet.java  |  7 +-
 pom.xml                                         |  1 +
 .../process/akka/MasterTraversalActor.java      | 85 +++++++++++++++++---
 .../process/akka/TinkerActorSystem.java         | 28 +++----
 .../process/akka/TraverserMailbox.java          | 35 +++++---
 .../process/akka/WorkerTraversalActor.java      | 39 ++++++---
 .../process/akka/messages/BarrierMessage.java   | 47 +++++++++++
 .../messages/BarrierSynchronizationMessage.java | 39 +++++++++
 .../messages/HaltSynchronizationMessage.java    | 26 ++++++
 .../akka/messages/SynchronizationMessage.java   | 26 ++++++
 10 files changed, 281 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dbadfb93/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/TraverserSet.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/TraverserSet.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/TraverserSet.java
index 3e3d5ea..8685784 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/TraverserSet.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/TraverserSet.java
@@ -40,13 +40,18 @@ import java.util.Spliterator;
  */
 public class TraverserSet<S> extends AbstractSet<Traverser.Admin<S>> implements Set<Traverser.Admin<S>>, Queue<Traverser.Admin<S>>, Serializable {
 
-    private final Map<Traverser.Admin<S>, Traverser.Admin<S>> map = new LinkedHashMap<>();
+    private final Map<Traverser.Admin<S>, Traverser.Admin<S>> map;
 
     public TraverserSet() {
+        this.map = new LinkedHashMap<>();
+    }
 
+    public TraverserSet(final Map<Traverser.Admin<S>, Traverser.Admin<S>> internalMap) {
+        this.map = internalMap;
     }
 
     public TraverserSet(final Traverser.Admin<S> traverser) {
+        this();
         this.map.put(traverser, traverser);
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dbadfb93/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 8199586..654cf4f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -297,6 +297,7 @@ limitations under the License.
                         <exclude>gremlin-console/bin/gremlin.sh</exclude>
                         <exclude>docs/site/home/css/**</exclude>
                         <exclude>docs/site/home/js/**</exclude>
+                        <exclude>**/src/test/resources/application.conf</exclude>
                     </excludes>
                     <licenses>
                         <license implementation="org.apache.rat.analysis.license.ApacheSoftwareLicense20"/>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dbadfb93/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/MasterTraversalActor.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/MasterTraversalActor.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/MasterTraversalActor.java
index 8e9ccf9..18e8fb3 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/MasterTraversalActor.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/MasterTraversalActor.java
@@ -26,53 +26,112 @@ import akka.actor.Props;
 import akka.dispatch.RequiresMessageQueue;
 import akka.japi.pf.ReceiveBuilder;
 import org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.TraversalVertexProgramStep;
+import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.step.Barrier;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMatrix;
+import org.apache.tinkerpop.gremlin.structure.Element;
 import org.apache.tinkerpop.gremlin.structure.Partition;
 import org.apache.tinkerpop.gremlin.structure.Partitioner;
+import org.apache.tinkerpop.gremlin.tinkergraph.process.akka.messages.BarrierMessage;
+import org.apache.tinkerpop.gremlin.tinkergraph.process.akka.messages.BarrierSynchronizationMessage;
+import org.apache.tinkerpop.gremlin.tinkergraph.process.akka.messages.HaltSynchronizationMessage;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
  */
-public final class MasterTraversalActor extends AbstractActor implements
-        RequiresMessageQueue<TraverserMailbox.TraverserSetSemantics> {
+public final class MasterTraversalActor extends AbstractActor implements RequiresMessageQueue<TraverserMailbox.TraverserSetSemantics> {
 
     private Traversal.Admin<?, ?> traversal;
+    private TraversalMatrix<?, ?> matrix;
     private final Partitioner partitioner;
     private List<ActorPath> workers;
 
+    private Map<String, Integer> responseCounter = new HashMap<>();
+
     public MasterTraversalActor(final Traversal.Admin<?, ?> traversal, final Partitioner partitioner) {
         System.out.println("master[created]: " + self().path());
         traversal.applyStrategies();
         this.traversal = ((TraversalVertexProgramStep) traversal.getStartStep()).computerTraversal.get();
+        this.matrix = new TraversalMatrix<>(this.traversal);
         this.partitioner = partitioner;
         this.initializeWorkers();
 
+        /*context().system().scheduler().schedule(
+                Duration.create(1, TimeUnit.NANOSECONDS),
+                Duration.create(1, TimeUnit.NANOSECONDS),
+                () -> self().tell(System.currentTimeMillis(), ActorRef.noSender()),
+                context().system().dispatcher());*/
+
         receive(ReceiveBuilder.
                 match(Traverser.Admin.class, traverser -> {
-                    if (traverser.isHalted())
-                        System.out.println("master[result]: " + traverser);
-                    else
-                        throw new RuntimeException("Master should only process halted traversers: " + traverser);
-
-                }).build()
-        );
+                    this.processTraverser(traverser);
+                }).
+                match(BarrierMessage.class, barrier -> {
+                    final Barrier barrierStep = ((Barrier) this.matrix.getStepById(barrier.getStepId()));
+                    barrierStep.addBarrier(barrier.getBarrier());
+                    broadcast(new BarrierSynchronizationMessage(barrierStep));
+                }).
+                match(BarrierSynchronizationMessage.class, barrierSync -> {
+                    final Integer counter = this.responseCounter.get(barrierSync.getStepId());
+                    final int newCounter = null == counter ? 1 : counter + 1;
+                    this.responseCounter.put(barrierSync.getStepId(), newCounter);
+                    if (newCounter == this.workers.size()) {
+                        final Step<?, ?> step = this.matrix.<Object, Object, Step<Object, Object>>getStepById(barrierSync.getStepId());
+                        while (step.hasNext()) {
+                            this.processTraverser(step.next());
+                        }
+                    }
+                }).
+                match(HaltSynchronizationMessage.class, haltSync -> {
+                    final Integer counter = this.responseCounter.get(Traverser.Admin.HALT);
+                    final int newCounter = null == counter ? 1 : counter + 1;
+                    this.responseCounter.put(Traverser.Admin.HALT, newCounter);
+                    if (newCounter == this.workers.size()) {
+                        context().system().terminate();
+                    }
+                }).build());
     }
 
-    public void initializeWorkers() {
+    private void initializeWorkers() {
         final List<Partition> partitions = this.partitioner.getPartitions();
         this.workers = new ArrayList<>(partitions.size());
         for (final Partition partition : partitions) {
-            final ActorRef worker = context().actorOf(Props.
-                            create(WorkerTraversalActor.class, this.traversal.clone(), partition, this.partitioner),
-                    "worker-" + partition.hashCode());
+            final ActorRef worker = context().actorOf(Props.create(WorkerTraversalActor.class, this.traversal.clone(), partition, this.partitioner), "worker-" + partition.hashCode());
             this.workers.add(worker.path());
         }
         for (final ActorPath worker : this.workers) {
             context().actorSelection(worker).tell(TinkerActorSystem.State.START, self());
         }
     }
+
+    private void broadcast(final Object message) {
+        for (final ActorPath worker : this.workers) {
+            context().actorSelection(worker).tell(message,self());
+        }
+    }
+
+    private void processTraverser(final Traverser.Admin traverser) {
+        if (traverser.isHalted()) {
+            System.out.println("master[result]: " + traverser);
+            broadcast(new HaltSynchronizationMessage());
+        } else {
+            if (traverser.get() instanceof Element) {
+                final Partition otherPartition = this.partitioner.getPartition((Element) traverser.get());
+                context().actorSelection("worker-" + otherPartition.hashCode()).tell(traverser,self());
+            } else {
+                final Step<?, ?> step = this.matrix.<Object, Object, Step<Object, Object>>getStepById(traverser.getStepId());
+                step.addStart(traverser);
+                while (step.hasNext()) {
+                    this.processTraverser(step.next());
+                }
+            }
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dbadfb93/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/TinkerActorSystem.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/TinkerActorSystem.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/TinkerActorSystem.java
index 9093612..ac21bcd 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/TinkerActorSystem.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/TinkerActorSystem.java
@@ -21,15 +21,14 @@ package org.apache.tinkerpop.gremlin.tinkergraph.process.akka;
 
 import akka.actor.ActorSystem;
 import akka.actor.Props;
-import com.typesafe.config.Config;
-import org.apache.tinkerpop.gremlin.process.traversal.P;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.structure.Column;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoIo;
 import org.apache.tinkerpop.gremlin.structure.util.HashPartitioner;
 import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
 
-import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.as;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.both;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -41,28 +40,21 @@ public final class TinkerActorSystem {
     private final ActorSystem system;
 
     public TinkerActorSystem(final Traversal.Admin<?, ?> traversal) {
-        final Config config;
-
         this.system = ActorSystem.create("traversal-" + traversal.hashCode());
-        this.system.actorOf(Props.create(MasterTraversalActor.class, traversal, new HashPartitioner(traversal.getGraph().get().partitioner(), 5)),"master");
-    }
-
-    public void close() {
-        this.system.terminate();
+        this.system.actorOf(Props.create(MasterTraversalActor.class, traversal, new HashPartitioner(traversal.getGraph().get().partitioner(), 10)), "master");
     }
 
     //////////////
 
     public static void main(String args[]) throws Exception {
         final Graph graph = TinkerGraph.open();
-        graph.io(GryoIo.build()).readGraph("data/tinkerpop-modern.kryo");
-        final Traversal.Admin<?, ?> traversal = graph.traversal().withComputer().V().match(
-                as("a").out("created").as("b"),
-                as("b").in("created").as("c"),
-                as("b").has("name", P.eq("lop"))).where("a", P.neq("c")).select("a", "b", "c").by("name").asAdmin();
-        final TinkerActorSystem system = new TinkerActorSystem(traversal);
-        Thread.sleep(1000);
-        system.close();
+        graph.io(GryoIo.build()).readGraph("data/grateful-dead.kryo");
+        /*final Traversal.Admin<?, ?> traversal = graph.traversal().withComputer().V().match(
+                as("a").out().as("b"),
+                as("b").in().as("c"),
+                as("b").has("name", P.eq("lop"))).where("a", P.neq("c")).select("a", "b", "c").by("name").asAdmin();*/
+        final Traversal.Admin<?, ?> traversal = graph.traversal().withComputer().V().repeat(both()).times(2).groupCount().select(Column.keys).unfold().valueMap().count().asAdmin();
+        new TinkerActorSystem(traversal);
     }
 
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dbadfb93/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/TraverserMailbox.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/TraverserMailbox.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/TraverserMailbox.java
index b9f693d..9d8931f 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/TraverserMailbox.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/TraverserMailbox.java
@@ -28,11 +28,13 @@ import akka.dispatch.ProducesMessageQueue;
 import com.typesafe.config.Config;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.util.TraverserSet;
+import org.apache.tinkerpop.gremlin.tinkergraph.process.akka.messages.BarrierSynchronizationMessage;
+import org.apache.tinkerpop.gremlin.tinkergraph.process.akka.messages.HaltSynchronizationMessage;
 import scala.Option;
 
 import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -40,43 +42,56 @@ import java.util.concurrent.atomic.AtomicReference;
 public class TraverserMailbox implements MailboxType, ProducesMessageQueue<TraverserMailbox.TraverserMessageQueue> {
 
     public static class TraverserMessageQueue implements MessageQueue, TraverserSetSemantics {
-        private final AtomicReference<TraverserSet<?>> traverserSet = new AtomicReference<>(new TraverserSet<>());
+        private final TraverserSet<?> traverserSet = new TraverserSet<>(new ConcurrentHashMap<>());
+        private final Queue<Envelope> barrierSyncs = new ConcurrentLinkedQueue<>();
+        private final Queue<Envelope> haltSyncs = new ConcurrentLinkedQueue<>();
         private final Queue<Envelope> queue = new ConcurrentLinkedQueue<>();
 
         // these must be implemented; queue used as example
         public void enqueue(final ActorRef receiver, final Envelope handle) {
             if (handle.message() instanceof Traverser.Admin)
-                this.traverserSet.get().add((Traverser.Admin) handle.message());
+                this.traverserSet.offer((Traverser.Admin) handle.message());
+            else if (handle.message() instanceof BarrierSynchronizationMessage)
+                this.barrierSyncs.offer(handle);
+            else if (handle.message() instanceof HaltSynchronizationMessage)
+                this.haltSyncs.offer(handle);
             else
-                queue.offer(handle);
+                this.queue.offer(handle);
         }
 
         public Envelope dequeue() {
-            return !this.queue.isEmpty() ? this.queue.poll() : new Envelope(this.traverserSet.get().poll(), ActorRef.noSender());
+            if (!this.queue.isEmpty())
+                return this.queue.poll();
+            else if (!this.traverserSet.isEmpty())
+                return new Envelope(this.traverserSet.poll(), ActorRef.noSender());
+            else if (!this.barrierSyncs.isEmpty())
+                return this.barrierSyncs.poll();
+            else
+                return this.haltSyncs.poll();
         }
 
         public int numberOfMessages() {
-            return this.queue.size() + this.traverserSet.get().size();
+            return this.queue.size() + this.traverserSet.size() + this.barrierSyncs.size() + this.haltSyncs.size();
         }
 
         public boolean hasMessages() {
-            return !this.queue.isEmpty() || !this.traverserSet.get().isEmpty();
+            return !this.queue.isEmpty() || !this.traverserSet.isEmpty() || !this.barrierSyncs.isEmpty() || !this.haltSyncs.isEmpty();
         }
 
         public void cleanUp(final ActorRef owner, final MessageQueue deadLetters) {
-            for (Envelope handle : this.queue) {
+            for (final Envelope handle : this.queue) {
                 deadLetters.enqueue(owner, handle);
             }
         }
     }
 
     // This constructor signature must exist, it will be called by Akka
-    public TraverserMailbox(ActorSystem.Settings settings, Config config) {
+    public TraverserMailbox(final ActorSystem.Settings settings, final Config config) {
         // put your initialization code here
     }
 
     // The create method is called to create the MessageQueue
-    public MessageQueue create(Option<ActorRef> owner, Option<ActorSystem> system) {
+    public MessageQueue create(final Option<ActorRef> owner, final Option<ActorSystem> system) {
         return new TraverserMessageQueue();
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dbadfb93/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/WorkerTraversalActor.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/WorkerTraversalActor.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/WorkerTraversalActor.java
index 602509b..5dad18a 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/WorkerTraversalActor.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/WorkerTraversalActor.java
@@ -20,16 +20,21 @@
 package org.apache.tinkerpop.gremlin.tinkergraph.process.akka;
 
 import akka.actor.AbstractActor;
+import akka.actor.ActorRef;
 import akka.dispatch.RequiresMessageQueue;
 import akka.japi.pf.ReceiveBuilder;
 import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.step.Barrier;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMatrix;
 import org.apache.tinkerpop.gremlin.structure.Element;
 import org.apache.tinkerpop.gremlin.structure.Partition;
 import org.apache.tinkerpop.gremlin.structure.Partitioner;
+import org.apache.tinkerpop.gremlin.tinkergraph.process.akka.messages.BarrierMessage;
+import org.apache.tinkerpop.gremlin.tinkergraph.process.akka.messages.BarrierSynchronizationMessage;
+import org.apache.tinkerpop.gremlin.tinkergraph.process.akka.messages.HaltSynchronizationMessage;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -41,6 +46,7 @@ public final class WorkerTraversalActor extends AbstractActor implements
     private final Partition partition;
     private final Partitioner partitioner;
 
+
     public WorkerTraversalActor(final Traversal.Admin<?, ?> traversal, final Partition partition, final Partitioner partitioner) {
         System.out.println("worker[created]: " + self().path());
         this.matrix = new TraversalMatrix<>(traversal);
@@ -56,23 +62,36 @@ public final class WorkerTraversalActor extends AbstractActor implements
                         this.processTraverser(step.next());
                     }
                 }).
-                match(Traverser.Admin.class, this::processTraverser).build()
+                match(BarrierSynchronizationMessage.class, barrierSync -> {
+                    final Barrier step = this.matrix.getStepById(barrierSync.getStepId());
+                    while (step.hasNextBarrier()) {
+                        sender().tell(new BarrierMessage(step), self());
+                    }
+                    sender().tell(new BarrierSynchronizationMessage(step),self());
+                }).
+                match(HaltSynchronizationMessage.class, haltSync -> {
+                    sender().tell(new HaltSynchronizationMessage(), self());
+                }).
+                match(Traverser.Admin.class, traverser -> {
+                    this.processTraverser(traverser);
+                }).build()
         );
     }
 
     private void processTraverser(final Traverser.Admin traverser) {
         if (traverser.isHalted())
-            context().actorSelection("../").tell(traverser, self());
-        else {
+            context().parent().tell(traverser, ActorRef.noSender());
+        else if (traverser.get() instanceof Element && !this.partition.contains((Element) traverser.get())) {
+            final Partition otherPartition = this.partitioner.getPartition((Element) traverser.get());
+            context().actorSelection("../worker-" + otherPartition.hashCode()).tell(traverser, self());
+        } else {
             final Step<?, ?> step = this.matrix.<Object, Object, Step<Object, Object>>getStepById(traverser.getStepId());
             step.addStart(traverser);
-            while (step.hasNext()) {
-                final Traverser.Admin<?> end = step.next();
-                if (end.get() instanceof Element && !this.partition.contains((Element) end.get())) {
-                    final Partition otherPartition = this.partitioner.getPartition((Element) end.get());
-                    context().actorSelection("../worker-" + otherPartition.hashCode()).tell(end, self());
-                } else {
-                    this.processTraverser(end);
+            if (step instanceof Barrier) {
+                context().parent().tell(new BarrierMessage((Barrier) step), self());
+            } else {
+                while (step.hasNext()) {
+                    this.processTraverser(step.next());
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dbadfb93/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/messages/BarrierMessage.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/messages/BarrierMessage.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/messages/BarrierMessage.java
new file mode 100644
index 0000000..211d227
--- /dev/null
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/messages/BarrierMessage.java
@@ -0,0 +1,47 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.tinkergraph.process.akka.messages;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Step;
+import org.apache.tinkerpop.gremlin.process.traversal.step.Barrier;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class BarrierMessage {
+
+    private final Object barrier;
+    private final String stepId;
+
+    public BarrierMessage(final Barrier barrier) {
+        this.barrier = barrier.nextBarrier();
+        this.stepId = ((Step) barrier).getId();
+    }
+
+    public Object getBarrier() {
+        return this.barrier;
+    }
+
+    public String getStepId() {
+        return this.stepId;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dbadfb93/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/messages/BarrierSynchronizationMessage.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/messages/BarrierSynchronizationMessage.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/messages/BarrierSynchronizationMessage.java
new file mode 100644
index 0000000..3e5ff14
--- /dev/null
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/messages/BarrierSynchronizationMessage.java
@@ -0,0 +1,39 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.tinkergraph.process.akka.messages;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Step;
+import org.apache.tinkerpop.gremlin.process.traversal.step.Barrier;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class BarrierSynchronizationMessage implements SynchronizationMessage {
+
+    private final String stepId;
+
+    public BarrierSynchronizationMessage(final Barrier barrier) {
+        this.stepId = ((Step) barrier).getId();
+    }
+
+    public String getStepId() {
+        return this.stepId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dbadfb93/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/messages/HaltSynchronizationMessage.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/messages/HaltSynchronizationMessage.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/messages/HaltSynchronizationMessage.java
new file mode 100644
index 0000000..b77c129
--- /dev/null
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/messages/HaltSynchronizationMessage.java
@@ -0,0 +1,26 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.tinkergraph.process.akka.messages;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class HaltSynchronizationMessage implements SynchronizationMessage {
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dbadfb93/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/messages/SynchronizationMessage.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/messages/SynchronizationMessage.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/messages/SynchronizationMessage.java
new file mode 100644
index 0000000..54e7ade
--- /dev/null
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/akka/messages/SynchronizationMessage.java
@@ -0,0 +1,26 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.tinkergraph.process.akka.messages;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public interface SynchronizationMessage {
+}