diff --git a/changes/en-us/2.0.0.md b/changes/en-us/2.0.0.md index ced91899bff..5a0c7b8bab0 100644 --- a/changes/en-us/2.0.0.md +++ b/changes/en-us/2.0.0.md @@ -70,6 +70,7 @@ The version is updated as follows: - [[#5787](https://github.com/seata/seata/pull/5794)] Solution cluster cannot be customized when redis serves as the registry - [[#5810](https://github.com/seata/seata/pull/5810)] fix XA transaction start exception and rollback failure caused by druid dependency conflict - [[#5821](https://github.com/seata/seata/pull/5821)] fix insert executor keywords unescape +- [[#5835](https://github.com/seata/seata/pull/5835)] bugfix: fix TC retry rollback wrongly, after the XA transaction fail and rollback ### optimize: - [[#5208](https://github.com/seata/seata/pull/5208)] optimize throwable getCause once more diff --git a/changes/zh-cn/2.0.0.md b/changes/zh-cn/2.0.0.md index 9aedec55fc6..5172223ceca 100644 --- a/changes/zh-cn/2.0.0.md +++ b/changes/zh-cn/2.0.0.md @@ -69,6 +69,7 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单 - [[#5787](https://github.com/seata/seata/pull/5794)] 解决redis作为注册中心时cluster无法自定义的BUG - [[#5810](https://github.com/seata/seata/pull/5810)] 修复druid依赖冲突导致的XA事务开始异常与回滚失败 - [[#5821](https://github.com/seata/seata/pull/5821)] 修复insert executor对关键字未转义的问题 +- [[#5835](https://github.com/seata/seata/pull/5835)] bugfix: 修复当 XA 事务失败回滚后,TC 还会继续重试回滚的问题 ### optimize: - [[#5208](https://github.com/seata/seata/pull/5208)] 优化多次重复获取Throwable#getCause问题 diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/xa/ConnectionProxyXA.java b/rm-datasource/src/main/java/io/seata/rm/datasource/xa/ConnectionProxyXA.java index d7e02c9a5b9..d59564adc7e 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/xa/ConnectionProxyXA.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/xa/ConnectionProxyXA.java @@ -212,15 +212,8 @@ public synchronized void commit() throws SQLException { setPrepareTime(now); xaResource.prepare(xaBranchXid); } catch (XAException xe) { - try { - // Branch Report to TC: Failed - DefaultResourceManager.get().branchReport(BranchType.XA, xid, xaBranchXid.getBranchId(), - BranchStatus.PhaseOne_Failed, null); - } catch (TransactionException te) { - LOGGER.warn("Failed to report XA branch commit-failure on " + xid + "-" + xaBranchXid.getBranchId() - + " since " + te.getCode() + ":" + te.getMessage() + " and XAException:" + xe.getMessage()); - - } + // Branch Report to TC: Failed + reportStatusToTC(BranchStatus.PhaseOne_Failed); throw new SQLException( "Failed to end(TMSUCCESS)/prepare xa branch on " + xid + "-" + xaBranchXid.getBranchId() + " since " + xe .getMessage(), xe); @@ -245,16 +238,11 @@ public void rollback() throws SQLException { xaRollback(xaBranchXid); } // Branch Report to TC - DefaultResourceManager.get().branchReport(BranchType.XA, xid, xaBranchXid.getBranchId(), - BranchStatus.PhaseOne_Failed, null); + reportStatusToTC(BranchStatus.PhaseOne_Failed); LOGGER.info(xaBranchXid + " was rollbacked"); } catch (XAException xe) { throw new SQLException("Failed to end(TMFAIL) xa branch on " + xid + "-" + xaBranchXid.getBranchId() + " since " + xe.getMessage(), xe); - } catch (TransactionException te) { - // log and ignore the report failure - LOGGER.warn("Failed to report XA branch rollback on " + xid + "-" + xaBranchXid.getBranchId() + " since " - + te.getCode() + ":" + te.getMessage()); } finally { cleanXABranchContext(); } @@ -274,6 +262,8 @@ private synchronized void start() throws XAException, SQLException { // the framework layer does not actively call ROLLBACK when setAutoCommit throws an SQL exception xaResource.end(this.xaBranchXid, XAResource.TMFAIL); xaRollback(xaBranchXid); + // Branch Report to TC: Failed + reportStatusToTC(BranchStatus.PhaseOne_Failed); throw e; } } @@ -360,4 +350,19 @@ private void termination(String xaBranchXid) throws SQLException { } } + /** + * Report branch status to TC + * + * @param status branch status + */ + private void reportStatusToTC(BranchStatus status) { + try { + DefaultResourceManager.get().branchReport(BranchType.XA, xid, xaBranchXid.getBranchId(), + status, null); + } catch (TransactionException te) { + LOGGER.warn("Failed to report XA branch " + status + " on " + xid + "-" + xaBranchXid.getBranchId() + + " since " + te.getCode() + ":" + te.getMessage()); + } + } + }