Skip to content

Commit

Permalink
handle CloneSnapshotOp DATA RACE (matrixorigin#16377)
Browse files Browse the repository at this point in the history
  • Loading branch information
qingxinhome committed May 29, 2024
1 parent 4137463 commit a2433c3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/txn/client/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,7 @@ type txnOperator struct {
lockService lockservice.LockService
sequence atomic.Uint64
createTs timestamp.Timestamp
//read-only txn operators for supporting snapshot read feature.
children []*txnOperator
parent atomic.Pointer[txnOperator]
parent atomic.Pointer[txnOperator]

mu struct {
sync.RWMutex
Expand All @@ -231,6 +229,8 @@ type txnOperator struct {
retry bool
lockSeq uint64
waitLocks map[uint64]Lock
//read-only txn operators for supporting snapshot read feature.
children []*txnOperator
}

commitCounter counter
Expand Down Expand Up @@ -282,7 +282,10 @@ func (tc *txnOperator) CloneSnapshotOp(snapshot timestamp.Timestamp) TxnOperator
op.workspace = tc.workspace.CloneSnapshotWS()
op.workspace.BindTxnOp(op)

tc.children = append(tc.children, op)
tc.mu.Lock()
defer tc.mu.Unlock()
tc.mu.children = append(tc.mu.children, op)

op.parent.Store(tc)
return op
}
Expand Down

0 comments on commit a2433c3

Please sign in to comment.