diff --git a/pkg/schedule/schedulers/hot_region.go b/pkg/schedule/schedulers/hot_region.go index c353621bb7fe..4806180e4506 100644 --- a/pkg/schedule/schedulers/hot_region.go +++ b/pkg/schedule/schedulers/hot_region.go @@ -758,6 +758,9 @@ func (bs *balanceSolver) tryAddPendingInfluence() bool { dstStoreID := uint64(0) if isSplit { region := bs.GetRegion(bs.ops[0].RegionID()) + if region == nil { + return false + } for id := range region.GetStoreIDs() { srcStoreIDs = append(srcStoreIDs, id) } diff --git a/pkg/schedule/schedulers/split_bucket.go b/pkg/schedule/schedulers/split_bucket.go index 5e75bded9b43..a08c84372b5d 100644 --- a/pkg/schedule/schedulers/split_bucket.go +++ b/pkg/schedule/schedulers/split_bucket.go @@ -262,6 +262,9 @@ func (s *splitBucketScheduler) splitBucket(plan *splitBucketPlan) []*operator.Op } if splitBucket != nil { region := plan.cluster.GetRegion(splitBucket.RegionID) + if region == nil { + return nil + } splitKey := make([][]byte, 0) if bytes.Compare(region.GetStartKey(), splitBucket.StartKey) < 0 { splitKey = append(splitKey, splitBucket.StartKey) @@ -269,7 +272,7 @@ func (s *splitBucketScheduler) splitBucket(plan *splitBucketPlan) []*operator.Op if bytes.Compare(region.GetEndKey(), splitBucket.EndKey) > 0 { splitKey = append(splitKey, splitBucket.EndKey) } - op, err := operator.CreateSplitRegionOperator(SplitBucketType, plan.cluster.GetRegion(splitBucket.RegionID), operator.OpSplit, + op, err := operator.CreateSplitRegionOperator(SplitBucketType, region, operator.OpSplit, pdpb.CheckPolicy_USEKEY, splitKey) if err != nil { splitBucketCreateOpeartorFailCounter.Inc() diff --git a/pkg/statistics/region_collection.go b/pkg/statistics/region_collection.go index c79eb0a3132c..26cbea9ef92d 100644 --- a/pkg/statistics/region_collection.go +++ b/pkg/statistics/region_collection.go @@ -119,7 +119,11 @@ func (r *RegionStatistics) GetRegionStatsByType(typ RegionStatisticType) []*core defer r.RUnlock() res := make([]*core.RegionInfo, 0, len(r.stats[typ])) for regionID := range r.stats[typ] { - res = append(res, r.rip.GetRegion(regionID).Clone()) + region := r.rip.GetRegion(regionID) + if region == nil { + continue + } + res = append(res, region.Clone()) } return res }