Skip to content

Commit

Permalink
tables: fix data race in mockStatRemoteData
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
  • Loading branch information
hawkingrei committed Nov 26, 2021
1 parent 3dc09f8 commit 16875da
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions table/tables/state_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ func (op *renewLeaseForReadOP) Exec(r *mockStateRemoteData) {
}

type mockStateRemoteData struct {
mu sync.Mutex
data map[int64]*stateRecord
}

Expand All @@ -241,6 +242,8 @@ func newMockStateRemoteData() *mockStateRemoteData {
}

func (r *mockStateRemoteData) Load(tid int64) (CachedTableLockType, uint64, error) {
r.mu.Lock()
defer r.mu.Unlock()
record, ok := r.data[tid]
if !ok {
return CachedTableLockNone, 0, nil
Expand All @@ -249,6 +252,8 @@ func (r *mockStateRemoteData) Load(tid int64) (CachedTableLockType, uint64, erro
}

func (r *mockStateRemoteData) LockForRead(tid int64, now, ts uint64) (bool, error) {
r.mu.Lock()
defer r.mu.Unlock()
record, ok := r.data[tid]
if !ok {
record = &stateRecord{
Expand Down Expand Up @@ -286,6 +291,8 @@ func (r *mockStateRemoteData) LockForRead(tid int64, now, ts uint64) (bool, erro
}

func (r *mockStateRemoteData) LockForWrite(tid int64, now, ts uint64) (uint64, error) {
r.mu.Lock()
defer r.mu.Unlock()
record, ok := r.data[tid]
if !ok {
record = &stateRecord{
Expand Down Expand Up @@ -334,6 +341,8 @@ func (r *mockStateRemoteData) LockForWrite(tid int64, now, ts uint64) (uint64, e
}

func (r *mockStateRemoteData) renewLeaseForRead(tid int64, oldTs uint64, newTs uint64) (bool, error) {
r.mu.Lock()
defer r.mu.Unlock()
record, ok := r.data[tid]
if !ok {
record = &stateRecord{
Expand Down

0 comments on commit 16875da

Please sign in to comment.