Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx committed Oct 24, 2023
1 parent 55dd28e commit c209d34
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pkg/schedule/scatter/region_scatterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ var (
scatterUnnecessaryCounter = scatterCounter.WithLabelValues("unnecessary", "")
scatterFailCounter = scatterCounter.WithLabelValues("fail", "")
scatterSuccessCounter = scatterCounter.WithLabelValues("success", "")
errRegionNotFound = errors.New("region not found")
errEmptyRegion = errors.New("empty region")
)

const (
Expand Down Expand Up @@ -165,7 +167,7 @@ func (r *RegionScatterer) ScatterRegionsByRange(startKey, endKey []byte, group s
regions := r.cluster.ScanRegions(startKey, endKey, -1)
if len(regions) < 1 {
scatterSkipEmptyRegionCounter.Inc()
return 0, nil, errors.New("empty region")
return 0, nil, errEmptyRegion
}
failures := make(map[uint64]error, len(regions))
regionMap := make(map[uint64]*core.RegionInfo, len(regions))
Expand All @@ -184,17 +186,18 @@ func (r *RegionScatterer) ScatterRegionsByRange(startKey, endKey []byte, group s
func (r *RegionScatterer) ScatterRegionsByID(regionsID []uint64, group string, retryLimit int, skipStoreLimit bool) (int, map[uint64]error, error) {
if len(regionsID) < 1 {
scatterSkipEmptyRegionCounter.Inc()
return 0, nil, errors.New("empty region")
return 0, nil, errEmptyRegion
}
if len(regionsID) == 1 {
scatterSkipNoRegionCounter.Inc()
return 0, nil, errRegionNotFound
}
failures := make(map[uint64]error, len(regionsID))
regions := make([]*core.RegionInfo, 0, len(regionsID))
for _, id := range regionsID {
region := r.cluster.GetRegion(id)
if region == nil {
scatterSkipNoRegionCounter.Inc()
if len(regionsID) == 1 {
return 0, nil, errors.New("region not found")
}
log.Warn("failed to find region during scatter", zap.Uint64("region-id", id))
failures[id] = errors.New(fmt.Sprintf("failed to find region %v", id))
continue
Expand Down Expand Up @@ -222,7 +225,7 @@ func (r *RegionScatterer) ScatterRegionsByID(regionsID []uint64, group string, r
func (r *RegionScatterer) scatterRegions(regions map[uint64]*core.RegionInfo, failures map[uint64]error, group string, retryLimit int, skipStoreLimit bool) (int, error) {
if len(regions) < 1 {
scatterSkipEmptyRegionCounter.Inc()
return 0, errors.New("empty region")
return 0, errEmptyRegion
}
if retryLimit > maxRetryLimit {
retryLimit = maxRetryLimit
Expand Down

0 comments on commit c209d34

Please sign in to comment.