Atomikos的使用过程中要注意的事

 在使用Atomikos过程中遇到的一些问题,以作记录:

MySQL does not support TMJOIN

 MySQL does not allow for joining an existing XA transaction branch, as mentioned here:http://dev.mysql.com/doc/refman/5.0/en/xa-restrictions.html - the consequence is that one transaction accessing the same MySQL multiple times can run into problems like this:

com.atomikos.datasource.ResourceException: resume for XID 192.168.162.50.tm0000100012192.168.162.50.tm1 raised -5: invalid arguments were given for the XA operation
   at com.atomikos.datasource.xa.XAResourceTransaction.resume(Unknown Source)
   at com.atomikos.jdbc.ConnectionProxy.invoke(Unknown Source)
   at $Proxy8.prepareStatement(Unknown Source)
   at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
   at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:94)
   at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
   at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2224)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
   at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:343)
   at org.hibernate.transaction.JTATransaction.commit(JTATransaction.java:135)
[...] 

A possible workaround might be to try and start TransactionsEssentials with the parametercom.atomikos.icatch.serial_jta_transactions set to false.

com.atomikos.icatch.serial_jta_transactions=false

Also, make sure to set the following property on the MySQL datasource:

 pinGlobalTxToPhysicalConnection="true"  

  以上是Atomikos官方关于Mysql bug的一些说明,解决这个问题按照官方说明,我们可以在jta.properties或者transactions.properties里面添加com.atomikos.icatch.serial_jta_transactions=false这么一段,可能我姿势不正确,没起作用。第二种方法是在Mysql的XADataSource的pinGlobalTxToPhysicalConnection设置为true,这可难办了,我使用的是druid的数据源,好像没有pinGlobalTxToPhysicalConnection这个的属性吧?苦恼了一段时间,查了一些资料都没有发现解决办法,突然灵机一动,试一下在url后缀加上这段东西,没想到真行了。

jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&pinGlobalTxToPhysicalConnection=true

MyBatis不能回滚事务?

2016-10-24 11:07:04,458 INFO  [com.atomikos.datasource.xa.XAResourceTransaction] - XAResource.end ( 31302E3232382E37352E3132352E746D30303030313030303134:31302E3232382E37352E3132352E746D31 , XAResource.TMSUCCESS ) on resource apikore represented by XAResource instance com.mysql.jdbc.jdbc2.optional.JDBC4SuspendableXAConnection@12a8ee2
2016-10-24 11:07:04,462 INFO  [com.atomikos.datasource.xa.XAResourceTransaction] - XAResource.rollback ( 31302E3232382E37352E3132352E746D30303030313030303134:31302E3232382E37352E3132352E746D31 ) on resource apikore represented by XAResource instance com.mysql.jdbc.jdbc2.optional.JDBC4SuspendableXAConnection@12a8ee2
2016-10-24 11:07:04,466 INFO  [com.atomikos.icatch.imp.CompositeTransactionImp] - rollback() done of transaction 127.0.0.1.tm0000100014

  检查一下控制台是否有着段输出,如果有,那么应该是回滚成功的。如果你断点spring的TransactionManager确定事务应经启用的情况下,出错了却没有回滚,请检查一下,事务设置是否带有rollback-for="Exception"

 <tx:method name="*" propagation="REQUIRED" rollback-for="Exception"/> 

 Connection pool exhausted - try increasing 'maxPoolSize'

错误:

[ERROR][2016-10-26 14:25:31,937][org.hibernate.engine.jdbc.spi.SqlExceptionHelper]Connection pool exhausted - try increasing 'maxPoolSize' and/or 'borrowConnectionTimeout' on the DataSourceBean.
[ERROR][2016-10-26 14:25:31,952][org.apache.struts2.dispatcher.Dispatcher]Exception occurred during processing request: Could not open connection

在AtomikosDataSourceBean配置添加如下代码:

 <property name="minPoolSize" value="5" />
 <property name="maxPoolSize" value="20" />
 <property name="borrowConnectionTimeout" value="60" />    

 Error in recovery

错误:

[ERROR][2016-11-03 10:17:30,771][com.atomikos.recovery.imp.CachedRepository]Corrupted log file - restart JVM
com.atomikos.recovery.LogReadException: java.lang.ArrayIndexOutOfBoundsException: 1
    at com.atomikos.recovery.imp.FileSystemRepository.getAllCoordinatorLogEntries(FileSystemRepository.java:139)
    at com.atomikos.recovery.imp.CachedRepository.init(CachedRepository.java:47)
    at com.atomikos.icatch.provider.imp.AssemblerImp.createCoordinatorLogEntryRepository(AssemblerImp.java:184)
    at com.atomikos.icatch.provider.imp.AssemblerImp.assembleTransactionService(AssemblerImp.java:135)
    at com.atomikos.icatch.config.Configuration.assembleSystemComponents(Configuration.java:484)
    at com.atomikos.icatch.config.Configuration.init(Configuration.java:446)
    at com.atomikos.icatch.jta.UserTransactionManager.startupTransactionService(UserTransactionManager.java:71)
    at com.atomikos.icatch.jta.UserTransactionManager.initializeTransactionManagerSingleton(UserTransactionManager.java:60)
    at com.atomikos.icatch.jta.UserTransactionManager.checkSetup(UserTransactionManager.java:52)
    at com.atomikos.icatch.jta.UserTransactionManager.init(UserTransactionManager.java:122)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
atomikos版本升级到4.0.4解决。

  后续若有发现问题,再行添加。

posted @ 2016-10-13 22:00  Gin.p  阅读(19096)  评论(0编辑  收藏  举报