Updating a Property on a Highly Accessed Node

There may be a time where many user sessions attempt to update the same property on the same node. Unlikely, but possible.

This may be a 'sequence' node, where you're keeping track of an increasing identifier, a sort of autoincrement.

How can you be, almost, certain that your CYPHER statement will not be blocked by another session updating the node property at that exact time?


Assume the sequence node:
CREATE (s:Sequences {counterToIncrement: 0})

Then call the following CYPHER
MATCH (s:Sequences)
CALL apoc.atomic.add(s,'counterToIncrement',1,10)
YIELD newValue as seq
RETURN seq

This will attempt to add 1 to the sequence property 'counterToIncrement' , and will attempt up to 10 times if the property is locked, and finally the new value of 'counterToIncrement' is yielded and returned.

From a post : https://community.neo4j.com/t5/neo4j-graph-platform/integer-sequence-generator-in-neo4j-apoc/td-p/19403


 

Comments

Popular posts from this blog

Property DataType - apoc.meta.type

Stopping and Starting the Neo4j Database

NULLS in Neo4j