Search code examples
neo4jcyphertransaction-isolation

Neo4j acquire/release the write lock - true/false vs remove


In Neo4j in order to simulate the SERIALIZABLE transaction isolation level I need to explicitly set a dummy property, for example:

SET n._lock_ = true

But how to properly release the lock, do I need to SET n._lock_ = false or to completely remove it via REMOVE n._lock_ query ?


Solution

  • You are using the documented default locking behavior. According to the documentation, the write lock is "released when the transaction finishes".

    Therefore, once you set the write lock, it is not released until your Cypher query (and transaction) finishes.

    The reason you want to include a REMOVE n._lock_ clause before ending your query is so that you make sure the _lock_ property, which is intended as a temporary hack, is no longer there after the query ends. (But the removal of that property is not responsible for the release the write lock.)