Copilot commented on code in PR #875:
URL:
https://github.com/apache/incubator-seata-go/pull/875#discussion_r2328966364
##########
pkg/datasource/sql/conn_xa.go:
##########
@@ -313,6 +325,7 @@ func (c *XAConn) Rollback(ctx context.Context) error {
c.cleanXABranchContext()
return fmt.Errorf("failed to report XA branch
commit-failure on xid:%s err:%w", c.txCtx.XID, err)
}
+ c.rollBacked = true
Review Comment:
The `c.rollBacked = true` line is placed inside the `if !c.rollBacked` block
but after the XA rollback operation. If the XA rollback fails and returns an
error, this line will not be executed, but the method will still return an
error. This could leave the connection in an inconsistent state where
subsequent rollback attempts might behave unexpectedly.
##########
pkg/datasource/sql/conn_xa.go:
##########
@@ -404,3 +417,19 @@ func (c *XAConn) XaRollback(ctx context.Context, xaXid
XAXid) error {
c.releaseIfNecessary()
return err
}
+
+// isXAER_RMFAILAlreadyEnded checks if the XAER_RMFAIL error indicates the XA
branch is already ended
+// expected error: Error 1399 (XAE07): XAER_RMFAIL: The command cannot be
executed when global transaction is in the IDLE state
+func isXAER_RMFAILAlreadyEnded(err error) bool {
+ if err == nil {
+ return false
+ }
+ if mysqlErr, ok := err.(*mysql.MySQLError); ok {
+ if mysqlErr.Number == types.ErrCodeXAER_RMFAIL_IDLE {
+ return strings.Contains(mysqlErr.Message, "IDLE state")
|| strings.Contains(mysqlErr.Message, "already ended")
+ }
+ }
+ //todo other DB error
Review Comment:
The comment should be properly formatted with a space after '//' and proper
capitalization: '// TODO: handle other DB errors'.
```suggestion
// TODO: handle other DB errors
```
##########
pkg/datasource/sql/conn_xa.go:
##########
@@ -404,3 +417,19 @@ func (c *XAConn) XaRollback(ctx context.Context, xaXid
XAXid) error {
c.releaseIfNecessary()
return err
}
+
+// isXAER_RMFAILAlreadyEnded checks if the XAER_RMFAIL error indicates the XA
branch is already ended
+// expected error: Error 1399 (XAE07): XAER_RMFAIL: The command cannot be
executed when global transaction is in the IDLE state
Review Comment:
There's an extra space in 'the IDLE state' - should be 'the IDLE state'
with only one space.
```suggestion
// expected error: Error 1399 (XAE07): XAER_RMFAIL: The command cannot be
executed when global transaction is in the IDLE state
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]