0

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 ?

alexanoid
  • 24,051
  • 54
  • 210
  • 410

2 Answers2

3

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.)

cybersam
  • 63,203
  • 6
  • 53
  • 76
  • Thanks, so it is impossible to remove the lock before the transaction ends? – alexanoid Apr 08 '18 at 08:58
  • 1
    Using neo4j's Java API, say when you are writing a plugin procedure, you can explicitly release the write [Lock](https://neo4j.com/docs/java-reference/current/javadocs/org/neo4j/graphdb/Lock.html) that you obtained when you [acquired the wire lock](https://neo4j.com/docs/java-reference/current/javadocs/org/neo4j/graphdb/Transaction.html#acquireWriteLock-org.neo4j.graphdb.PropertyContainer-). – cybersam Apr 08 '18 at 09:40
0

I don't understand what you want to do.

Neo4j is transactional, so there is a transaction isolation, and Neo4j manages locks for you.

Sometimes, it is useful to manually create a lock by setting a dummy property, for example in order to avoid deadlock.

Locks are released when you commit/rollback the transaction.

logisima
  • 7,340
  • 1
  • 18
  • 31
  • AFAIK Neo4j use read-committed isolation level, with custom lock I’d like to emulate serializable isolation level. The question is how to properly remove the lock before the transaction ends – alexanoid Apr 08 '18 at 08:57