Skip to main content

XA transaction optimized into 1 phase commit transaction when using the same database.

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
5 replies [Last post]
crocodilu
Offline
Joined: 2003-06-12

Hi,
I have a question about the XA transaction management. Consider this scenario: there is a XADataSource connecting to a MySQL server. There is also a JMS connection that uses a JDBC store in the same database (configured to use XA transactions). The MySQL connection parameters use the same 'resourceId' property, so that the XAResource.isSameRM() returns true for both the XADatasource and the JMS JDBC store (as described here: http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configurati...). Then there is a transaction that writes in both the XADatasource and the JMS connection.
Is it possible for Glassfish to figure out that is the same database/resource and optimize the 2 phase commit/XA transaction into a one phase commit transaction?
I know that if I set for example the JMS JDBC store to use Local transactions, the 'last resource optimization' will kick in; but will it still use the a 2 phase commit for the XADataSource? I am not sure how to interpret the documentation.
Any help is appreciated.
Thanks. Mircea.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mvatkina
Offline
Joined: 2005-04-04

If you access a database and send a JMS message, it will always be a 2 phase commit because there will be 2 resources used in such transaction.
-marina

crocodilu
Offline
Joined: 2003-06-12

Hi,
I understand that this is the default behavior, but in this case, the XA transaction actually uses just one database under the hood. I was hoping that the transaction manager somehow figures this (why else is there a XAResource.isSameRM() method ?) and uses the same underlying JDBC connection. I think I will have to do a test with a 'logXaCommands' setting on MySQL to monitor what actually happens :).
Mircea.

mvatkina
Offline
Joined: 2005-04-04

It doesn't matter - JMS is also a resource.
-marina

crocodilu
Offline
Joined: 2003-06-12

Resin already knows how to do this, see: http://www.caucho.com/resin-3.0/jms/config.xtp. I remember using it on a PostgreSQL 7.X version atht did not have XA support and It worked as I described: the XA transaction was optimized into a local transaction. I was hoping for the same kind of functionality in Glassfish.

crocodilu
Offline
Joined: 2003-06-12

I have tested and even though I use the same resourceId, Glassfish still uses XA transactions. Anyway, good to know. :)