Brief summary
Using latest Titan-0.5 snapshot. Our code creates vertices in concurrent threads. We are ending up in a state where we have multiple vertices with the same key. We expect this not to occur due to our constraints.
Configuring keys with following:
PropertyKey name = management.makePropertyKey(keyName)
.dataType(String.class)
.cardinality(Cardinality.SINGLE)
.make();
TitanGraphIndex nameIndex = management.buildIndex(keyName, Vertex.class)
.indexKey(name)
.unique()
.buildCompositeIndex();
management.setConsistency(nameIndex, ConsistencyModifier.LOCK);
Full Story
We have a Titan DB configured with unique vertex property keys. When writing to the DB within concurrent threads, we find Titan persisting multiple vertices with the same key.
I've distilled the issue down to a single test file: https://gist.github.com/ubit-ee/8520304273cd2024af29 This was built against the latest from 0.5 branch.
The code spawns three threads, which are synchronized to start concurrently (as much as can be) via a countdown latch. The threads then: create vertex with key "KEY_VALUE_A" create vertex with key "KEY_VALUE_B" creates a label between the two If the threads were to run sequentially, one would expect exceptions due to duplicate keys. I've been able to force this case.
When the threads run concurrently, I would expect at least one thread to succeed and any number fail. Regardless, I expect the final state of the graph to be two vertices and a single edge between the two.
Unfortunately, when I run this, the DB is repeatedly left in a state with more that 2 vertices and edges. There are vertices with duplicate keys. The tests dumps the graph to XML. Example: https://gist.github.com/ubit-ee/d5530e4fa4b87c752294
The test code in configured for berkeleydb, but I've repeated the issue against Cassandra as well.
Questions
- Have I configured the schema correctly, such that the vertex key should be unique?
- Should I be doing anything different with transactions?
- Am I misunderstanding the expected behavior of Titan?
Janusgraph
which is based of titan and having a similar issue where I defined and index on property keyuid
with unique constraint for vertexes but am still able to create multiple vertexes with the same uid. – Amyth