user3743889
user3743889

Reputation: 13

Deadlock issue in neo4j while updating the relationship by multiple thread

I have two nodes called Member and Content and both are related in n:n way with relationship HAS_RECOMMENDED (Member -[:HAS_RECOMMENDED] -> Content). One member can have multiple recommended contents and one content can be recommended by multiple members.

When I am creating the graph and relationship from java using multiple threads, I am getting below error:

org.springframework.dao.ConcurrencyFailureException: Error executing Cypher "Neo.TransientError.Transaction.DeadlockDetected"; Code: Neo.TransientError.Transaction.DeadlockDetected; Description: LockClient[1604184] can't wait on resource RWLock[NODE(63575), hash=2083848996] since => LockClient[1604184] <-[:HELD_BY]- RWLock[NODE(63663), hash=1735956338] <-[:WAITING_FOR]- LockClient[1604182] <-[:HELD_BY]- RWLock[NODE(63575), hash=2083848996]; nested exception is org.neo4j.ogm.exception.CypherException: Error executing Cypher "Neo.TransientError.Transaction.DeadlockDetected"; Code: Neo.TransientError.Transaction.DeadlockDetected; Description: LockClient[1604184] can't wait on resource RWLock[NODE(63575), hash=2083848996] since => LockClient[1604184] <-[:HELD_BY]- RWLock[NODE(63663), hash=1735956338] <-[:WAITING_FOR]- LockClient[1604182] <-[:HELD_BY]- RWLock[NODE(63575), hash=2083848996]

Upvotes: 1

Views: 1286

Answers (1)

cybersam
cybersam

Reputation: 66999

When a relationship is created, its endpoint nodes are write-locked. If multiple threads attempt to create relationships involving the same set of endpoint nodes, deadlocks can occur, as you are experiencing.

If you can have each thread work on its own set of endpoint nodes (not shared by any other thread), then you should be able to avoid these kind of deadlocks.

Upvotes: 4

Related Questions