Jonathan Crosmer
Jonathan Crosmer

Reputation: 786

Is it possible to override Neo4j lock behavior for relationships?

See: http://neo4j.com/docs/stable/transactions-locking.html "When creating or deleting a relationship a write lock will be taken on the specific relationship and both its nodes"

Suppose I need to create many relationships within a transaction. I don't care about locking on the nodes that are connected to those relationships. In particular, for other concurrent transactions: 1) Updating properties on those nodes does not interfere with my operation 2) Creating or removing other relationships to those nodes would not interfere with my operation

The "default locking behavior" generates a huge amount of contention and possibilities for deadlocks in some cases. For example, I have a set X of 30 nodes, and two transactions are concurrently creating new nodes that have relationships to each node in X. That requires each transaction to get a write lock on all 30 nodes in X; deadlock is a strong possibility.

The description of the behavior as "default" makes it sound like it is possible to override this behavior. If so, how can I do this?

(More background: the system normally uses Spring Data Neo4j and Cypher queries to interact with the database.)

Upvotes: 0

Views: 1526

Answers (1)

Chris Vest
Chris Vest

Reputation: 8672

It's not possible to override the locking behaviour. Neo4j used to support multiple isolation levels, so it might be that the word "default" is from that time and that the page needs an update.

In Neo4j, you can't delete a node that has relationships. I think that's why it locks the nodes when you create relationships. That it interferes with modifying properties and other relationships is unfortunate.

If you can take liberties with your graph model, you can introduce relation-nodes that the contended nodes can delegate their volatile relationships to. That way you stripe the locks at the cost of a more complicated graph.

Upvotes: 1

Related Questions