Skip to content

Commit

Permalink
bugfix: fix TC retry rollback wrongly, after the XA transaction fail …
Browse files Browse the repository at this point in the history
…and rollback (#5833)
  • Loading branch information
capthua authored Oct 8, 2023
1 parent 351b108 commit 866ef33
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
2 changes: 2 additions & 0 deletions changes/en-us/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Add changes here for all PR submitted to the develop branch.
- [[#5892](https://github.com/seata/seata/pull/5892)] support PolarDB-X 2.0 database

### bugfix:
- [[#5833](https://github.com/seata/seata/pull/5833)] bugfix: fix TC retry rollback wrongly, after the XA transaction fail and rollback
- [[#5884](https://github.com/seata/seata/pull/5884)] fix dm escaped characters for upper and lower case column names

### optimize:
Expand All @@ -29,6 +30,7 @@ Thanks to these contributors for their code commits. Please report an unintended

<!-- Please make sure your Github ID is in the list below -->
- [slievrly](https://github.com/slievrly)
- [capthua](https://github.com/capthua)
- [funky-eyes](https://github.com/funky-eyes)
- [iquanzhan](https://github.com/iquanzhan)

Expand Down
2 changes: 2 additions & 0 deletions changes/zh-cn/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [[#5892](https://github.com/seata/seata/pull/5892)] AT模式支持PolarDB-X 2.0数据库

### bugfix:
- [[#5833](https://github.com/seata/seata/pull/5833)] bugfix: 修复当 XA 事务失败回滚后,TC 还会继续重试回滚的问题
- [[#5884](https://github.com/seata/seata/pull/5884)] 修复达梦前后镜像查询列名都加了引号导致sql异常的问题

### optimize:
Expand All @@ -29,6 +30,7 @@

<!-- 请确保您的 GitHub ID 在以下列表中 -->
- [slievrly](https://github.com/slievrly)
- [capthua](https://github.com/capthua)
- [funky-eyes](https://github.com/funky-eyes)
- [iquanzhan](https://github.com/iquanzhan)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
LOGGER.info(xaBranchXid + " was rollbacked");
reportStatusToTC(BranchStatus.PhaseOne_Failed);
LOGGER.info("{} was rollbacked", xaBranchXid);
} 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();
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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 {} on {}-{} since {}:{}",
status, xid, xaBranchXid.getBranchId(), te.getCode(), te.getMessage());
}
}

}

0 comments on commit 866ef33

Please sign in to comment.