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

executor: fix data race in GetDirtyTable() #12767

Merged
5 changes: 5 additions & 0 deletions executor/union_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package executor

import (
"context"
"sync"

"github.com/pingcap/errors"
"github.com/pingcap/parser/model"
Expand All @@ -28,12 +29,15 @@ import (
// DirtyDB stores uncommitted write operations for a transaction.
// It is stored and retrieved by context.Value and context.SetValue method.
type DirtyDB struct {
sync.Mutex

// tables is a map whose key is tableID.
tables map[int64]*DirtyTable
}

// GetDirtyTable gets the DirtyTable by id from the DirtyDB.
func (udb *DirtyDB) GetDirtyTable(tid int64) *DirtyTable {
udb.Lock()
eurekaka marked this conversation as resolved.
Show resolved Hide resolved
dt, ok := udb.tables[tid]
if !ok {
dt = &DirtyTable{
Expand All @@ -43,6 +47,7 @@ func (udb *DirtyDB) GetDirtyTable(tid int64) *DirtyTable {
}
udb.tables[tid] = dt
}
udb.Unlock()
return dt
}

Expand Down