funky-eyes commented on code in PR #7102:
URL: https://github.com/apache/incubator-seata/pull/7102#discussion_r1912788269


##########
rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/ConnectionProxyXA.java:
##########
@@ -223,34 +233,12 @@ public synchronized void commit() throws SQLException {
             throw new SQLException("should NOT commit on an inactive session", 
SQLSTATE_XA_NOT_END);
         }
         try {
-            // XA End: Success
-            try {
-                end(XAResource.TMSUCCESS);
-            } catch (SQLException sqle) {
-                // Rollback immediately before the XA Branch Context is 
deleted.
-                String xaBranchXid = this.xaBranchXid.toString();
-                rollback();
-                throw new SQLException("Branch " + xaBranchXid + " was 
rollbacked on committing since " + sqle.getMessage(), SQLSTATE_XA_NOT_END, 
sqle);
-            }
-            long now = System.currentTimeMillis();
-            checkTimeout(now);
-            setPrepareTime(now);
-            int prepare = xaResource.prepare(xaBranchXid);
-            // Based on the four databases: MySQL (8), Oracle (12c), Postgres 
(16), and MSSQL Server (2022),
-            // only Oracle has read-only optimization; the others do not 
provide read-only feedback.
-            // Therefore, the database type check can be eliminated here.
-            if (prepare == XAResource.XA_RDONLY) {
-                // Branch Report to TC: RDONLY
-                reportStatusToTC(BranchStatus.PhaseOne_RDONLY);
-            }
-        } catch (XAException xe) {
-            // 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);
+            xaEnd(xaBranchXid, XAResource.TMSUCCESS);

Review Comment:
   ```suggestion
               end(XAResource.TMSUCCESS);
   ```



##########
rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/ConnectionProxyXA.java:
##########
@@ -324,13 +308,41 @@ private void checkTimeout(Long now) throws XAException {
 
     @Override
     public synchronized void close() throws SQLException {
-        rollBacked = false;
-        if (isHeld() && shouldBeHeld()) {
-            // if kept by a keeper, just hold the connection.
-            return;
+        try {
+            if (xaEnded) {
+                termination();
+                long now = System.currentTimeMillis();
+                checkTimeout(now);
+                setPrepareTime(now);
+                int prepare = xaResource.prepare(xaBranchXid);

Review Comment:
   如果走了rollback的事务不需要prepare,直接上报一阶段失败即可
   If the transaction that has gone rollback does not need to be prepared, it 
can directly report the failure of the first stage



##########
rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/ConnectionProxyXA.java:
##########
@@ -324,13 +308,41 @@ private void checkTimeout(Long now) throws XAException {
 
     @Override
     public synchronized void close() throws SQLException {
-        rollBacked = false;
-        if (isHeld() && shouldBeHeld()) {
-            // if kept by a keeper, just hold the connection.
-            return;
+        try {
+            if (xaEnded) {
+                termination();

Review Comment:
   我认为prepare这块的逻辑不需要termination
   I don't think the logic of preparing this piece needs termination



##########
rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/ConnectionProxyXA.java:
##########
@@ -223,34 +233,12 @@ public synchronized void commit() throws SQLException {
             throw new SQLException("should NOT commit on an inactive session", 
SQLSTATE_XA_NOT_END);
         }
         try {
-            // XA End: Success
-            try {
-                end(XAResource.TMSUCCESS);
-            } catch (SQLException sqle) {
-                // Rollback immediately before the XA Branch Context is 
deleted.
-                String xaBranchXid = this.xaBranchXid.toString();
-                rollback();
-                throw new SQLException("Branch " + xaBranchXid + " was 
rollbacked on committing since " + sqle.getMessage(), SQLSTATE_XA_NOT_END, 
sqle);
-            }
-            long now = System.currentTimeMillis();
-            checkTimeout(now);
-            setPrepareTime(now);
-            int prepare = xaResource.prepare(xaBranchXid);
-            // Based on the four databases: MySQL (8), Oracle (12c), Postgres 
(16), and MSSQL Server (2022),
-            // only Oracle has read-only optimization; the others do not 
provide read-only feedback.
-            // Therefore, the database type check can be eliminated here.
-            if (prepare == XAResource.XA_RDONLY) {
-                // Branch Report to TC: RDONLY
-                reportStatusToTC(BranchStatus.PhaseOne_RDONLY);
-            }
-        } catch (XAException xe) {
-            // 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);
+            xaEnd(xaBranchXid, XAResource.TMSUCCESS);
+        } catch (XAException e) {
+            throw new SQLException("Failed to end(TMSUCCESS) xa branch on " + 
xid + "-" + xaBranchXid.getBranchId()
+                    + " since " + e.getMessage(), e);
         } finally {
-            cleanXABranchContext();
+            xaActive = false;

Review Comment:
   这个改成false后,如果通过setAutoCommit触发commit时要怎么办?
   After changing this to false, what if the commit is triggered by 
setAutoCommit?



##########
rm-datasource/src/main/java/org/apache/seata/rm/datasource/xa/ConnectionProxyXA.java:
##########
@@ -324,13 +308,41 @@ private void checkTimeout(Long now) throws XAException {
 
     @Override
     public synchronized void close() throws SQLException {
-        rollBacked = false;
-        if (isHeld() && shouldBeHeld()) {
-            // if kept by a keeper, just hold the connection.
-            return;
+        try {
+            if (xaEnded) {

Review Comment:
   
end后的xa事务应该是可以join的,只要没有进入prepare阶段,如果我手动commit或rollback,再接着发sql,这里被标识成了xaended,如何进行prepare?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to