Is it possible to override Neo4j lock behavior for relationships?

谁说我不能喝 提交于 2019-12-02 15:21:40

问题


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.)


回答1:


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.



来源:https://stackoverflow.com/questions/30920379/is-it-possible-to-override-neo4j-lock-behavior-for-relationships

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!