2

I am getting very strange behaviour when trying to multithread read from a tinkergraph. I have the following situation:

Graph graph = TinkerGraph.open();
Set<Vertex> verticesAdded = randomGraph(graph);

verticesAdded is a set of vertices which I added during the randomGraph(graph) process. Once I have this list I check an internal property of this vertex and depending on that property I pass the vertex to a thread for some additional work. The process I follow is roughly:

public class ValidateVerticies(){
    private Set<Vertex> vertices;
    private ExecutorService executor;
    public ValidateVerticies(Set<Vertex> verticesAdded){
        vertices = verticesAdded;
        executor = Executors.newSingleThreadExecutor(); //Single just for testing purposes
    }

    public validate(){
        for(Vertex vertex: vertices){
            String prop = vertex.property("type");
            if(type.equals("1"))
                executor.submit(() -> validateRule1(vertex))
            else if(type.equals("2"))
                executor.submit(() -> validateRule2(vertex))
            else if(type.equals("n"))
                executor.submit(() -> validateRule3(vertex))
            ...
            else if(type.equals("n"))
                executor.submit(() -> validateRulen(vertex))
        }
    }
}

The above code works when it is entirely Single Threaded but once I introduced the thread pool I am getting a strange variety of errors. Including:

  1. The vertex property "type" not existing.
  2. java.lang.IndexOutOfBoundsException: Index: 0, Size: -1 when trying to access certain vertex properties.
  3. Validation rules failing when originally they passed.

Is there something subtle when doing multithreaded reads from tinkergraph ?

Edit:

I will try to simplify the problem: The following works:

public class ValidateVerticies(){
    private Set<Vertex> vertices;
    public ValidateVerticies(Set<Vertex> verticesAdded){
        vertices = verticesAdded;
    }

    public validate(){
        for(Vertex vertex: vertices){
            String prop = vertex.property("type");
            if(type.equals("1"))
                validateRule1(vertex);
            ...
            else if(type.equals("n"))
                validateRulen(vertex);
        }
    }
}

While the multithreaded version above fails with TinkerGraph (same applies to Titan which supports transactions) returns inconsistent results when reading from the graph.

Filipe Teixeira
  • 3,565
  • 1
  • 25
  • 45
  • Your code snippets don't make it clear where your transaction boundaries are, particularly where you commit your transactions. Could you please add the info? – Ralf Jan 26 '16 at 10:34
  • TinkerGraph doesn't support transactions. While TinkerGraph is not officially "thread safe" I'm semi-surprised that you would see these problems with TinkerGraph with the way you are using it. I think more information is required as jason alluded to below. – stephen mallette Jan 26 '16 at 10:49
  • I have edited my example. I should highlight that the issues appear when reading from the graph in different threads. I don't even get to the `commit` statement. – Filipe Teixeira Jan 27 '16 at 08:55

1 Answers1

0

Give this a try. Replace

String prop = vertex.property("type");

with this

String type = vertex.value("type");

The former returns a VertexProperty while the latter returns the value of the VertexProperty, which is what I think you're looking for.

As for your #2 and #3 bullets, you'll need to supply more details.

Jason Plurad
  • 6,682
  • 2
  • 18
  • 37
  • That change does not resolve the problem. Everything works singled threaded but when I add the Threadpool then these problems appear. – Filipe Teixeira Jan 22 '16 at 17:14