I'm employing multi-threaded transactions as described by JanusGraph docs. Each of my threads contributes to building a directory tree. Before inserting a new vertex for a specific directory, each thread first checks if such a vertex already exists within the same query. Vertexes are only inserted with .orElseGet
if no existing one can be found.
Vertex vertex = graph.traversal().V()
.hasLabel(VertexLabels.DIRECTORY)
.has(PropertyKeys.PATH, directory.path())
.tryNext()
.orElseGet(() -> {
return graph.addVertex(
T.label, VertexLabels.DIRECTORY,
PropertyKeys.PATH, directory.path());
});
Technically, this should prevent duplicates assuming that all threads operate within the same transactional scope. I do however encounter duplicates. The docs don't seem to give any answers regarding this issue. Can you confirm whether multi-threaded transactions operate within the same scope?