3

I got this error when I tried to delete two different relationships from a node concurrently.

{ [Error: LockClient[402733] can't wait on resource RWLock[RELATIONSHIP(201056), hash=1039491204] since => LockClient[402733] <-[:HELD_BY]- RWLock[NODE(131064), hash=949197283] <-[:WAITING_FOR]- LockClient[402732] <-[:HELD_BY]- RWLock[RELATIONSHIP(201056), hash=1039491204]] message: 'LockClient[402733] can\'t wait on resource RWLock[RELATIONSHIP(201056), hash=1039491204] since => LockClient[402733] <-[:HELD_BY]- RWLock[NODE(131064), hash=949197283] <-[:WAITING_FOR]- LockClient[402732] <-[:HELD_BY]- RWLock[RELATIONSHIP(201056), hash=1039491204]' }

Is this expected? how do I avoid this?

Krishna Shetty
  • 1,361
  • 4
  • 18
  • 39

1 Answers1

2

You can avoid this if your code uses consistent ordering of the stuff to delete, e.g. by node/relationship ids.

Stefan Armbruster
  • 39,465
  • 6
  • 87
  • 97
  • 1) match (a{id:1})-[r1:r]->(b{id:2}) delete r1; 2) match (a{id:1})-[r2:r]->(c{id:3}) delete r2. 1) and 2) can run concurrently. How do I avoid this? – Krishna Shetty Jul 16 '14 at 12:50
  • Sorry, I didn't get your answer – Krishna Shetty Jul 16 '14 at 12:52
  • by setting a property you'd grab a write lock. So doing `match (a{id:1})-[r1:r]->(b{id:2}) set a.dummyProp=1 delete r` should make sure a write lock is first grabbed on a and then r is deleted. – Stefan Armbruster Jul 16 '14 at 12:53
  • Thank you. How about trying again if we detect 'DeadlockDetectedException' as mentioned here http://stackoverflow.com/questions/20495549/how-to-avoid-deadlocks-with-neo4j ? – Krishna Shetty Jul 16 '14 at 13:33
  • That's the other solution. The original question was how to avoid it. Catching deadlockexcptions and retrying might be the least invasive solution however. – Stefan Armbruster Jul 16 '14 at 13:57
  • Thank you. I felt setting dummy property like a.dummyProp is extra overhead for each writes, trying again on deadlock exception or Transaction.acquireWriteLock() may be better. – Krishna Shetty Jul 16 '14 at 18:06