Improper handling of TXs in JBossCache?
manik Jul 3, 2006 7:44 AMAfter a short conversation with Kevin Conner about the way we deal with 2PC transactions, I believe we have an incorrect implementation. From the email thread:
"Manik Surtani" wrote:
I have a resource, R, participating in a transaction, and registers a Synchronization S. When the transaction starts to commit, the TM calls S.beforeCompletion() which completes successfully. The TM then moves to the second phase and calls S.afterCompletion(). Now somewhere in the process of S.afterCompletion(), an exception occurs.
What would the 'correct' thing to do be at this stage:
a) initiate a rollback with tx.rollback() or tx.setRollbackOnly()?
b) throw an exception and let the TM deal with it?
I suspect it is b), but just wanted some clarification.
"Kevin Conner" wrote:
Neither is appropriate. The call to afterCompletion occurs after the transaction has finished, you no longer have a transaction context.
"Manik Surtani" wrote:
The reason why S.afterCompletion() may throw an exception is that this step involves replicating a commit call to remote caches in a cluster. At this stage, we may have a network hiccup which will cause this step to fail.
"Kevin Conner" wrote:
What you should really be doing is creating a resource that can take part in the 2PC protocol and replicate it as part of the protocol.
The other issue you will face is that calls to afterCompletion are not guaranteed to occur. If there was a failure after the intentions list had been logged then recovery would only restore the resources, not the synchronisations.
"Manik Surtani" wrote:
So are you suggesting that each instance in the cluster registers a synchronisation?
"Kevin Conner" wrote:
No, the opposite. :-)
What I am suggesting is that you use an XAResource instead of a synchronisation. This can then take part in the 2PC on the appropriate instance and, as part of the 2PC protocol, replicate the information across the cluster. It can also cause the transaction to fail should that be appropriate.