diff --git a/pkg/core/region.go b/pkg/core/region.go index 6875844b7a63..2ac323a12722 100644 --- a/pkg/core/region.go +++ b/pkg/core/region.go @@ -1339,8 +1339,8 @@ func (r *RegionsInfo) GetStoreWriteRate(storeID uint64) (bytesRate, keysRate flo // GetClusterNotFromStorageRegionsCnt gets the total count of regions that not loaded from storage anymore func (r *RegionsInfo) GetClusterNotFromStorageRegionsCnt() int { - r.st.RLock() - defer r.st.RUnlock() + r.t.RLock() + defer r.t.RUnlock() return r.tree.notFromStorageRegionsCnt } diff --git a/pkg/mcs/scheduling/server/cluster.go b/pkg/mcs/scheduling/server/cluster.go index 09ae4ede5281..0c4e781e7471 100644 --- a/pkg/mcs/scheduling/server/cluster.go +++ b/pkg/mcs/scheduling/server/cluster.go @@ -206,7 +206,7 @@ func (c *Cluster) AllocID() (uint64, error) { defer cancel() resp, err := client.AllocID(ctx, &pdpb.AllocIDRequest{Header: &pdpb.RequestHeader{ClusterId: c.clusterID}}) if err != nil { - c.checkMembershipCh <- struct{}{} + c.triggerMembershipCheck() return 0, err } return resp.GetId(), nil @@ -215,12 +215,19 @@ func (c *Cluster) AllocID() (uint64, error) { func (c *Cluster) getAPIServerLeaderClient() (pdpb.PDClient, error) { cli := c.apiServerLeader.Load() if cli == nil { - c.checkMembershipCh <- struct{}{} + c.triggerMembershipCheck() return nil, errors.New("API server leader is not found") } return cli.(pdpb.PDClient), nil } +func (c *Cluster) triggerMembershipCheck() { + select { + case c.checkMembershipCh <- struct{}{}: + default: // avoid blocking + } +} + // SwitchAPIServerLeader switches the API server leader. func (c *Cluster) SwitchAPIServerLeader(new pdpb.PDClient) bool { old := c.apiServerLeader.Load()