Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle CloneSnapshotOp DATA RACE #16377

Merged
merged 9 commits into from
May 27, 2024
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
Loading