Uniqueness Constraint Being Violated, Neo4J 2.1.3 Bug?

81 views
Skip to first unread message

Saad Mufti

unread,
Sep 16, 2014, 5:15:57 PM9/16/14
to ne...@googlegroups.com
Hi,

We have a Neo4J 2.1.3 database and we have a uniqueness constraint that was created as follows:

CREATE CONSTRAINT ON (segment:SEGMENT) ASSERT segment.segmentId IS UNIQUE

When we test this from the browser, it works fine in detecting violations, e.g:

CREATE (n:SEGMENT {name : "duplicate", segmentId : 110484}) RETURN n

results in

Node 589 already exists with label SEGMENT and property "segmentId"=[110484]
Neo.ClientError.Schema.ConstraintViolation

which is fine.

We have a load tester setup with  3 machines and multiple threads per box using Cypher over REST talking to Neo4J and using the transactional endpoints to do creates similar to above (but of course many more properties relevant to our app), and always writing to the Neo4J master in an HA setup.

We can reliably reproduce in that setup multiple violations of the uniqueness constraint that are NOT caught by Neo4J, they execute without error and in the resulting db we can see multiple nodes with the SEGMENT label and the same value for the segmentId property (we are intentionally generating duplicate segmentId values for our test).

Anyone else run into the same issue? Is this a Neo4J bug?

Thanks.

-----
Saad

Michael Hunger

unread,
Sep 16, 2014, 5:29:33 PM9/16/14
to ne...@googlegroups.com
To assure uniqueness across multiple threads and a cluster (with appropriate locks, please use MERGE)

MERGE (n:SEGMENT {segmentId : 110484}) ON CREATE SET n.name = "name" , ....;


--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Hunger

unread,
Sep 16, 2014, 5:31:27 PM9/16/14
to ne...@googlegroups.com
Also I recommend that you focus writing to the master and not the slaves for higher performance.

Feel free to raise a support ticket with our Neo Technology customer account when the issue persists with MERGE

Saad Mufti

unread,
Sep 16, 2014, 5:50:25 PM9/16/14
to ne...@googlegroups.com
We're already writing to the master.

What do you mean by "with appropriate locks"? We're using Cypher over REST hitting the transactional endpoints as documented at:

http://docs.neo4j.org/chunked/stable/rest-api-transactional.html

I don't see anything documented there to allow obtaining of any kind of lock over the REST API.

We are not using MERGE, will use that and update this thread.

Thanks.

----
Saad

Michael Hunger

unread,
Sep 16, 2014, 5:57:00 PM9/16/14
to ne...@googlegroups.com
MERGE is the only cypher operation that guarantees uniqueness and also takes the necessary machine- and cluster-wide locks to assure that.

Cheers, Michael

Saad Mufti

unread,
Sep 17, 2014, 9:31:22 AM9/17/14
to ne...@googlegroups.com
I don't understand, of what use is the uniqueness constraint then if it can be violated so easily if you use the CREATE cypher command?

MERGE will not work for us because we are trying to create two logically separate nodes while ensuring that they have unique segment id's, and want the constraint to throw an error if we happen to violate the uniqueness constraint. Is the Neo4J constraint not useful for that use case?

Thanks.

----
Saad

Mattias Persson

unread,
Sep 18, 2014, 6:35:37 AM9/18/14
to Neo4j Development
I feel that MERGE or no MERGE, neo4j should always keep this constraint. So to me it absolutely feels like a bug where neo4j fails to detect the constraint violation. I'd love to try and reproduce to see where the problem is.
Mattias Persson
Neo4j Hacker at Neo Technology
Reply all
Reply to author
Forward
0 new messages