在JBoss 7.1.1 for MySQL Cluster中创建XA数据源:连接只读错误

时间:2013-12-17 07:21:52

标签: mysql spring jboss datasource xa

我们正在JBoss 7.1.1应用服务器中为后端集群MySQL服务器(Master-Master配置)配置XA数据源。以下是数据源配置:

<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>

我们面临以下问题:

  1. 在DB URL中jdbc:mysql://10.2.0.35:3306,10.2.0.36:3306 / test_prod?autoReconnect = true,如果10.27.40.35服务器关闭,则它会给出以下异常。但是,如果我将URL配置反转为jdbc:mysql://10.2.0.36:3306,10.2.0.35:3306 / test_prod?autoReconnect = true,它可以正常工作。你能否帮我确定导致这个问题的原因?
  2. 在开始时我认为这是一个驱动程序问题。但是使用相同的驱动程序,当我运行独立应用程序时,它没有任何问题。

    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
    

    注意: 我们正在使用mysql-connector-java-5.1.12-bin.jar mysql驱动程序作为最新版本21 OR 24 OR 27给出以下错误:

    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)
    

    非常感谢您解决此问题的答案。

    问候,

    Manjunath

1 个答案:

答案 0 :(得分:0)

您可以尝试用jdbc:mysql:替换jdbc:mysql:loadbalance:。它应该使第二个服务器能够以读/写方式而不是只读方式进行访问。

BR,伊利亚