graphtitantinkerpoptinkerpop-blueprinttinkergraph

Is com.tinkerpop.blueprints.Graph object thread-safe?


I've a use case where I build a graph from data retrieved from multiple data stores. Each of those data stores has its own client library that builds the sub-graph representing that particular data stores data.

Current implementation Since, I didn't have any concurrency requirements, I build a single Graph object in the service layer and pass it to each of those client libraries and they will use the same Graph instance

New implementation - to meet the SLA

To meet the SLA, i want to pull the data from these data stores concurrently.

  1. In this scenario, can each of the client libraries build the sub-graph using the same Graph instance passed from the service layer?
  2. Or is there a better way to handle this?

EDIT

How the object being used

  1. Client sends a REST request to pull person data
  2. Person data is stored in 3 different data stores
  3. Service layer creates an instance of com.tinkerpop.blueprints.impls.tg.TinkerGraph and shares it among 3 different threads retreiving the data from 3 different store simultaneously on 3 different threads. Each thread also responsible for adding the data pulled to the shared Graph instance.

Solution

  • It depends on the Graph interface implementation. For example, if you are using TinkerGraph it makes no guarantees of thread-safety. Neo4jGraph uses a ThreadLocal variable to manage transactions which means that you can share the same Neo4jGraph instance with multiple threads without any trouble. Blueprints also allows for multi-threaded transactions via ThreadedTransactionalGraph:

    https://github.com/tinkerpop/blueprints/wiki/Graph-Transactions#threadedtransactionalgraph-and-multi-threads-for-one-transaction

    but you have to find a Graph that supports that function.