Avoiding duplicate vertex creation using unique indices
Umesh Gade <er.umeshgade@...>
To avoid a situation of duplicate vertex creation due to parallel transactions, we are using index uniqueness over property which defines uniqueness of vertex. As per doc, we need to specify lock on index and property. (https://docs.janusgraph.org/advanced-topics/eventual-consistency/)
mgmt.setConsistency(name, ConsistencyModifier.LOCK) // Ensures only one name per vertex mgmt.setConsistency(index, ConsistencyModifier.LOCK) // Ensures name uniqueness in the graph
As per observation, specifying lock only on index blocks parallel transaction commit which avoids duplicate vertex creation. We didn't see any behavior change with or without lock on property.
Can anybody help me understand the significance of lock on property i.e. name in above example?
Any example scenario to understand the meaning of "Ensures only one name per vertex" ?
I read this yesterday and thought your reasoning was sound, but at the same time it seemed unlikely it was in the ref docs for no reason. Just now, a scenario appeared to me where both locks are relevant, but actually this scenario speaks in favor of your approach! If you take a lock on both the property key and the index, in the case of parallel transactions one transaction could get the lock on the property key and the other on the index (hopefully other mechanisms prevent both transactions to fail). If you want to pursue this matter, you will have to investigate which scenarios are covered by tests in the janusgraph gitrepo and try to introduce a failing test.
I also thought about threaded transactions on a single janusgraph instance where in one transaction two threads try to add a name to the same vertex, but that scenario should be handled by the cardinality of the property.