About relationship locks and deadlocks

6 views
Skip to first unread message

Matias Burak

unread,
Aug 4, 2016, 2:21:58 AM8/4/16
to Neo4j
Hi all,

we are getting into a deadlock scenario when we have multiple concurrent threads that are deleting/creating relationships.
I'm not sure why we are getting them but as we are updating most of the relationships to the same nodes we are getting into something like this:
We have

(a1)-[:r1]-(b1)
(a2)-[:r2]-(b2)

we are trying to update the relationship on (a1) so it's now (a1)-[]-(b2), so we delete r1 so (a1) and (b1) get locked. And the create a rel between (a1) and (b2), so these nodes are locked.
In a different thread we are trying to do the opposite, we need to update (a2) to have a rel to (b1), so we delete r2 and (a2) and (b2) get locked. And then create a rel between (a2) and (b1), so these nodes are locked.
At certain point we are getting a deadlock because both threads have the resources of the other, thread 1 has a lock to (a1) and needs (a2) and thread 2 has a lock to (a2) and needs (a1).
I don't think we have a way to sort this to avoid a deadlock.
Is there any other way?
Locking both nodes when creating/deleting a relationship doesn't make sense for us at least in this case. We are doing heaving updating on relationships and most of them have similar related nodes.
I think we should have a way to at least avoid locking nodes on certain operations.
Also, as we have multiple concurrent threads doing these kind of updates, it takes a lot of time to update relationships because these threads are trying to update relationships to the same node but it's locked so they need to wait.
I'm using neo4j v3. 

Thanks,
Matias. 
Reply all
Reply to author
Forward
0 new messages