Threaded transaction ConcurrentModificationException exception

38 views
Skip to first unread message

pavel.s...@glowbyteconsulting.com

unread,
May 19, 2016, 4:57:14 AM5/19/16
to Aurelius
Hi, I using thread pool to load graph from csv.
As first thread executes tx.commit(), it got exception:
11:43:13 ERROR com.thinkaurelius.titan.graphdb.database.StandardTitanGraph  - Could not commit transaction [1] due to exception
java
.util.ConcurrentModificationException
        at java
.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
        at java
.util.ArrayList$Itr.next(ArrayList.java:851)
        at com
.google.common.collect.Iterators$7.computeNext(Iterators.java:651)
...

I use Titan 1.0.0 + Cassandra backend. I start global threaded transaction and recreate it after each commit inside each thread, according to documentation. My code looks like this:
tx = graph.tx().createThreadedTx()  // graph.newTransaction() also does not helps here
g
= tx.traversal()
...
getOrCreate
= { id -> g.V().has("uid", id).tryNext().orElseGet{ tx.addV("uid", id).next() } }
...
loadFile
= { fname ->
 
...
 v1
= getOrCreate(id_from)
 v2
= getOrCreate(id_to)
 e
= v1.addEdge("friend", v2)

 tx
.commit();  // got exception here!
 tx
= graph.tx().createThreadedTx();
 g
= tx.traversal()
}

threadPool
= Executors.newFixedThreadPool(4)
new File("${file_path}/").listFiles().sort{ it.name }.each {
 threadPool
.submit({-> loadFile it.name } as Callable);
}
threadPool
.shutdown();
threadPool
.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);

pavel.s...@glowbyteconsulting.com

unread,
May 20, 2016, 5:18:46 AM5/20/16
to Aurelius
Any ideas?
Nay be somone have working code template for API multithread loading??
Thanks.

Daniel Kuppitz

unread,
May 20, 2016, 10:20:19 AM5/20/16
to aureliu...@googlegroups.com
What if one thread executes this line:

tx = graph.tx().createThreadedTx();

... while another thread still uses the old tx instance to add new elements?

Multi-threading is not just about sending arbitrary code snippets into thread pool. There need to be a lot more work done.
As long as you don't have proper multi-threading code, I wouldn't care about what kind of exceptions you get from Titan.

Cheers,
Daniel


--
You received this message because you are subscribed to the Google Groups "Aurelius" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aureliusgraph...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aureliusgraphs/6ad9a6b0-b924-4cc3-b22f-d076594eb28c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

pavel.s...@glowbyteconsulting.com

unread,
May 23, 2016, 5:57:00 AM5/23/16
to Aurelius
Thanks, Daniel. I removed commits from threads and add synchronous commit after all threads end (one my thread loads one part of input file). Now it works fine.
Thus, so called (in docs) "threaded transaction" is not actually threaded, but simple transaction.
Reply all
Reply to author
Forward
0 new messages