带有标识符的 Atomikos 错误准备事务 "transaction id" 不存在

Atomikos error prepared transaction "transaction id" with identifier does not exist

我有 spring 启动应用程序,使用 Atomikos 作为事务管理器,我看到了这个日志:

ERROR: prepared transaction with identifier "1096044365_MTcyLjE3LjAuMy50bTAwNDAyMDAwMDE=_MTcyLjE3LjAuMy50bTQwMg==" does not exist

连续打印。

阅读 Atomikos 文档后,我了解到 Atomikos 有一些崩溃恢复机制,我遵循了这个 http://fogbugz.atomikos.com/default4343.html?community.6.1918.14 但它没有解决我的问题。

我的问题是:为什么 Atomikos 会尝试永远清理交易?当没有机会让它进入提交状态时。

下面是堆栈跟踪:

org.postgresql.xa.PGXAException: Error rolling back prepared transaction at org.postgresql.xa.PGXAConnection.rollback(PGXAConnection.java:419) ~[postgresql-9.1-901-1.jdbc4.jar!/:na] at com.atomikos.datasource.xa.XAResourceTransaction.rollback(XAResourceTransaction.java:636) ~[transactions-jta-3.9.3.jar!/:na] at com.atomikos.icatch.imp.RollbackMessage.send(RollbackMessage.java:70) [transactions-3.9.3.jar!/:na] at com.atomikos.icatch.imp.PropagationMessage.submit(PropagationMessage.java:83) [transactions-3.9.3.jar!/:na] at com.atomikos.icatch.imp.Propagator$PropagatorThread.run(Propagator.java:79) [transactions-3.9.3.jar!/:na] at com.atomikos.icatch.imp.Propagator.submitPropagationMessage(Propagator.java:58) [transactions-3.9.3.jar!/:na] at com.atomikos.icatch.imp.HeurHazardStateHandler.onTimeout(HeurHazardStateHandler.java:135) [transactions-3.9.3.jar!/:na] at com.atomikos.icatch.imp.CoordinatorImp.alarm(CoordinatorImp.java:933) [transactions-3.9.3.jar!/:na] at com.atomikos.timing.PooledAlarmTimer.notifyListeners(PooledAlarmTimer.java:112) [atomikos-util-3.9.3.jar!/:na] at com.atomikos.timing.PooledAlarmTimer.run(PooledAlarmTimer.java:99) [atomikos-util-3.9.3.jar!/:na] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_151] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_151] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151] Caused by: org.postgresql.util.PSQLException: ERROR: prepared transaction with identifier "1096044365_MTcyLjE3LjAuMy50bTAwNDAyMDAwMDE=_MTcyLjE3LjAuMy50bTQwMg==" does not exist at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103) ~[postgresql-9.1-901-1.jdbc4.jar!/:na] at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1836) ~[postgresql-9.1-901-1.jdbc4.jar!/:na] at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257) ~[postgresql-9.1-901-1.jdbc4.jar!/:na] at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:512) ~[postgresql-9.1-901-1.jdbc4.jar!/:na] at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:374) ~[postgresql-9.1-901-1.jdbc4.jar!/:na] at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:302) ~[postgresql-9.1-901-1.jdbc4.jar!/:na] at org.postgresql.xa.PGXAConnection.rollback(PGXAConnection.java:409) ~[postgresql-9.1-901-1.jdbc4.jar!/:na] ... 12 common frames omitted

如何停止重试机制

更新到 4.0.6 后再次发生这种情况

2018-01-22 20:42:52.247 ERROR [RequestId:] 1 --- [ Atomikos:51] c.a.datasource.xa.XAResourceTransaction : Heuristic termination of XAResourceTransaction: 3137322E31372E302E342E746D313531363637303131363034343030383435:3137322E31372E302E342E746D383435 with state HEUR_HAZARD 2018-01-22 20:42:52.247 ERROR [RequestId:] 1 --- [ Atomikos:51] com.atomikos.icatch.imp.CoordinatorImp : Local heuristic termination of coordinator 172.17.0.4.tm151667011604400845 with state HEUR_HAZARD 2018-01-22 20:42:52.247 ERROR [RequestId:] 1 --- [ Atomikos:51] com.atomikos.publish.EventPublisher : Transaction 172.17.0.4.tm151667011604400845 corrupted - check https://www.atomikos.com/Documentation/HowToHandleHeuristics to learn more 2018-01-22 20:42:52.420 WARN [RequestId:] 1 --- [ Atomikos:51] c.a.datasource.xa.XAResourceTransaction : XA resource 'postgres': rollback for XID '3137322E31372E302E342E746D313531363637303131363034343030383435:3137322E31372E302E342E746D383435' raised -3: the XA resource detected an internal error

org.postgresql.xa.PGXAException: Error rolling back prepared transaction at org.postgresql.xa.PGXAConnection.rollback(PGXAConnection.java:419) ~[postgresql-9.1-901-1.jdbc4.jar!/:na] at com.atomikos.datasource.xa.XAResourceTransaction.rollback(XAResourceTransaction.java:460) ~[transactions-jta-4.0.6.jar!/:na] at com.atomikos.icatch.imp.RollbackMessage.send(RollbackMessage.java:47) [transactions-4.0.6.jar!/:na] at com.atomikos.icatch.imp.RollbackMessage.send(RollbackMessage.java:20) [transactions-4.0.6.jar!/:na] at com.atomikos.icatch.imp.PropagationMessage.submit(PropagationMessage.java:67) [transactions-4.0.6.jar!/:na] at com.atomikos.icatch.imp.Propagator$PropagatorThread.run(Propagator.java:63) [transactions-4.0.6.jar!/:na] at com.atomikos.icatch.imp.Propagator.submitPropagationMessage(Propagator.java:42) [transactions-4.0.6.jar!/:na] at com.atomikos.icatch.imp.HeurHazardStateHandler.onTimeout(HeurHazardStateHandler.java:75) [transactions-4.0.6.jar!/:na] at com.atomikos.icatch.imp.CoordinatorImp.alarm(CoordinatorImp.java:650) [transactions-4.0.6.jar!/:na] at com.atomikos.timing.PooledAlarmTimer.notifyListeners(PooledAlarmTimer.java:95) [atomikos-util-4.0.6.jar!/:na] at com.atomikos.timing.PooledAlarmTimer.run(PooledAlarmTimer.java:82) [atomikos-util-4.0.6.jar!/:na] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_151] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_151] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151] Caused by: org.postgresql.util.PSQLException: ERROR: prepared transaction with identifier "1096044365_MTcyLjE3LjAuNC50bTE1MTY2NzAxMTYwNDQwMDg0NQ==_MTcyLjE3LjAuNC50bTg0NQ==" does not exist at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103) ~[postgresql-9.1-901-1.jdbc4.jar!/:na] at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1836) ~[postgresql-9.1-901-1.jdbc4.jar!/:na] at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257) ~[postgresql-9.1-901-1.jdbc4.jar!/:na] at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:512) ~[postgresql-9.1-901-1.jdbc4.jar!/:na] at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:374) ~[postgresql-9.1-901-1.jdbc4.jar!/:na] at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:302) ~[postgresql-9.1-901-1.jdbc4.jar!/:na] at org.postgresql.xa.PGXAConnection.rollback(PGXAConnection.java:409) ~[postgresql-9.1-901-1.jdbc4.jar!/:na] ... 13 common frames omitted

这看起来像是已在 TransactionsEssentials 4.0.6 中修复的错误

在深入研究 Atomikos 源代码并查看堆栈跟踪之后。 下面是我对 CoordinatorImp.java 中的警报方法所做的更改(在 Atomikos 源代码中),这解决了我的问题。

public void alarm ( AlarmTimer timer )
{
   try {
        boolean isHeuristic = stateHandler_ instanceof 
          HeurHazardStateHandler 
|| stateHandler_ instanceof HeurAbortedStateHandler
                                  || stateHandler_ instanceof HeurCommittedStateHandler || stateHandler_ instanceof HeurMixedStateHandler;
    if (!(isHeuristic)) {
     stateHandler_.onTimeout ();
    }
    } catch ( Exception e ) {
       LOGGER.logWarning( "Exception on timeout of coordinator " + root_ , e );
    }
   }