Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: fix TC retry rollback wrongly, after the XA transaction fail and rollback #5835

Merged
merged 3 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/en-us/2.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions changes/zh-cn/2.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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问题
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);
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();
}
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 " + status + " on " + xid + "-" + xaBranchXid.getBranchId()
+ " since " + te.getCode() + ":" + te.getMessage());
}
}

}
Loading