Felix Chapman created TINKERPOP-1519:

             Summary: TinkerGraphComputer doesn't handle multiple MessageScopes 
in single iteration
                 Key: TINKERPOP-1519
                 URL: https://issues.apache.org/jira/browse/TINKERPOP-1519
             Project: TinkerPop
          Issue Type: Bug
          Components: tinkergraph
    Affects Versions: 3.1.1-incubating
         Environment: Mac OSX
            Reporter: Felix Chapman
            Priority: Minor

When executing a VertexProgram that sends messages on multiple MessageScopes in 
a single iteration, then the messages behave as if they were sent on all scopes 
within that iteration.

The problem can be resolved by using only a single MessageScope per iteration, 
but this involves increasing the number of iterations.

An example of this behaviour is below:

public class TinkerTest {

    public static void main(String[] args) throws ExecutionException, 
InterruptedException {
        TinkerGraph graph = TinkerGraph.open();
        Vertex a = graph.addVertex("a");
        Vertex b = graph.addVertex("b");
        Vertex c = graph.addVertex("c");
        a.addEdge("edge", b);
        b.addEdge("edge", c);

        // Simple graph:
        // a -> b -> c

        // Execute a traversal program that sends an incoming message of "2" 
and an outgoing message of "1" from "b"
        // then each vertex sums any received messages
        ComputerResult result = graph.compute().program(new 

        // We expect the results to be {a=2, b=0, c=1}. Instead it is {a=3, 
b=0, c=3}

class MyVertexProgram implements VertexProgram<Long> {

    private final MessageScope.Local<Long> countMessageScopeIn = 
    private final MessageScope.Local<Long> countMessageScopeOut = 

    private static final String MEMORY_KEY = "count";

    private static final Set<String> COMPUTE_KEYS = 

    public void setup(final Memory memory) {}

    public GraphComputer.Persist getPreferredPersist() {
        return GraphComputer.Persist.VERTEX_PROPERTIES;

    public Set<String> getElementComputeKeys() {
        return COMPUTE_KEYS;

    public Set<MessageScope> getMessageScopes(final Memory memory) {
        return Sets.newHashSet(countMessageScopeIn, countMessageScopeOut);

    public void execute(Vertex vertex, Messenger<Long> messenger, Memory 
memory) {
        switch (memory.getIteration()) {
            case 0:
                if (vertex.label().equals("b")) {
                    messenger.sendMessage(this.countMessageScopeIn, 2L);
                    messenger.sendMessage(this.countMessageScopeOut, 1L);
            case 1:
                long edgeCount = 
IteratorUtils.reduce(messenger.receiveMessages(), 0L, (a, b) -> a + b);
                vertex.property(MEMORY_KEY, edgeCount);

    public boolean terminate(final Memory memory) {
        return memory.getIteration() == 1;

    public GraphComputer.ResultGraph getPreferredResultGraph() {
        return GraphComputer.ResultGraph.NEW;

    public MyVertexProgram clone() {
        try {
            return (MyVertexProgram) super.clone();
        } catch (final CloneNotSupportedException e) {
            throw new RuntimeException(e);


This message was sent by Atlassian JIRA

Reply via email to