Neo4j 3.0.6 Uniqueness constraint being violated with MERGE -
i running neo4j 3.0.6, , importing large amounts of data fresh instance multiple sources. enforce uniqueness using following constraint:
create constraint on (n:person) assert n.id unique
i import data , relationships multiple sources , multiple threads:
merge (mother:person{id: 22}) merge (father:person{id: 55}) merge (self:person{id: 128}) set self += {name: "alan"} merge (self)-[:mother]->(mother) merge (self)-[:father]->(father)
meanwhile, on thread, still on same neo4j server , bolt endpoint, i'll importing rest of data:
merge (husband:person{id: 55}) merge (self:person{id: 22}) set self += {name: "phyllis"} merge (self)-[:husband]->(husband)
merge (wife:person{id: 22}) merge (self:person{id: 55}) set self += {name: "angel"} merge (self)-[:wife]->(wife)
merge (brother:person{id: 128}) merge (self:person{id: 92}) set self += {name: "brian"} merge (self)-[:brother]->(brother) merge (self)<-[:brother]-(brother)
finally, if run constraint command again, this:
unable create constraint on ( person:person ) assert person.id unique: multiple nodes label `person` have property `id` = 55: node(708823) node(708827)
there no guarantee order records processed in. ends happening multiple records same (:person{id})
created, 1 gets populated name
data.
it appears there race condition in neo4j if 2 merge
's happen same id @ same time, both created. there way avoid race condition? there way establish necessary locks?
possible duplicate: neo4j 2.1.3 uniqueness constraint being violated, bug? create
, this google groups answer indicates create
behaves differently merge
in respect constraints.
i understand can implicit lock on node , use synchronization, think serializes processing, processing won't processed concurrently.
overall think better approach abandon processing same kind of data in multiple threads , single import on 1 thread merge :persons , set properties.
after that's imported, can process creation of relationships, understanding you'll matching instead of mergeing on :persons.
Comments
Post a Comment