Skip to content

Commit

Permalink
fix xa report state to tc
Browse files Browse the repository at this point in the history
  • Loading branch information
Code-Fight committed Nov 25, 2024
1 parent ad092d5 commit eb2ac1c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pkg/datasource/sql/conn_xa.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,6 @@ func (c *XAConn) createNewTxOnExecIfNeed(ctx context.Context, f func() (types.Ex
err error
)

currentAutoCommit := c.autoCommit
if c.txCtx.TransactionMode != types.Local && tm.IsGlobalTx(ctx) && c.autoCommit {
tx, err = c.BeginTx(ctx, driver.TxOptions{Isolation: driver.IsolationLevel(gosql.LevelDefault)})
if err != nil {
return nil, err
}
}
defer func() {
recoverErr := recover()
if err != nil || recoverErr != nil {
Expand All @@ -201,6 +194,14 @@ func (c *XAConn) createNewTxOnExecIfNeed(ctx context.Context, f func() (types.Ex
}
}()

currentAutoCommit := c.autoCommit
if c.txCtx.TransactionMode != types.Local && tm.IsGlobalTx(ctx) && c.autoCommit {
tx, err = c.BeginTx(ctx, driver.TxOptions{Isolation: driver.IsolationLevel(gosql.LevelDefault)})
if err != nil {
return nil, err
}
}

// execute SQL
ret, err := f()
if err != nil {
Expand All @@ -212,7 +213,7 @@ func (c *XAConn) createNewTxOnExecIfNeed(ctx context.Context, f func() (types.Ex
}

if tx != nil && currentAutoCommit {
if err := c.Commit(ctx); err != nil {
if err = c.Commit(ctx); err != nil {
log.Errorf("xa connection proxy commit failure xid:%s, err:%v", c.txCtx.XID, err)
// XA End & Rollback
if err := c.Rollback(ctx); err != nil {
Expand Down

0 comments on commit eb2ac1c

Please sign in to comment.