Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-02-2020 07:56 AM
Hello!
I was wondering if I explicitly acquire a read lock then use the node, will the transaction drop the lock?
I tried running a test for this but for some reason when I tried to run more than 2 cypher queries in a transaction using neo4j sandbox, the transaction stalled on the third and didn't give me a reason.
Is the read lock on node (a: A) ever dropped during the transaction, after it is acquired in the explicit apoc.lock.read call?
def fn(tx):
tx.run("MATCH (a: A) call apoc.lock.read.nodes([a]) RETURN NULL").consume()
# POINT 1
tx.run("MATCH (a: A) RETURN a.prop").consume()
# POINT 3
tx.run("call apoc.util.sleep(10000) RETURN NULL").consume()
# POINT 4
return TRUE
with driver.session() as session:
session.read_transaction(fn)
11-04-2020 11:08 AM
Hi @dansolnik I think maybe this could help you https://neo4j.com/developer/kb/shared-vs-exclusive-transaction-locks/
11-04-2020 11:14 AM
Thank you! I have already read through that page. That's actually what helped me come up with the test case.
I was unable to run the test case on the sandbox and I do not have access to enterprise edition of neo4j.
11-04-2020 11:21 AM
Specifically, I run the following code on my computer:
from neo4j import GraphDatabase, basic_auth
def fn(tx):
tx.run("MATCH (m: E) call apoc.lock.read.nodes([a]) RETURN NULL").consume()
print("point 1")
tx.run("MATCH (m: E) RETURN m.prop").consume()
print("point 2")
tx.run("call apoc.util.sleep(30000) RETURN NULL").consume()
print("point 3")
return True
def main():
print("STARTING!")
neo4j = GraphDatabase.driver(
location,
auth=basic_auth("neo4j", password))
print("CONNECTED")
with neo4j.session() as session:
session.read_transaction(fn)
print("DONE")
main()
And then I try to use the techniques on that page to find the locks held by the process. However, it seems like the process just never runs the third part of the transaction and just gets stuck after point 2 with no active query.
hence, I was unable to answer my question.
11-04-2020 11:22 AM
ok, but now is it working?
11-04-2020 11:35 AM
I just gave it another try and it worked this time! There must have been something wrong with the sandbox I had.
The answer, for all those curious, is that the lock is held throughout the whole transaction. It is only released when the transaction is over.
11-04-2020 11:39 AM
Thank you for your help!
11-04-2020 12:01 PM
no problem, if there is anything that I could help you let me know
All the sessions of the conference are now available online