From 8e844d8483655ca3cd902220c372621c6c14cb43 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Wed, 27 Sep 2023 16:43:47 +0800 Subject: [PATCH] *: use syncutil lock (#7157) ref tikv/pd#4399 Signed-off-by: Ryan Leung Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- pkg/balancer/round_robin.go | 5 +++-- pkg/btree/btree_generic.go | 5 +++-- pkg/btree/btree_generic_test.go | 6 ++++-- pkg/election/leadership.go | 4 ++-- pkg/keyspace/tso_keyspace_group.go | 3 ++- pkg/mcs/resourcemanager/server/manager.go | 4 ++-- pkg/mcs/resourcemanager/server/resource_group.go | 4 ++-- pkg/memory/meminfo.go | 10 +++++----- pkg/ratelimit/limiter_test.go | 11 ++++++----- pkg/schedule/schedulers/scheduler_controller.go | 3 ++- pkg/statistics/region_collection.go | 6 +++--- pkg/tso/keyspace_group_manager.go | 3 ++- pkg/tso/keyspace_group_manager_test.go | 7 ++++--- pkg/utils/etcdutil/etcdutil.go | 3 ++- pkg/utils/etcdutil/etcdutil_test.go | 9 +++++---- pkg/utils/tempurl/tempurl.go | 4 ++-- server/apiv2/handlers/tso_keyspace_group.go | 4 ++-- server/grpc_service.go | 3 ++- server/server.go | 5 +++-- tests/cluster.go | 9 +++++---- tests/integrations/client/global_config_test.go | 4 ++-- tests/server/id/id_test.go | 3 ++- tests/server/tso/consistency_test.go | 3 ++- 23 files changed, 67 insertions(+), 51 deletions(-) diff --git a/pkg/balancer/round_robin.go b/pkg/balancer/round_robin.go index 5013a447d3e..51abb575481 100644 --- a/pkg/balancer/round_robin.go +++ b/pkg/balancer/round_robin.go @@ -15,13 +15,14 @@ package balancer import ( - "sync" "sync/atomic" + + "github.com/tikv/pd/pkg/utils/syncutil" ) // RoundRobin is a balancer that selects nodes in a round-robin fashion. type RoundRobin[T uint32 | string] struct { - sync.RWMutex + syncutil.RWMutex nodes []T exists map[T]struct{} next uint32 diff --git a/pkg/btree/btree_generic.go b/pkg/btree/btree_generic.go index 634a24b5bd8..630cb25abcd 100644 --- a/pkg/btree/btree_generic.go +++ b/pkg/btree/btree_generic.go @@ -78,7 +78,8 @@ package btree import ( "sort" - "sync" + + "github.com/tikv/pd/pkg/utils/syncutil" ) // Item represents a single object in the tree. @@ -101,7 +102,7 @@ const ( // FreeList, in particular when they're created with Clone. // Two Btrees using the same freelist are safe for concurrent write access. type FreeListG[T Item[T]] struct { - mu sync.Mutex + mu syncutil.Mutex freelist []*node[T] } diff --git a/pkg/btree/btree_generic_test.go b/pkg/btree/btree_generic_test.go index 228269056a9..751fb2744e9 100644 --- a/pkg/btree/btree_generic_test.go +++ b/pkg/btree/btree_generic_test.go @@ -36,6 +36,8 @@ import ( "sort" "sync" "testing" + + "github.com/tikv/pd/pkg/utils/syncutil" ) // perm returns a random permutation of n Int items in the range [0, n). @@ -752,7 +754,7 @@ func BenchmarkDescendLessOrEqual(b *testing.B) { const cloneTestSize = 10000 -func cloneTestG[T Item[T]](t *testing.T, b *BTreeG[T], start int, p []T, wg *sync.WaitGroup, trees *[]*BTreeG[T], lock *sync.Mutex) { +func cloneTestG[T Item[T]](t *testing.T, b *BTreeG[T], start int, p []T, wg *sync.WaitGroup, trees *[]*BTreeG[T], lock *syncutil.Mutex) { t.Logf("Starting new clone at %v", start) lock.Lock() *trees = append(*trees, b) @@ -773,7 +775,7 @@ func TestCloneConcurrentOperationsG(t *testing.T) { p := perm(cloneTestSize) var wg sync.WaitGroup wg.Add(1) - go cloneTestG(t, b, 0, p, &wg, &trees, &sync.Mutex{}) + go cloneTestG(t, b, 0, p, &wg, &trees, &syncutil.Mutex{}) wg.Wait() want := rang(cloneTestSize) t.Logf("Starting equality checks on %d trees", len(trees)) diff --git a/pkg/election/leadership.go b/pkg/election/leadership.go index 692344eb52a..d5d73e90b58 100644 --- a/pkg/election/leadership.go +++ b/pkg/election/leadership.go @@ -16,7 +16,6 @@ package election import ( "context" - "sync" "sync/atomic" "time" @@ -27,6 +26,7 @@ import ( "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/grpcutil" + "github.com/tikv/pd/pkg/utils/syncutil" "go.etcd.io/etcd/clientv3" "go.etcd.io/etcd/mvcc/mvccpb" "go.uber.org/zap" @@ -61,7 +61,7 @@ type Leadership struct { keepAliveCtx context.Context keepAliveCancelFunc context.CancelFunc - keepAliveCancelFuncLock sync.Mutex + keepAliveCancelFuncLock syncutil.Mutex } // NewLeadership creates a new Leadership. diff --git a/pkg/keyspace/tso_keyspace_group.go b/pkg/keyspace/tso_keyspace_group.go index a092e5b18a6..c8694c4a7c6 100644 --- a/pkg/keyspace/tso_keyspace_group.go +++ b/pkg/keyspace/tso_keyspace_group.go @@ -35,6 +35,7 @@ import ( "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/logutil" + "github.com/tikv/pd/pkg/utils/syncutil" "go.etcd.io/etcd/clientv3" "go.etcd.io/etcd/mvcc/mvccpb" "go.uber.org/zap" @@ -60,7 +61,7 @@ type GroupManager struct { client *clientv3.Client clusterID uint64 - sync.RWMutex + syncutil.RWMutex // groups is the cache of keyspace group related information. // user kind -> keyspace group groups map[endpoint.UserKind]*indexedHeap diff --git a/pkg/mcs/resourcemanager/server/manager.go b/pkg/mcs/resourcemanager/server/manager.go index 1731faf8af1..03db817cf12 100644 --- a/pkg/mcs/resourcemanager/server/manager.go +++ b/pkg/mcs/resourcemanager/server/manager.go @@ -20,7 +20,6 @@ import ( "math" "sort" "strings" - "sync" "time" "github.com/gogo/protobuf/proto" @@ -34,6 +33,7 @@ import ( "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/jsonutil" "github.com/tikv/pd/pkg/utils/logutil" + "github.com/tikv/pd/pkg/utils/syncutil" "go.uber.org/zap" ) @@ -49,7 +49,7 @@ const ( // Manager is the manager of resource group. type Manager struct { - sync.RWMutex + syncutil.RWMutex srv bs.Server controllerConfig *ControllerConfig groups map[string]*ResourceGroup diff --git a/pkg/mcs/resourcemanager/server/resource_group.go b/pkg/mcs/resourcemanager/server/resource_group.go index 74bc463002b..863cfd19026 100644 --- a/pkg/mcs/resourcemanager/server/resource_group.go +++ b/pkg/mcs/resourcemanager/server/resource_group.go @@ -17,19 +17,19 @@ package server import ( "encoding/json" - "sync" "time" "github.com/pingcap/errors" rmpb "github.com/pingcap/kvproto/pkg/resource_manager" "github.com/pingcap/log" "github.com/tikv/pd/pkg/storage/endpoint" + "github.com/tikv/pd/pkg/utils/syncutil" "go.uber.org/zap" ) // ResourceGroup is the definition of a resource group, for REST API. type ResourceGroup struct { - sync.RWMutex + syncutil.RWMutex Name string `json:"name"` Mode rmpb.GroupMode `json:"mode"` // RU settings diff --git a/pkg/memory/meminfo.go b/pkg/memory/meminfo.go index 0981ddacdfb..5a81cf57d3d 100644 --- a/pkg/memory/meminfo.go +++ b/pkg/memory/meminfo.go @@ -15,7 +15,6 @@ package memory import ( - "sync" "time" "github.com/pingcap/failpoint" @@ -23,6 +22,7 @@ import ( "github.com/pingcap/sysutil" "github.com/shirou/gopsutil/v3/mem" "github.com/tikv/pd/pkg/cgroup" + "github.com/tikv/pd/pkg/utils/syncutil" "go.uber.org/zap" "golang.org/x/exp/constraints" ) @@ -76,7 +76,7 @@ func MemUsedNormal() (uint64, error) { type memInfoCache struct { updateTime time.Time - mu *sync.RWMutex + mu *syncutil.RWMutex mem uint64 } @@ -168,13 +168,13 @@ func init() { MemUsed = MemUsedNormal } memLimit = &memInfoCache{ - mu: &sync.RWMutex{}, + mu: &syncutil.RWMutex{}, } memUsage = &memInfoCache{ - mu: &sync.RWMutex{}, + mu: &syncutil.RWMutex{}, } serverMemUsage = &memInfoCache{ - mu: &sync.RWMutex{}, + mu: &syncutil.RWMutex{}, } _, err := MemTotal() mustNil(err) diff --git a/pkg/ratelimit/limiter_test.go b/pkg/ratelimit/limiter_test.go index 6443028eec6..d5d9829816a 100644 --- a/pkg/ratelimit/limiter_test.go +++ b/pkg/ratelimit/limiter_test.go @@ -20,6 +20,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/syncutil" "golang.org/x/time/rate" ) @@ -33,7 +34,7 @@ func TestUpdateConcurrencyLimiter(t *testing.T) { label := "test" status := limiter.Update(label, opts...) re.True(status&ConcurrencyChanged != 0) - var lock sync.Mutex + var lock syncutil.Mutex successCount, failedCount := 0, 0 var wg sync.WaitGroup for i := 0; i < 15; i++ { @@ -118,7 +119,7 @@ func TestUpdateQPSLimiter(t *testing.T) { status := limiter.Update(label, opts...) re.True(status&QPSChanged != 0) - var lock sync.Mutex + var lock syncutil.Mutex successCount, failedCount := 0, 0 var wg sync.WaitGroup wg.Add(3) @@ -173,7 +174,7 @@ func TestQPSLimiter(t *testing.T) { opt(label, limiter) } - var lock sync.Mutex + var lock syncutil.Mutex successCount, failedCount := 0, 0 var wg sync.WaitGroup wg.Add(200) @@ -208,7 +209,7 @@ func TestTwoLimiters(t *testing.T) { opt(label, limiter) } - var lock sync.Mutex + var lock syncutil.Mutex successCount, failedCount := 0, 0 var wg sync.WaitGroup wg.Add(200) @@ -245,7 +246,7 @@ func TestTwoLimiters(t *testing.T) { } func countRateLimiterHandleResult(limiter *Limiter, label string, successCount *int, - failedCount *int, lock *sync.Mutex, wg *sync.WaitGroup) { + failedCount *int, lock *syncutil.Mutex, wg *sync.WaitGroup) { result := limiter.Allow(label) lock.Lock() defer lock.Unlock() diff --git a/pkg/schedule/schedulers/scheduler_controller.go b/pkg/schedule/schedulers/scheduler_controller.go index 4d72699b0fe..4f22f50f81d 100644 --- a/pkg/schedule/schedulers/scheduler_controller.go +++ b/pkg/schedule/schedulers/scheduler_controller.go @@ -30,6 +30,7 @@ import ( "github.com/tikv/pd/pkg/schedule/plan" "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/utils/logutil" + "github.com/tikv/pd/pkg/utils/syncutil" "go.uber.org/zap" ) @@ -39,7 +40,7 @@ var denySchedulersByLabelerCounter = labeler.LabelerEventCounter.WithLabelValues // Controller is used to manage all schedulers. type Controller struct { - sync.RWMutex + syncutil.RWMutex wg sync.WaitGroup ctx context.Context cluster sche.SchedulerCluster diff --git a/pkg/statistics/region_collection.go b/pkg/statistics/region_collection.go index 6d3ac3f1760..c79eb0a3132 100644 --- a/pkg/statistics/region_collection.go +++ b/pkg/statistics/region_collection.go @@ -15,13 +15,13 @@ package statistics import ( - "sync" "time" "github.com/pingcap/log" "github.com/tikv/pd/pkg/core" sc "github.com/tikv/pd/pkg/schedule/config" "github.com/tikv/pd/pkg/schedule/placement" + "github.com/tikv/pd/pkg/utils/syncutil" ) // RegionInfoProvider is an interface to provide the region information. @@ -85,7 +85,7 @@ type RegionInfoWithTS struct { // RegionStatistics is used to record the status of regions. type RegionStatistics struct { - sync.RWMutex + syncutil.RWMutex rip RegionInfoProvider conf sc.CheckerConfigProvider stats map[RegionStatisticType]map[uint64]*RegionInfoWithTS @@ -284,7 +284,7 @@ func (r *RegionStatistics) Reset() { // LabelStatistics is the statistics of the level of labels. type LabelStatistics struct { - sync.RWMutex + syncutil.RWMutex regionLabelStats map[uint64]string labelCounter map[string]int } diff --git a/pkg/tso/keyspace_group_manager.go b/pkg/tso/keyspace_group_manager.go index 3b352884eab..badcb18d5d8 100644 --- a/pkg/tso/keyspace_group_manager.go +++ b/pkg/tso/keyspace_group_manager.go @@ -43,6 +43,7 @@ import ( "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/memberutil" + "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/tsoutil" "github.com/tikv/pd/pkg/utils/typeutil" "go.etcd.io/etcd/clientv3" @@ -62,7 +63,7 @@ const ( ) type state struct { - sync.RWMutex + syncutil.RWMutex // ams stores the allocator managers of the keyspace groups. Each keyspace group is // assigned with an allocator manager managing its global/local tso allocators. // Use a fixed size array to maximize the efficiency of concurrent access to diff --git a/pkg/tso/keyspace_group_manager_test.go b/pkg/tso/keyspace_group_manager_test.go index 91c68a5a268..c20abfc5f79 100644 --- a/pkg/tso/keyspace_group_manager_test.go +++ b/pkg/tso/keyspace_group_manager_test.go @@ -36,6 +36,7 @@ import ( mcsutils "github.com/tikv/pd/pkg/mcs/utils" "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/utils/etcdutil" + "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/tempurl" "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/pkg/utils/tsoutil" @@ -751,7 +752,7 @@ func (suite *keyspaceGroupManagerTestSuite) runTestLoadKeyspaceGroupsAssignment( defer mgr.Close() step := 30 - mux := sync.Mutex{} + mux := syncutil.Mutex{} wg := sync.WaitGroup{} for i := 0; i < numberOfKeyspaceGroupsToAdd; i += step { wg.Add(1) @@ -872,12 +873,12 @@ func addKeyspaceGroupAssignment( groupID uint32, rootPath string, svcAddrs []string, - priorites []int, + priorities []int, keyspaces []uint32, ) error { members := make([]endpoint.KeyspaceGroupMember, len(svcAddrs)) for i, svcAddr := range svcAddrs { - members[i] = endpoint.KeyspaceGroupMember{Address: svcAddr, Priority: priorites[i]} + members[i] = endpoint.KeyspaceGroupMember{Address: svcAddr, Priority: priorities[i]} } group := &endpoint.KeyspaceGroup{ ID: groupID, diff --git a/pkg/utils/etcdutil/etcdutil.go b/pkg/utils/etcdutil/etcdutil.go index 336e0593f8a..1432b6e37c3 100644 --- a/pkg/utils/etcdutil/etcdutil.go +++ b/pkg/utils/etcdutil/etcdutil.go @@ -31,6 +31,7 @@ import ( "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/grpcutil" "github.com/tikv/pd/pkg/utils/logutil" + "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/typeutil" "go.etcd.io/etcd/clientv3" "go.etcd.io/etcd/etcdserver" @@ -566,7 +567,7 @@ type LoopWatcher struct { postEventFn func() error // forceLoadMu is used to ensure two force loads have minimal interval. - forceLoadMu sync.RWMutex + forceLoadMu syncutil.RWMutex // lastTimeForceLoad is used to record the last time force loading data from etcd. lastTimeForceLoad time.Time diff --git a/pkg/utils/etcdutil/etcdutil_test.go b/pkg/utils/etcdutil/etcdutil_test.go index 80194a6287e..f7fadd3bbf6 100644 --- a/pkg/utils/etcdutil/etcdutil_test.go +++ b/pkg/utils/etcdutil/etcdutil_test.go @@ -31,6 +31,7 @@ import ( "github.com/pingcap/failpoint" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/tempurl" "github.com/tikv/pd/pkg/utils/testutil" "go.etcd.io/etcd/clientv3" @@ -398,7 +399,7 @@ func (suite *loopWatcherTestSuite) TearDownSuite() { func (suite *loopWatcherTestSuite) TestLoadWithoutKey() { cache := struct { - sync.RWMutex + syncutil.RWMutex data map[string]struct{} }{ data: make(map[string]struct{}), @@ -428,7 +429,7 @@ func (suite *loopWatcherTestSuite) TestLoadWithoutKey() { func (suite *loopWatcherTestSuite) TestCallBack() { cache := struct { - sync.RWMutex + syncutil.RWMutex data map[string]struct{} }{ data: make(map[string]struct{}), @@ -494,7 +495,7 @@ func (suite *loopWatcherTestSuite) TestWatcherLoadLimit() { suite.put(fmt.Sprintf("TestWatcherLoadLimit%d", i), "") } cache := struct { - sync.RWMutex + syncutil.RWMutex data []string }{ data: make([]string, 0), @@ -532,7 +533,7 @@ func (suite *loopWatcherTestSuite) TestWatcherLoadLimit() { func (suite *loopWatcherTestSuite) TestWatcherBreak() { cache := struct { - sync.RWMutex + syncutil.RWMutex data string }{} checkCache := func(expect string) { diff --git a/pkg/utils/tempurl/tempurl.go b/pkg/utils/tempurl/tempurl.go index 4b3a680bd14..421513ff001 100644 --- a/pkg/utils/tempurl/tempurl.go +++ b/pkg/utils/tempurl/tempurl.go @@ -17,15 +17,15 @@ package tempurl import ( "fmt" "net" - "sync" "time" "github.com/pingcap/log" "github.com/tikv/pd/pkg/errs" + "github.com/tikv/pd/pkg/utils/syncutil" ) var ( - testAddrMutex sync.Mutex + testAddrMutex syncutil.Mutex testAddrMap = make(map[string]struct{}) ) diff --git a/server/apiv2/handlers/tso_keyspace_group.go b/server/apiv2/handlers/tso_keyspace_group.go index 1e64e125038..a580b21f705 100644 --- a/server/apiv2/handlers/tso_keyspace_group.go +++ b/server/apiv2/handlers/tso_keyspace_group.go @@ -18,7 +18,6 @@ import ( "net/http" "strconv" "strings" - "sync" "github.com/gin-gonic/gin" "github.com/pingcap/errors" @@ -26,6 +25,7 @@ import ( "github.com/tikv/pd/pkg/mcs/utils" "github.com/tikv/pd/pkg/slice" "github.com/tikv/pd/pkg/storage/endpoint" + "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/server" "github.com/tikv/pd/server/apiv2/middlewares" ) @@ -210,7 +210,7 @@ type SplitKeyspaceGroupByIDParams struct { } var patrolKeyspaceAssignmentState struct { - sync.RWMutex + syncutil.RWMutex patrolled bool } diff --git a/server/grpc_service.go b/server/grpc_service.go index dd53416d30d..febb666c22d 100644 --- a/server/grpc_service.go +++ b/server/grpc_service.go @@ -42,6 +42,7 @@ import ( "github.com/tikv/pd/pkg/tso" "github.com/tikv/pd/pkg/utils/grpcutil" "github.com/tikv/pd/pkg/utils/logutil" + "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/tsoutil" "github.com/tikv/pd/pkg/versioninfo" "github.com/tikv/pd/server/cluster" @@ -199,7 +200,7 @@ func (s *GrpcServer) GetMinTSFromTSOService(dcLocation string) (*pdpb.Timestamp, } // Get the minimal timestamp from the TSO servers/pods - var mutex sync.Mutex + var mutex syncutil.Mutex resps := make([]*tsopb.GetMinTSResponse, len(addrs)) wg := sync.WaitGroup{} wg.Add(len(addrs)) diff --git a/server/server.go b/server/server.go index ca131debb29..d3fe5446a03 100644 --- a/server/server.go +++ b/server/server.go @@ -73,6 +73,7 @@ import ( "github.com/tikv/pd/pkg/utils/grpcutil" "github.com/tikv/pd/pkg/utils/jsonutil" "github.com/tikv/pd/pkg/utils/logutil" + "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/tsoutil" "github.com/tikv/pd/pkg/utils/typeutil" "github.com/tikv/pd/pkg/versioninfo" @@ -201,7 +202,7 @@ type Server struct { clientConns sync.Map tsoClientPool struct { - sync.RWMutex + syncutil.RWMutex clients map[string]tsopb.TSO_TsoClient } @@ -259,7 +260,7 @@ func CreateServer(ctx context.Context, cfg *config.Config, services []string, le DiagnosticsServer: sysutil.NewDiagnosticsServer(cfg.Log.File.Filename), mode: mode, tsoClientPool: struct { - sync.RWMutex + syncutil.RWMutex clients map[string]tsopb.TSO_TsoClient }{ clients: make(map[string]tsopb.TSO_TsoClient), diff --git a/tests/cluster.go b/tests/cluster.go index c49f3cd982d..5b1cb7f06fc 100644 --- a/tests/cluster.go +++ b/tests/cluster.go @@ -39,6 +39,7 @@ import ( "github.com/tikv/pd/pkg/swaggerserver" "github.com/tikv/pd/pkg/tso" "github.com/tikv/pd/pkg/utils/logutil" + "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/server" "github.com/tikv/pd/server/api" @@ -68,7 +69,7 @@ var ( // TestServer is only for test. type TestServer struct { - sync.RWMutex + syncutil.RWMutex server *server.Server grpcServer *server.GrpcServer state int32 @@ -445,7 +446,7 @@ type TestCluster struct { servers map[string]*TestServer // tsPool is used to check the TSO uniqueness among the test cluster tsPool struct { - sync.Mutex + syncutil.Mutex pool map[uint64]struct{} } schedulingCluster *TestSchedulingCluster @@ -491,7 +492,7 @@ func createTestCluster(ctx context.Context, initialServerCount int, isAPIService config: config, servers: servers, tsPool: struct { - sync.Mutex + syncutil.Mutex pool map[uint64]struct{} }{ pool: make(map[uint64]struct{}), @@ -512,7 +513,7 @@ func restartTestCluster( config: cluster.config, servers: make(map[string]*TestServer, len(cluster.servers)), tsPool: struct { - sync.Mutex + syncutil.Mutex pool map[uint64]struct{} }{ pool: make(map[uint64]struct{}), diff --git a/tests/integrations/client/global_config_test.go b/tests/integrations/client/global_config_test.go index 83a3384b92f..bfe432807ce 100644 --- a/tests/integrations/client/global_config_test.go +++ b/tests/integrations/client/global_config_test.go @@ -17,7 +17,6 @@ package client_test import ( "path" "strconv" - "sync" "testing" "time" @@ -28,6 +27,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "github.com/tikv/pd/pkg/utils/assertutil" + "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/server" "go.uber.org/zap" @@ -54,7 +54,7 @@ type globalConfigTestSuite struct { server *server.GrpcServer client pd.Client cleanup testutil.CleanupFunc - mu sync.Mutex + mu syncutil.Mutex } func TestGlobalConfigTestSuite(t *testing.T) { diff --git a/tests/server/id/id_test.go b/tests/server/id/id_test.go index 737aa4deac2..4742424d9b5 100644 --- a/tests/server/id/id_test.go +++ b/tests/server/id/id_test.go @@ -21,6 +21,7 @@ import ( "github.com/pingcap/kvproto/pkg/pdpb" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/tests" "go.uber.org/goleak" @@ -55,7 +56,7 @@ func TestID(t *testing.T) { var wg sync.WaitGroup - var m sync.Mutex + var m syncutil.Mutex ids := make(map[uint64]struct{}) for i := 0; i < 10; i++ { diff --git a/tests/server/tso/consistency_test.go b/tests/server/tso/consistency_test.go index 9cfadbf5ba3..c50b791b47f 100644 --- a/tests/server/tso/consistency_test.go +++ b/tests/server/tso/consistency_test.go @@ -28,6 +28,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/tikv/pd/pkg/tso" "github.com/tikv/pd/pkg/utils/grpcutil" + "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/pkg/utils/tsoutil" "github.com/tikv/pd/server/config" @@ -42,7 +43,7 @@ type tsoConsistencyTestSuite struct { leaderServer *tests.TestServer dcClientMap map[string]pdpb.PDClient - tsPoolMutex sync.Mutex + tsPoolMutex syncutil.Mutex tsPool map[uint64]struct{} }