How can I see the number of rollbacks in my STM in Clojure?
Asked
Active
Viewed 474 times
3 Answers
18
You can't... unless you are willing to cheat:
(defmacro spy-dosync [& body]
`(let [retries# (atom -1)
result# (dosync
(swap! retries# inc)
~@body)]
(println "retries count:" @retries#)
result#))
and then replace your dosync by a spy-dosync.

cgrand
- 7,939
- 28
- 32
5
If you're feeling frisky, you could hack the Clojure source and rebuild (it's easy to rebuild the Clojure source). Transaction retries happen in src/jvm/clojure/lang/LockingTransaction.java in the run() method. There's a big for loop there that goes until done or RETRY_LIMIT. The value of i when the loop exits should be the retry count.

Alex Miller
- 69,183
- 25
- 122
- 167