I'm using the Java API to improve performance of what was once an expensive Cypher query. I was refactoring just now and noticed that I'm calling tx.success()
, even though I'm not changing any data. Is there any performance downside to marking a transaction successful when nothing has changed or does it not matter since it knows that there's nothing to actually commit?
Asked
Active
Viewed 431 times
3

subvertallchris
- 5,282
- 2
- 25
- 43
1 Answers
6
I did dive into the Java Api too and ran immediately in a case where this was needed.
If you use nested transactions and have outer code calling your read operation that is not doing tx.success, then when the outer transaction will try to commit(tx.success()), your inner transaction(your read) will mark the tx as not having completed successfully) and the database will raise an exception.

Christophe Willemsen
- 19,399
- 2
- 29
- 36
-
Ah! That is a good point. I wish I could mark multiple answers as correct, cause I feel like we're going to get more responses to this. – subvertallchris Apr 21 '15 at 22:27
-
2Something I noticed just now when looking at the source is that when you call `tx.success()`, it fires an event that will notify anything subscribing to closed transactions. If you have any plugins that perform actions on tx completion, they'll be triggered, so that may be a reason to do or not do it, depending on your database and what's plugged into it. – subvertallchris Apr 21 '15 at 22:27