Skip to content

Commit

Permalink
fix trx log
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyuecai committed Mar 23, 2024
1 parent c93ad45 commit 86bdaae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
25 changes: 13 additions & 12 deletions pkg/runtime/transaction/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package transaction

import (
"context"
rcontext "github.com/arana-db/arana/pkg/runtime/context"
)

import (
Expand All @@ -40,15 +41,15 @@ func NewXAHook(tenant string, enable bool) (*xaHook, error) {
enable: enable,
}

trxStateChangeFunc := map[runtime.TxState]handleFunc{
runtime.TrxStarted: xh.onStarted,
runtime.TrxPreparing: xh.onPreparing,
runtime.TrxPrepared: xh.onPrepared,
runtime.TrxCommitting: xh.onCommitting,
runtime.TrxCommitted: xh.onCommitted,
runtime.TrxAborted: xh.onAborting,
runtime.TrxRolledBacking: xh.onRollbackOnly,
runtime.TrxRolledBacked: xh.onRolledBack,
trxStateChangeFunc := map[rcontext.TxState]handleFunc{
rcontext.TrxStarted: xh.onStarted,
rcontext.TrxPreparing: xh.onPreparing,
rcontext.TrxPrepared: xh.onPrepared,
rcontext.TrxCommitting: xh.onCommitting,
rcontext.TrxCommitted: xh.onCommitted,
rcontext.TrxAborted: xh.onAborting,
rcontext.TrxRolledBacking: xh.onRollbackOnly,
rcontext.TrxRolledBacked: xh.onRolledBack,
}

xh.trxMgr = trxMgr
Expand All @@ -64,10 +65,10 @@ type xaHook struct {
enable bool
trxMgr *TrxManager
trxLog *GlobalTrxLog
trxStateChangeFunc map[runtime.TxState]handleFunc
trxStateChangeFunc map[rcontext.TxState]handleFunc
}

func (xh *xaHook) OnTxStateChange(ctx context.Context, state runtime.TxState, tx runtime.CompositeTx) error {
func (xh *xaHook) OnTxStateChange(ctx context.Context, state rcontext.TxState, tx runtime.CompositeTx) error {
if !xh.enable {
return nil
}
Expand Down Expand Up @@ -162,7 +163,7 @@ func (xh *xaHook) onRollbackOnly(ctx context.Context, tx runtime.CompositeTx) er
}

func (xh *xaHook) onRolledBack(ctx context.Context, tx runtime.CompositeTx) error {
xh.trxLog.Status = runtime.TrxRolledBacking
xh.trxLog.Status = rcontext.TrxRolledBacking
if err := xh.trxMgr.trxLog.AddOrUpdateGlobalTxLog(*xh.trxLog); err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/runtime/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"database/sql"
"fmt"
rcontext "github.com/arana-db/arana/pkg/runtime/context"
"testing"
"time"
)
Expand All @@ -41,7 +42,7 @@ func Test_branchTx_CallFieldList(t *testing.T) {
type fields struct {
closed atomic.Bool
parent *AtomDB
state TxState
state rcontext.TxState
prepare dbFunc
commit dbFunc
rollback dbFunc
Expand Down Expand Up @@ -89,7 +90,7 @@ func Test_compositeTx_Rollback(t *testing.T) {
beginTime time.Time
endTime time.Time
isoLevel sql.IsolationLevel
txState TxState
txState rcontext.TxState
beginFunc dbFunc
rt *defaultRuntime
txs map[string]*branchTx
Expand Down

0 comments on commit 86bdaae

Please sign in to comment.