Skip to content

Commit 13d2db4

Browse files
authored
optimize: use retry logic to end global trx (#7283)
1 parent b1f0c04 commit 13d2db4

File tree

4 files changed

+11
-21
lines changed

4 files changed

+11
-21
lines changed

changes/en-us/2.x.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Add changes here for all PR submitted to the 2.x branch.
8585
- [[#7242](https://github.com/apache/incubator-seata/pull/7242)] optimize ratelimit bucketTokenNumPerSecond config
8686
- [[#7232](https://github.com/apache/incubator-seata/pull/7232)] add license header
8787
- [[#7260](https://github.com/apache/incubator-seata/pull/7260)] upgrade npmjs dependencies
88+
- [[#7283](https://github.com/apache/incubator-seata/pull/7283)] optimize: use retry logic to end global trx
8889
- [[#7284](https://github.com/apache/incubator-seata/pull/7284)] add dependency-check profile
8990

9091

changes/zh-cn/2.x.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@
8383
- [[#7250](https://github.com/apache/incubator-seata/pull/7250)] 适配 client_protocol_version > server_protocol_version场景
8484
- [[#7232](https://github.com/apache/incubator-seata/pull/7232)] 增加 license header
8585
- [[#7260](https://github.com/apache/incubator-seata/pull/7260)] 升级 npmjs 依赖版本
86+
- [[#7283](https://github.com/apache/incubator-seata/pull/7283)] 使用重试逻辑优化事务的结束
8687
- [[#7284](https://github.com/apache/incubator-seata/pull/7284)] 增加 dependency-check profile
8788

89+
8890
### security:
8991
- [[#6069](https://github.com/apache/incubator-seata/pull/6069)] 升级Guava依赖版本,修复安全漏洞
9092
- [[#6144](https://github.com/apache/incubator-seata/pull/6144)] 升级Nacos依赖版本至1.4.6

server/src/main/java/org/apache/seata/server/console/impl/AbstractGlobalService.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
import org.apache.seata.core.model.GlobalStatus;
2121
import org.apache.seata.server.console.exception.ConsoleException;
2222
import org.apache.seata.server.console.service.GlobalSessionService;
23-
import org.apache.seata.server.coordinator.DefaultCoordinator;
2423
import org.apache.seata.server.session.BranchSession;
2524
import org.apache.seata.server.session.GlobalSession;
26-
import org.apache.seata.server.session.SessionHolder;
2725

2826
import java.util.ArrayList;
2927
import java.util.List;
@@ -121,21 +119,10 @@ public SingleResult<Void> sendCommitOrRollback(String xid) {
121119
boolean res;
122120
if (RETRY_COMMIT_STATUS.contains(globalStatus) || GlobalStatus.Committing.equals(globalStatus)
123121
|| GlobalStatus.StopCommitOrCommitRetry.equals(globalStatus)) {
124-
res = DefaultCoordinator.getInstance().doGlobalCommit(globalSession, false);
125-
if (res && globalSession.hasBranch() && globalSession.hasATBranch()) {
126-
globalSession.clean();
127-
globalSession.asyncCommit();
128-
} else if (res && SessionHolder.findGlobalSession(xid) != null) {
129-
globalSession.end();
130-
}
122+
res = doRetryCommitGlobal(globalSession);
131123
} else if (RETRY_ROLLBACK_STATUS.contains(globalStatus) || GlobalStatus.Rollbacking.equals(globalStatus)
132124
|| GlobalStatus.StopRollbackOrRollbackRetry.equals(globalStatus)) {
133-
res = DefaultCoordinator.getInstance().doGlobalRollback(globalSession, false);
134-
// the record is not deleted
135-
if (res && SessionHolder.findGlobalSession(xid) != null) {
136-
globalSession.changeGlobalStatus(GlobalStatus.Rollbacked);
137-
globalSession.end();
138-
}
125+
res = doRetryRollbackGlobal(globalSession);
139126
} else {
140127
throw new IllegalArgumentException("current global transaction status is not support to do");
141128
}
@@ -152,11 +139,11 @@ public SingleResult<Void> changeGlobalStatus(String xid) {
152139
GlobalStatus globalStatus = globalSession.getStatus();
153140
try {
154141
if (FAIL_COMMIT_STATUS.contains(globalStatus)) {
155-
boolean committed = doCommitGlobal(globalSession);
142+
boolean committed = doRetryCommitGlobal(globalSession);
156143
return committed ? SingleResult.success() : SingleResult.failure("Commit fail, please try again");
157144
}
158145
if (FAIL_ROLLBACK_STATUS.contains(globalStatus)) {
159-
boolean rollbacked = doRollbackGlobal(globalSession);
146+
boolean rollbacked = doRetryRollbackGlobal(globalSession);
160147
return rollbacked ? SingleResult.success() : SingleResult.failure("Rollback fail, please try again");
161148
}
162149
} catch (Exception e) {

server/src/main/java/org/apache/seata/server/console/impl/AbstractService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ protected boolean doForceDeleteBranch(GlobalSession globalSession, BranchSession
147147
return true;
148148
}
149149

150-
protected boolean doCommitGlobal(GlobalSession globalSession) throws TransactionException {
151-
return DefaultCoordinator.getInstance().doGlobalCommit(globalSession, false);
150+
protected boolean doRetryCommitGlobal(GlobalSession globalSession) throws TransactionException {
151+
return DefaultCoordinator.getInstance().doGlobalCommit(globalSession, true);
152152
}
153153

154-
protected boolean doRollbackGlobal(GlobalSession globalSession) throws TransactionException {
155-
return DefaultCoordinator.getInstance().doGlobalRollback(globalSession, false);
154+
protected boolean doRetryRollbackGlobal(GlobalSession globalSession) throws TransactionException {
155+
return DefaultCoordinator.getInstance().doGlobalRollback(globalSession, true);
156156
}
157157

158158
protected static class CheckResult {

0 commit comments

Comments
 (0)