This is an automated email from the ASF dual-hosted git repository.

jianbin pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git


The following commit(s) were added to refs/heads/2.x by this push:
     new 13d2db4935 optimize: use retry logic to end global trx (#7283)
13d2db4935 is described below

commit 13d2db49354f1f25d58267e6c83603e41e8adcbb
Author: Jingliu <928124...@qq.com>
AuthorDate: Thu Apr 17 09:12:32 2025 +0800

    optimize: use retry logic to end global trx (#7283)
---
 changes/en-us/2.x.md                                |  1 +
 changes/zh-cn/2.x.md                                |  2 ++
 .../server/console/impl/AbstractGlobalService.java  | 21 ++++-----------------
 .../seata/server/console/impl/AbstractService.java  |  8 ++++----
 4 files changed, 11 insertions(+), 21 deletions(-)

diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index 09bc1667af..e3b696b80e 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -85,6 +85,7 @@ Add changes here for all PR submitted to the 2.x branch.
 - [[#7242](https://github.com/apache/incubator-seata/pull/7242)] optimize 
ratelimit bucketTokenNumPerSecond config
 - [[#7232](https://github.com/apache/incubator-seata/pull/7232)] add license 
header
 - [[#7260](https://github.com/apache/incubator-seata/pull/7260)] upgrade npmjs 
dependencies
+- [[#7283](https://github.com/apache/incubator-seata/pull/7283)] optimize: use 
retry logic to end global trx
 - [[#7284](https://github.com/apache/incubator-seata/pull/7284)] add 
dependency-check profile
 
 
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index 93fc50d35e..a3cca49e0c 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -83,8 +83,10 @@
 - [[#7250](https://github.com/apache/incubator-seata/pull/7250)] 适配 
client_protocol_version > server_protocol_version场景
 - [[#7232](https://github.com/apache/incubator-seata/pull/7232)] 增加 license 
header
 - [[#7260](https://github.com/apache/incubator-seata/pull/7260)] 升级 npmjs 依赖版本
+- [[#7283](https://github.com/apache/incubator-seata/pull/7283)] 使用重试逻辑优化事务的结束
 - [[#7284](https://github.com/apache/incubator-seata/pull/7284)] 增加 
dependency-check profile
 
+
 ### security:
 - [[#6069](https://github.com/apache/incubator-seata/pull/6069)] 
升级Guava依赖版本,修复安全漏洞
 - [[#6144](https://github.com/apache/incubator-seata/pull/6144)] 
升级Nacos依赖版本至1.4.6
diff --git 
a/server/src/main/java/org/apache/seata/server/console/impl/AbstractGlobalService.java
 
b/server/src/main/java/org/apache/seata/server/console/impl/AbstractGlobalService.java
index c45631e0b3..2305dc112b 100644
--- 
a/server/src/main/java/org/apache/seata/server/console/impl/AbstractGlobalService.java
+++ 
b/server/src/main/java/org/apache/seata/server/console/impl/AbstractGlobalService.java
@@ -20,10 +20,8 @@ import org.apache.seata.common.result.SingleResult;
 import org.apache.seata.core.model.GlobalStatus;
 import org.apache.seata.server.console.exception.ConsoleException;
 import org.apache.seata.server.console.service.GlobalSessionService;
-import org.apache.seata.server.coordinator.DefaultCoordinator;
 import org.apache.seata.server.session.BranchSession;
 import org.apache.seata.server.session.GlobalSession;
-import org.apache.seata.server.session.SessionHolder;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -121,21 +119,10 @@ public abstract class AbstractGlobalService extends 
AbstractService implements G
             boolean res;
             if (RETRY_COMMIT_STATUS.contains(globalStatus) || 
GlobalStatus.Committing.equals(globalStatus)
                     || 
GlobalStatus.StopCommitOrCommitRetry.equals(globalStatus)) {
-                res = 
DefaultCoordinator.getInstance().doGlobalCommit(globalSession, false);
-                if (res && globalSession.hasBranch() && 
globalSession.hasATBranch()) {
-                    globalSession.clean();
-                    globalSession.asyncCommit();
-                } else if (res && SessionHolder.findGlobalSession(xid) != 
null) {
-                    globalSession.end();
-                }
+                res = doRetryCommitGlobal(globalSession);
             } else if (RETRY_ROLLBACK_STATUS.contains(globalStatus) || 
GlobalStatus.Rollbacking.equals(globalStatus)
                     || 
GlobalStatus.StopRollbackOrRollbackRetry.equals(globalStatus)) {
-                res = 
DefaultCoordinator.getInstance().doGlobalRollback(globalSession, false);
-                // the record is not deleted
-                if (res && SessionHolder.findGlobalSession(xid) != null) {
-                    globalSession.changeGlobalStatus(GlobalStatus.Rollbacked);
-                    globalSession.end();
-                }
+                res = doRetryRollbackGlobal(globalSession);
             } else {
                 throw new IllegalArgumentException("current global transaction 
status is not support to do");
             }
@@ -152,11 +139,11 @@ public abstract class AbstractGlobalService extends 
AbstractService implements G
         GlobalStatus globalStatus = globalSession.getStatus();
         try {
             if (FAIL_COMMIT_STATUS.contains(globalStatus)) {
-                boolean committed = doCommitGlobal(globalSession);
+                boolean committed = doRetryCommitGlobal(globalSession);
                 return committed ? SingleResult.success() : 
SingleResult.failure("Commit fail, please try again");
             }
             if (FAIL_ROLLBACK_STATUS.contains(globalStatus)) {
-                boolean rollbacked = doRollbackGlobal(globalSession);
+                boolean rollbacked = doRetryRollbackGlobal(globalSession);
                 return rollbacked ? SingleResult.success() : 
SingleResult.failure("Rollback fail, please try again");
             }
         } catch (Exception e) {
diff --git 
a/server/src/main/java/org/apache/seata/server/console/impl/AbstractService.java
 
b/server/src/main/java/org/apache/seata/server/console/impl/AbstractService.java
index 5c893e1d15..e5dd211fd9 100644
--- 
a/server/src/main/java/org/apache/seata/server/console/impl/AbstractService.java
+++ 
b/server/src/main/java/org/apache/seata/server/console/impl/AbstractService.java
@@ -147,12 +147,12 @@ public abstract class AbstractService {
         return true;
     }
 
-    protected boolean doCommitGlobal(GlobalSession globalSession) throws 
TransactionException {
-        return DefaultCoordinator.getInstance().doGlobalCommit(globalSession, 
false);
+    protected boolean doRetryCommitGlobal(GlobalSession globalSession) throws 
TransactionException {
+        return DefaultCoordinator.getInstance().doGlobalCommit(globalSession, 
true);
     }
 
-    protected boolean doRollbackGlobal(GlobalSession globalSession) throws 
TransactionException {
-        return 
DefaultCoordinator.getInstance().doGlobalRollback(globalSession, false);
+    protected boolean doRetryRollbackGlobal(GlobalSession globalSession) 
throws TransactionException {
+        return 
DefaultCoordinator.getInstance().doGlobalRollback(globalSession, true);
     }
 
     protected static class CheckResult {


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org
For additional commands, e-mail: notifications-h...@seata.apache.org

Reply via email to