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

tables: fix data race in mockStatRemoteData #30180

Merged
merged 3 commits into from
Nov 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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