Creating XA Datasource in JBoss 7.1.1 for MySQL Cluster : Connection Read Only Error

我的梦境 提交于 2019-12-11 19:38:56

问题


We are configuring the XA datasource in the JBoss 7.1.1 application server for the backend clustered MySQL server (Master-Master configuration). Below are the datasource configuration:

<xa-datasource jndi-name="java:/datasoucrenew" pool-name="datasoucrenew" enabled="true" use-ccm="false">
                    <xa-datasource-property name="URL">
                        jdbc:mysql://10.2.0.35:3306,10.2.0.36:3306/test_prod?autoReconnect=true
                    </xa-datasource-property>
                    <xa-datasource-property name="password">
                        password
                    </xa-datasource-property>
                    <xa-datasource-property name="user">
                        user
                    </xa-datasource-property>
                    <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
                    <driver>mysql-connector-java-5.1.12-bin.jar</driver>
                    <xa-pool>
                        <min-pool-size>0</min-pool-size>
                        <max-pool-size>100</max-pool-size>
                        <use-strict-min>true</use-strict-min>
                        <is-same-rm-override>false</is-same-rm-override>
                        <interleaving>false</interleaving>
                        <pad-xid>false</pad-xid>
                        <wrap-xa-resource>false</wrap-xa-resource>
                    </xa-pool>
                    <security>
                        <user-name>user</user-name>
                        <password>password</password>
                    </security>
                    <validation>
                        <validate-on-match>false</validate-on-match>
                        <background-validation>false</background-validation>
                        <exception-sorter class-name="org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter"/>
                    </validation>
                    <statement>
                        <share-prepared-statements>false</share-prepared-statements>
                    </statement>
                </xa-datasource>

We are facing below issues:

  1. In DB URL jdbc:mysql://10.2.0.35:3306,10.2.0.36:3306/test_prod?autoReconnect=true, if the 10.27.40.35 server is down, then it gives below exception. But if i reverse the URL configuration to jdbc:mysql://10.2.0.36:3306,10.2.0.35:3306/test_prod?autoReconnect=true, it works fine. Can you please help me to identify whats causing this issue?

At the starting i was thinking this is an driver issue. But with same driver, when i ran the standalone application, it worked without any issues.

12:06:08,782 ERROR [stderr] (MSC service thread 1-1) com.mysql.jdbc.jdbc2.optional.MysqlXAException: **Connection is read-only. Queries leading to data modificati
on are not allowed.**
12:06:08,784 ERROR [stderr] (MSC service thread 1-1)    at com.mysql.jdbc.jdbc2.optional.MysqlXAConnection.mapXAExceptionFromSQLException(MysqlXAConnection.java
:607)
12:06:08,788 ERROR [stderr] (MSC service thread 1-1)    at com.mysql.jdbc.jdbc2.optional.MysqlXAConnection.dispatchCommand(MysqlXAConnection.java:586)
12:06:08,790 ERROR [stderr] (MSC service thread 1-1)    at com.mysql.jdbc.jdbc2.optional.MysqlXAConnection.start(MysqlXAConnection.java:526)
12:06:08,793 ERROR [stderr] (MSC service thread 1-1)    at org.jboss.jca.adapters.jdbc.xa.XAManagedConnection.start(XAManagedConnection.java:259)
12:06:08,796 ERROR [stderr] (MSC service thread 1-1)    at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.enlistResource(TransactionImple.j
ava:636)
12:06:08,799 ERROR [stderr] (MSC service thread 1-1)    at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.enlistResource(TransactionImple.j
ava:397)
12:06:08,802 ERROR [stderr] (MSC service thread 1-1)    at org.jboss.jca.core.connectionmanager.listener.TxConnectionListener$TransactionSynchronization.enlist(
TxConnectionListener.java:587)
12:06:08,806 ERROR [stderr] (MSC service thread 1-1)    at org.jboss.jca.core.connectionmanager.listener.TxConnectionListener.enlist(TxConnectionListener.java:2
64)
12:06:08,809 ERROR [stderr] (MSC service thread 1-1)    at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.managedConnectionReconnected(TxConnec
tionManagerImpl.java:467)
12:06:08,813 ERROR [stderr] (MSC service thread 1-1)    at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.reconnectManagedConnection(AbstractCon
nectionManager.java:599)
12:06:08,817 ERROR [stderr] (MSC service thread 1-1)    at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionM
anager.java:467)
12:06:08,819 ERROR [stderr] (MSC service thread 1-1)    at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:129)
12:06:08,821 ERROR [stderr] (MSC service thread 1-1)    at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceCon

Note: We are using the mysql-connector-java-5.1.12-bin.jar mysql driver as the the latest version 21 OR 24 OR 27 are giving below error:

java.lang.ClassCastException: $Proxy0 cannot be cast to com.mysql.jdbc.ConnectionImpl
Completed
    at com.mysql.jdbc.jdbc2.optional.MysqlXADataSource.wrapConnection(MysqlXADataSource.java:76)
    at com.mysql.jdbc.jdbc2.optional.MysqlXADataSource.getXAConnection(MysqlXADataSource.java:52)

Really appreciate a your answers to fix this issue.

Regards,

Manjunath


回答1:


Could you please try lo replace jdbc:mysql: with jdbc:mysql:loadbalance:. It should make the second server be able to access as read/write instead of read-only.

BR, Ilya



来源:https://stackoverflow.com/questions/20628234/creating-xa-datasource-in-jboss-7-1-1-for-mysql-cluster-connection-read-only-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!