I'm getting a deadlock issue, and I want a way to make each query take longer so I can systematically reproduce the deadlock. Does anyone have an idea how to achieve that using Cypher? I could be either creating a temporary lock the node each time, or making a query that takes longer to execute?
我遇到了死锁问题,我希望有一种方法可以让每个查询花费更长时间,这样我就可以系统地重现死锁。有没有人知道如何使用Cypher实现这一目标?我可能要么每次都创建一个临时锁定节点,要么执行一个需要更长时间才能执行的查询?
Thanks in advance!
提前致谢!
Update:
I tried using the apoc.lock
method, and this is the query I end up with:
我尝试使用apoc.lock方法,这是我最终得到的查询:
sb.append("MERGE (user:User {id: {1}}) ON CREATE SET user.id = {1}, user.name = {2}, user.createTime = timestamp()");
sb.append(" WITH user AS user CALL apoc.lock.nodes([user])");
sb.append(" MERGE (user2:User {id: {1}}) ON MATCH SET user2.updateTime = timestamp()");
sb.append(" MERGE (session:Session {id: {3}}) ON CREATE SET session.id = {3}");
sb.append(" MERGE (user)-[:STARTED]->(session)");
sb.append(" WITH 5000 AS duration CALL apoc.util.sleep(duration)");
sb.append(" MERGE (user3:User {id: {1}}) ON MATCH SET user3.closeTime = timestamp(), user3.timeDiff = user3.closeTime - user3.createTime");
3 个解决方案
#1
2
APOC Procedures has apoc.util.sleep(), which you can call within a Cypher query to sleep for some number of milliseconds
APOC过程有apoc.util.sleep(),您可以在Cypher查询中调用它来休眠几毫秒
For example:
...
// after cypher which obtains locks
CALL apoc.util.sleep(5000) // sleep 5 seconds
APOC also has procedures for locking on nodes.
APOC还具有锁定节点的过程。
#2
0
You can increase the number of concurrent requests and/or repeat the same requests many times.
您可以多次增加并发请求的数量和/或重复相同的请求。
There are APOC procedures that help with the latter. For example, apoc.periodic.repeat will repeatedly execute the same Cypher statement until you call apoc.periodic.cancel
to cancel.
有APOC程序可以帮助后者。例如,apoc.periodic.repeat将重复执行相同的Cypher语句,直到您调用apoc.periodic.cancel取消。
#3
0
I'll add in that APOC has a run Cypher (apoc.cypher.run), So you can get a write lock on a node, and then use APOC to recursively do another write on it and that should create a deadlock.
我要补充一点,APOC有一个运行Cypher(apoc.cypher.run),所以你可以在一个节点上获得一个写锁,然后使用APOC递归地对它进行另一次写操作,这应该会造成死锁。
#1
2
APOC Procedures has apoc.util.sleep(), which you can call within a Cypher query to sleep for some number of milliseconds
APOC过程有apoc.util.sleep(),您可以在Cypher查询中调用它来休眠几毫秒
For example:
...
// after cypher which obtains locks
CALL apoc.util.sleep(5000) // sleep 5 seconds
APOC also has procedures for locking on nodes.
APOC还具有锁定节点的过程。
#2
0
You can increase the number of concurrent requests and/or repeat the same requests many times.
您可以多次增加并发请求的数量和/或重复相同的请求。
There are APOC procedures that help with the latter. For example, apoc.periodic.repeat will repeatedly execute the same Cypher statement until you call apoc.periodic.cancel
to cancel.
有APOC程序可以帮助后者。例如,apoc.periodic.repeat将重复执行相同的Cypher语句,直到您调用apoc.periodic.cancel取消。
#3
0
I'll add in that APOC has a run Cypher (apoc.cypher.run), So you can get a write lock on a node, and then use APOC to recursively do another write on it and that should create a deadlock.
我要补充一点,APOC有一个运行Cypher(apoc.cypher.run),所以你可以在一个节点上获得一个写锁,然后使用APOC递归地对它进行另一次写操作,这应该会造成死锁。