Re: Threaded Operations - Quarkus
Thank you Marc. I'm currently doing everything with a traversal,
and then doing a traversal.tx().commit()
Sounds like what you suggested is what I want, but just to be
clear:
Here's what I'm trying to do.
Thread 1/JVM1 gets a request that requires adding new vertices
and edges to the graph.
Thread 2/JVM1 gets a similar request.
Some of the vertices added in Thread 1 end up having the same
attributes/name has vertices from Thread 2, but I only want to
have one vertex if it's going to have the same attributes.
If Thread 1 adds that vertex before it does a commit, then Thread
2, when it looks up said vertex won't find it; so it will also add
it.
Code example (traversal is a GraphTraversalSource gotten from
JanusGraphFactory.traversal())
try {
correlationVertex = traversal.V().has("correlationID",
correlationID).next();
} catch (java.util.NoSuchElementException nse) {
correlationVertex = null;
}
.
.
.
if (correlationVertex == null) {
correlationVertex =
traversal.addV("correlation").property("correlationID",
correlationID).next();
correlationVertex.property("a", blah1);
correlationVertex.property("b", blah2);
}
I do similar things with edges:
try {
dataSourceToCorrelationEdge =
traversal.E().has("edgeID", edgeID).next();
} catch (NoSuchElementException nse) {
dataSourceToCorrelationEdge = null;
}
Ultimately, I'd like to have several JVMs handling these
requests; each which runs multiple threads.
I'll look at using a new transaction per call. Thank you!
-Joe
Hi Joe,
Do you mean with threadsafe transactions that requests from different client threads should be handled independently, that is in different JanusGraph Transactions?
In that case, I think you want to use a GraphTraversalSource per request like this:
g = graph.newTransaction().traversal()
Best wishes, Marc