Skip to content

Commit eb2ac1c

Browse files
committed
fix xa report state to tc
1 parent ad092d5 commit eb2ac1c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

pkg/datasource/sql/conn_xa.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,6 @@ func (c *XAConn) createNewTxOnExecIfNeed(ctx context.Context, f func() (types.Ex
181181
err error
182182
)
183183

184-
currentAutoCommit := c.autoCommit
185-
if c.txCtx.TransactionMode != types.Local && tm.IsGlobalTx(ctx) && c.autoCommit {
186-
tx, err = c.BeginTx(ctx, driver.TxOptions{Isolation: driver.IsolationLevel(gosql.LevelDefault)})
187-
if err != nil {
188-
return nil, err
189-
}
190-
}
191184
defer func() {
192185
recoverErr := recover()
193186
if err != nil || recoverErr != nil {
@@ -201,6 +194,14 @@ func (c *XAConn) createNewTxOnExecIfNeed(ctx context.Context, f func() (types.Ex
201194
}
202195
}()
203196

197+
currentAutoCommit := c.autoCommit
198+
if c.txCtx.TransactionMode != types.Local && tm.IsGlobalTx(ctx) && c.autoCommit {
199+
tx, err = c.BeginTx(ctx, driver.TxOptions{Isolation: driver.IsolationLevel(gosql.LevelDefault)})
200+
if err != nil {
201+
return nil, err
202+
}
203+
}
204+
204205
// execute SQL
205206
ret, err := f()
206207
if err != nil {
@@ -212,7 +213,7 @@ func (c *XAConn) createNewTxOnExecIfNeed(ctx context.Context, f func() (types.Ex
212213
}
213214

214215
if tx != nil && currentAutoCommit {
215-
if err := c.Commit(ctx); err != nil {
216+
if err = c.Commit(ctx); err != nil {
216217
log.Errorf("xa connection proxy commit failure xid:%s, err:%v", c.txCtx.XID, err)
217218
// XA End & Rollback
218219
if err := c.Rollback(ctx); err != nil {

0 commit comments

Comments
 (0)