br: fix data race in the RecordStores (#37472)

close pingcap/tidb#37470
This commit is contained in:
Weizhen Wang
2022-08-30 18:28:23 +08:00
committed by GitHub
parent 4cece12c72
commit 8277bd5954
2 changed files with 5 additions and 3 deletions

View File

@ -153,6 +153,7 @@ go_test(
"@org_golang_google_grpc//codes",
"@org_golang_google_grpc//keepalive",
"@org_golang_google_grpc//status",
"@org_golang_x_exp//slices",
"@org_uber_go_goleak//:goleak",
"@org_uber_go_multierr//:multierr",
"@org_uber_go_zap//:zap",

View File

@ -30,6 +30,7 @@ import (
"github.com/pingcap/tidb/tablecodec"
"github.com/stretchr/testify/require"
pd "github.com/tikv/pd/client"
"golang.org/x/exp/slices"
"google.golang.org/grpc/keepalive"
)
@ -424,9 +425,9 @@ func (r *RecordStores) put(id uint64) {
}
func (r *RecordStores) sort() {
sort.Slice(r.stores, func(i, j int) bool {
return r.stores[i] < r.stores[j]
})
r.mu.Lock()
defer r.mu.Unlock()
slices.Sort(r.stores)
}
var recordStores RecordStores