Hello,
I'm having a locking issue and I was hoping someone could confirm what a user can assume the default locking behaviour currently is. From the documentation I understood that when merging a relationship a lock would be taken on the nodes on both sides and the relationship itself. I seem to be experiencing neo4j taking a lock on both nodes and multiple relationships on those nodes.
As a contrived example:
I have 2 nodes, Person and Book. A person has a favourite book and a most hated book
(:Person)-[:loves]-(:Book)
(:Person)-[:hates]-(:Book)
I know from my domain that no book has more than 10 relationships total so I can group those together into a single transaction, so I decide to try parallelise the relationship inserting. So I sort my relationship csv's so that they are in alphabetical order by book so all same books are together. Then I split them into batches of minumum size + however many over till a unique book appears. So now I have a group of batches that have no duplicate people across transactions and the same book will only ever appear in a single transaction.
My merge queries are simply
UNWIND $rows as row
MATCH (p:Person { uuid: row[0] })
MATCH (b:Book { isbn: row[1] })
MERGE (p)-[:loves]->(b)
UNWIND $rows as row
MATCH (p:Person { uuid: row[0] })
MATCH (b:Book { isbn: row[1] })
MERGE (p)-[:hates]->(b)
I load all the loves relationships in using all the cores on my server and it works flawlessly giving a nice speedup.
Then I try to load all the hates relationships in after and everything starts to fail. I start getting lock exceptions
org.neo4j.driver.exceptions.TransientException: ForsetiClient[5] can't acquire ExclusiveLock{owner=ForsetiClient[7]} on RELATIONSHIP(2249506), because holders of that lock are waiting for ForsetiClient[5].
Now if I look up relationship with id 2249506 it's a "loves" relationship, so I'm wondering why when I'm loading in "hates" relationships it's trying to lock a "loves" relationship?