voila
voila

Reputation: 1666

Neo4j PHP Acquire wirte lock

Sinking in big trouble,

Well can anyone tell me , how can i acquire write lock through cypher. Note : I will use REST APIs , So my cypher would in php.

EDITED : Scenario:

I am using Neo4j REST server and PHP to access it.

Now i have created a node say 'counter-node' which generates new user id. Logic is just add 1 to previous value.

Now If two users are coming simultaneously then first user read 'counter-node' value BUT before it can update it to 1 , second user read it . Thus value in 'counter-node' is not as expected.

Any Help

Upvotes: 0

Views: 155

Answers (2)

John
John

Reputation: 10099

The popular APOC plugin for Neo4j has a selection of explicit Locking procedures that can be called via Cypher such as call apoc.lock.nodes([nodes])

Learn more at neo4j-contrib.github.io/neo4j-apoc-procedures/#_locking

Note: as far as I can tell, this functionality doesn't exist natively in Cypher so APOC is probably your best bet.

Upvotes: 1

Michal Bachman
Michal Bachman

Reputation: 2661

You don't need to acquire write locks explicitly. All nodes that you modify in a transaction are write-locked automatically.

So if you do this in your logic:

start tx
increment counter node
read the value of the counter node and set it on the user node as ID
commit tx

no two users will ever get the same ID.

Upvotes: 1

Related Questions