Skip to content

Commit

Permalink
fix dead lock (#21279)
Browse files Browse the repository at this point in the history
fix dead lock

Approved by: @ouyuanning
  • Loading branch information
zhangxu19830126 authored Jan 18, 2025
1 parent 97ec151 commit fb4cc6f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pkg/txn/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,9 @@ func (client *txnClient) removeFromWaitActiveLocked(txnID []byte) bool {

func (client *txnClient) waitMarkAllActiveAbortedLocked() {
if client.mu.waitMarkAllActiveAbortedC != nil {
<-client.mu.waitMarkAllActiveAbortedC
c := client.mu.waitMarkAllActiveAbortedC
client.mu.Unlock()
<-c
client.mu.Lock()
}
}
13 changes: 13 additions & 0 deletions pkg/txn/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,16 @@ func TestNewWithUpdateSnapshotTimeout(t *testing.T) {
assert.Equal(t, 0, len(v.mu.waitActiveTxns))
v.mu.Unlock()
}

func TestWaitAbortMarked(t *testing.T) {
c := make(chan struct{})
tc := &txnClient{}
tc.mu.waitMarkAllActiveAbortedC = c
tc.mu.state = normal
tc.mu.activeTxns = map[string]*txnOperator{}
go func() {
close(c)
}()
op := &txnOperator{}
require.NoError(t, tc.openTxn(op))
}
3 changes: 1 addition & 2 deletions pkg/txn/client/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"sync/atomic"
"time"

"go.uber.org/zap"

"github.com/matrixorigin/matrixone/pkg/common/log"
"github.com/matrixorigin/matrixone/pkg/common/moerr"
"github.com/matrixorigin/matrixone/pkg/common/runtime"
Expand All @@ -38,6 +36,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/txn/rpc"
"github.com/matrixorigin/matrixone/pkg/txn/util"
v2 "github.com/matrixorigin/matrixone/pkg/util/metric/v2"
"go.uber.org/zap"
)

var (
Expand Down

0 comments on commit fb4cc6f

Please sign in to comment.