Browse Source

【WIP】fix: xa report state to TC (#717)

fix xa report state to tc

Co-authored-by: JayLiu <38887641+luky116@users.noreply.github.com>
tags/v2.0.0
FengZhang GitHub 9 months ago
parent
commit
9aead3033c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 8 deletions
  1. +9
    -8
      pkg/datasource/sql/conn_xa.go

+ 9
- 8
pkg/datasource/sql/conn_xa.go View File

@@ -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 {
@@ -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 {
@@ -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 {


Loading…
Cancel
Save