Bug #64188 MysqlXAConnection.MYSQL_ERROR_CODES_TO_XA_ERROR_CODES is missing XA error codes
Submitted: 1 Feb 2012 0:25 Modified: 14 Sep 2016 21:46
Reporter: Clement Pang Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:5.1.18 OS:Any
Assigned to: Filipe Silva CPU Architecture:Any

[1 Feb 2012 0:25] Clement Pang
Description:
Currently, the static hash map in MysqlXAConnection is populated as such:

HashMap temp = new HashMap();

temp.put(Constants.integerValueOf(1397), Constants.integerValueOf(XAException.XAER_NOTA));
temp.put(Constants.integerValueOf(1398), Constants.integerValueOf(XAException.XAER_INVAL));
temp.put(Constants.integerValueOf(1399), Constants.integerValueOf(XAException.XAER_RMFAIL));
temp.put(Constants.integerValueOf(1400), Constants.integerValueOf(XAException.XAER_OUTSIDE));
temp.put(Constants.integerValueOf(1401), Constants.integerValueOf(XAException.XAER_RMERR));
temp.put(Constants.integerValueOf(1402), Constants.integerValueOf(XAException.XA_RBROLLBACK));

MYSQL_ERROR_CODES_TO_XA_ERROR_CODES = Collections.unmodifiableMap(temp);

This is missing XA error codes that can be sent from the server as detailed in: http://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html

Specifically:

Error: 1440 SQLSTATE: XAE08 (ER_XAER_DUPID)
Error: 1613 SQLSTATE: XA106 (ER_XA_RBTIMEOUT)
Error: 1614 SQLSTATE: XA102 (ER_XA_RBDEADLOCK)

How to repeat:
Transaction managers need the XA error code to determine what action to take and right now, when there is a deadlock, they don't and report that the exception is an unknown error:

ARJUNA16045: attempted rollback of < formatId=131076, gtrid_length=29, bqual_length=28, tx_uid=0:ffff0a2c2311:983f:4f287b38:176, node_name=1, branch_uid=0:ffff0a2c2311:983f:4f287b38:179, eis_name=unknown eis name > (com.mysql.jdbc.jdbc2.optional.JDBC4MysqlXAConnection@258bd34e) failed with exception code Unknown error code:0
com.mysql.jdbc.jdbc2.optional.MysqlXAException: XA_RBDEADLOCK: Transaction branch was rolled back: deadlock was detected

Note the text "Unknown error code:0"

The correct behavior here should be error code: 102.

Suggested fix:
The hashmap needs to include:

temp.put(Constants.integerValueOf(1440), Constants.integerValueOf(XAException.XAER_DUPID));
temp.put(Constants.integerValueOf(1613), Constants.integerValueOf(XAException.XA_RBTIMEOUT));
temp.put(Constants.integerValueOf(1614), Constants.integerValueOf(XAException.XA_RBDEADLOCK));
[1 Feb 2012 3:16] Clement Pang
Same issue in 5.1.18
[2 Feb 2012 12:06] Valeriy Kravchuk
Thank you for the bug report. Verified by code review.
[14 Sep 2016 21:46] Daniel So
Posted by developer:
 
Added the following entry to the Connector/J 5.1.40 changelog:

"Added support for the error codes of two MySQL server errors, ER_XA_RBTIMEOUT and ER_XA_RBDEADLOCK."
[14 Oct 2016 15:59] Daniel So
The fix has been included in Connector/J 6.0.5. The entry for the 5.1.40
changelog has been included into the 6.0.5 changelog.