To be a last resource an XAResource (wrapper if necessary) just needs to implement LastResourceCommitOptimization (https://github.com/jbosstm/narayana/blob/master/ArjunaJTA/jta/classes/com/arjuna/ats/jta/resources/LastResourceCommitOptimisation.java) of Narayana.
To be sure its working, add your breakpoint here:
You will see we have an additional technique called commit markable resources too. This makes LRCO safer as by default it has the possibility for failure (it is described here: 11.3.2. About the LRCO Optimization for Single-phase Commit (1PC) )
Hope that helps,
Thank you Tom. Do you have any sample/quick-start code in a Spring + Tomcat + Hibernate setup that I can use as a reference ?
I don't have a complete example but some of the techniques are illustrated here:
However I would say that you won't find the LRCO example there. To make the XADS LRCO you could use the example you pointed to but manually wrap the PGXADataSource such that the getXAConnection::getXAResource that is returned implements our interface. Alternatively you could use IronJacamar (quickstart/jca-and-tomcat at master · jbosstm/quickstart · GitHub ) to get the DS as that can wrap with the right interface.
Thanks Tom, that makes sense.
Now, I'm not sure if I'm doing the right thing. Since I'm using MariaDB connector, I just modified org.mariadb.jdbc.MariaXaResource (mariadb-connector-j/MariaXaResource.java at master · MariaDB/mariadb-connector-j · GitHub to implement com.arjuna.ats.jta.resources.LastResourceCommitOptimisation instead of javax.transaction.xa.XAResource. I then get the following errors and warnings.
com.arjuna.ats.jta - ARJUNA016061: TransactionImple.enlistResource - XAResource.start returned: XAException.XAER_RMFAIL for < formatId=131077, gtrid_length=29, bqual_length=36, tx_uid=0:ffffc0a81d7b:ce00:58475d90:c, node_name=1, branch_uid=0:ffffc0a81d7b:ce00:58475d90:e, subordinatenodename=null, eis_name=0 >
Error querying database. Cause: java.sql.SQLException: Unable to enlist connection in transaction: enlistResource returns 'false'.
Sorry, my information was incomplete. The RMFAIL is because Galera likely won't take these XA directives. As you are already editing the source of Galera you could make further changes to prevent the XA calls ending up as XA directives on the driver.
Here is the IronJacamar XA wrapper for LastResources:
You would really need to make all those changes, not just change the interface.
As you can see, things like xa_start are then mapped to the local transaction begin and so forth.
An alternative is to add the LRCO/CMR facility to transactional driver if you would be able to move to using that (normal XA example over here: quickstart/spring/jta at master · jbosstm/quickstart · GitHub ). If you would like me to investigate that let me know and I will see how feasible it would be.
I link to the docs for this item:
Thanks Tom. I'm yet to try it out. I'll keep you posted if I make any progress.
Thanks for the update - good luck!
Just wondering how this went?