[CONJ-122] Raised -5: invalid arguments were given for the XA operation Created: 2014-11-17  Updated: 2014-12-09  Resolved: 2014-12-09

Status: Closed
Project: MariaDB Connector/J
Component/s: None
Affects Version/s: 1.1.7
Fix Version/s: 1.1.8

Type: Bug Priority: Major
Reporter: David Martin Assignee: Massimo Siani (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Environment:

OS: Unix based
Server: Tomcat 7
JVM: 1.7.0_51
External Java libraries: Atomikos 3.9.3, Hibernate 4.1.4, Spring 3.1.2


Attachments: Java Archive File mariadb-java-client-1.1.8-preview.jar    

 Description   

Hi,

we are migrating the java db connector from mysql 5.1.18 to mariadb 1.1.7
Our system depends of two different MariaDB databases and we are doing XA transaction between them. To implement JTA transactions in Java we use Atomikos (http://www.atomikos.com/Main/TransactionsEssentials).

The datasources spring configuration look as follow:

	<bean id="db1XADataSource" 
		  class="com.atomikos.jdbc.AtomikosDataSourceBean" 
		  init-method="init" 
		  destroy-method="close"
		  lazy-init="true">
		<property name="xaDataSourceClassName" value="org.mariadb.jdbc.MySQLDataSource"/>
		<property name="uniqueResourceName" value="db1XADataSource"/>    
		<property name="minPoolSize" value="${db1.jdbc.minPoolSize}" />
	    <property name="maxPoolSize" value="${db1.jdbc.maxPoolSize}" />  
	    <property name="maxIdleTime" value="${db1.jdbc.maxIdleTime}" />
	    <property name="maxLifetime" value="${db1.jdbc.maxLifetime}" /> 
		<property name="xaProperties">
	        <props>
	            <prop key="url">jdbc:mariadb://localhost:3306/db1?autoReconnect=true</prop>
	            <prop key="user">userdb1</prop>
	            <prop key="password">pwddb1</prop>
	        </props>
	    </property>
	</bean>
 
	<bean id="db2XADataSource" 
		  class="com.atomikos.jdbc.AtomikosDataSourceBean" 
		  init-method="init" 
		  destroy-method="close"
		  lazy-init="true">
	    <property name="xaDataSourceClassName" value="org.mariadb.jdbc.MySQLDataSource"/>
	    <property name="uniqueResourceName" value="db2XADataSource"/>    
	    <property name="minPoolSize" value="${db2.jdbc.minPoolSize}" />
	    <property name="maxPoolSize" value="${db2.jdbc.maxPoolSize}" />
	    <property name="maxIdleTime" value="${db2.jdbc.maxIdleTime}" />
	    <property name="maxLifetime" value="${auditlog.jdbc.maxLifetime}" />   
	    <property name="xaProperties">
	        <props>
	            <prop key="url">jdbc:mariadb://localhost:3306/db2?autoReconnect=true</prop>
	            <prop key="user">userdb2</prop>
	            <prop key="password">pwddb2</prop>
	        </props>
	    </property>
	</bean>

Trying to perform an XA transaction we have the following exception "invalid arguments were given for the XA operation":

Nov 17, 2014 10:05:47 AM com.atomikos.logging.Slf4jLogger logInfo
INFO: XAResource.start ( 61646D696E41746F6D696B6F73544D30303030313030313839:61646D696E41746F6D696B6F73544D31 , XAResource.TMJOIN ) on resource domainXADataSource represented by XAResource instance org.mariadb.jdbc.MySQLXAResource@88ee298
Nov 17, 2014 10:05:47 AM com.atomikos.logging.Slf4jLogger logWarning
WARNING: XA resource 'domainXADataSource': resume for XID '61646D696E41746F6D696B6F73544D30303030313030313839:61646D696E41746F6D696B6F73544D31' raised -5: invalid arguments were given for the XA operation
javax.transaction.xa.XAException
	at org.mariadb.jdbc.MySQLXAResource.mapXAException(MySQLXAResource.java:41)
	at org.mariadb.jdbc.MySQLXAResource.execute(MySQLXAResource.java:51)
	at org.mariadb.jdbc.MySQLXAResource.start(MySQLXAResource.java:148)
	at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:427)
	at com.atomikos.datasource.xa.session.BranchEnlistedStateHandler.<init>(BranchEnlistedStateHandler.java:59)
	at com.atomikos.datasource.xa.session.NotInBranchStateHandler.checkEnlistBeforeUse(NotInBranchStateHandler.java:64)
	at com.atomikos.datasource.xa.session.TransactionContext.checkEnlistBeforeUse(TransactionContext.java:88)
	at com.atomikos.datasource.xa.session.SessionHandleState.notifyBeforeUse(SessionHandleState.java:179)
	at com.atomikos.jdbc.AtomikosConnectionProxy.enlist(AtomikosConnectionProxy.java:223)
	at com.atomikos.jdbc.AtomikosConnectionProxy.invoke(AtomikosConnectionProxy.java:142)
....
....
....

This is a documented issue in Atomikos (http://www.atomikos.com/Documentation/KnownProblems#MySQL_does_not_support_TMJOIN) and it was solved with MySQL adding the following parameter to the URL connection string : &pinGlobalTxToPhysicalConnection=true

After migrate the java connector to MariaDB it seems that this parameter is not available for the connector being impossible to run the application.

Best regards



 Comments   
Comment by Massimo Siani (Inactive) [ 2014-12-02 ]

Hi David, could you run the XA test here please:
https://code.launchpad.net/~massimo-siani/mariadb-java-client/CONJ-122
and tell me if it reproduces the issue, thanks.

Comment by David Martin [ 2014-12-02 ]

Hi Massimo,

After downloading and running the test I have this exception trace:

java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '5' for key 'PRIMARY'
	at org.mariadb.jdbc.internal.SQLExceptionMapper.get(SQLExceptionMapper.java:132)
	at org.mariadb.jdbc.internal.SQLExceptionMapper.throwException(SQLExceptionMapper.java:106)
	at org.mariadb.jdbc.MySQLStatement.executeQueryEpilog(MySQLStatement.java:268)
	at org.mariadb.jdbc.MySQLStatement.execute(MySQLStatement.java:296)
	at org.mariadb.jdbc.MySQLStatement.execute(MySQLStatement.java:346)
	at org.mariadb.jdbc.XA.XATransactionsTest(XA.java:221)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	... 26 more

This is caused by the code which tries to create a duplicate key in the xaTransaction2 table.
Our issue occurs when Atomikos tries to join one transaction to another:

INFO: XAResource.start ( 61646D696E41746F6D696B6F73544D30303030313030313839:61646D696E41746F6D696B6F73544D31 , XAResource.TMJOIN )

When that happens, we have this exception:

WARNING: XA resource 'domainXADataSource': resume for XID '61646D696E41746F6D696B6F73544D30303030313030313839:61646D696E41746F6D696B6F73544D31' raised -5: invalid arguments were given for the XA operation
javax.transaction.xa.XAException
	at org.mariadb.jdbc.MySQLXAResource.mapXAException(MySQLXAResource.java:41)

Using MySQL J/Connector the issue is solved setting to true the pinGlobalTxToPhysicalConnection as parameter in the connection string.
The Mysql documentation said:

pinGlobalTxToPhysicalConnection

When using XAConnections, should the driver ensure that operations on a given XID are always routed to the same physical connection? This allows the XAConnection to support "XA START ... JOIN" after "XA END" has been called

Default: false

Since version: 5.0.1

Link: http://dev.mysql.com/doc/connector-j/en/connector-j-reference-configuration-properties.html

Comment by Massimo Siani (Inactive) [ 2014-12-04 ]

David, could you please test this snapshot against your code in a test environment?
Many thanks.

Comment by David Martin [ 2014-12-05 ]

Hi,

I have tested the code with the new version but we still have the same issue:

Dec 05, 2014 12:55:55 PM com.atomikos.logging.Slf4jLogger logWarning
WARNING: XA resource 'domainXADataSource': resume for XID '746F6F6C733241746F6D696B6F73544D30303030313030343630:746F6F6C733241746F6D696B6F73544D31' raised -5: invalid arguments were given for the XA operation
javax.transaction.xa.XAException
	at org.mariadb.jdbc.MySQLXAResource.mapXAException(MySQLXAResource.java:41)
	at org.mariadb.jdbc.MySQLXAResource.execute(MySQLXAResource.java:51)
	at org.mariadb.jdbc.MySQLXAResource.start(MySQLXAResource.java:151)
	at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:427)
	at com.atomikos.datasource.xa.session.BranchEnlistedStateHandler.<init>(BranchEnlistedStateHandler.java:59)
	at com.atomikos.datasource.xa.session.NotInBranchStateHandler.checkEnlistBeforeUse(NotInBranchStateHandler.java:64)
	at com.atomikos.datasource.xa.session.TransactionContext.checkEnlistBeforeUse(TransactionContext.java:88)
	at com.atomikos.datasource.xa.session.SessionHandleState.notifyBeforeUse(SessionHandleState.java:179)
	at com.atomikos.jdbc.AtomikosConnectionProxy.enlist(AtomikosConnectionProxy.java:223)
	at com.atomikos.jdbc.AtomikosConnectionProxy.invoke(AtomikosConnectionProxy.java:142)

Cheers

Comment by Massimo Siani (Inactive) [ 2014-12-05 ]

Sorry, very basic question because I didn't tell you: did you add pinGlobalTxToPhysicalConnection=true to your url?

Comment by David Martin [ 2014-12-05 ]

Good point, I didn't use the parameter. I tested again and this version solves the problem. Thanks a lot for your effort.
When do you plan release 1.1.8 version?

Cheers

Comment by Massimo Siani (Inactive) [ 2014-12-09 ]

Thanks David for reporting and testing.
I believe that 1.1.8 could be out by the end of the year, or beginning of 2015.

Generated at Thu Feb 08 03:13:20 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.