Skip to content

Commit

Permalink
executor: fix the issue that tiflash cop throw exception `Income key …
Browse files Browse the repository at this point in the history
…ranges is empty for region: 211` (#52763)

close #52762
  • Loading branch information
SeaRise authored Apr 19, 2024
1 parent d4a8058 commit 6ed747b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pkg/store/copr/coprocessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,12 @@ func TestSplitKeyRangesByLocationsWithoutBuckets(t *testing.T) {
rangeEqual(t, locRanges[1].Ranges.ToRanges(), "g", "h", "h", "m", "n")
rangeEqual(t, locRanges[2].Ranges.ToRanges(), "n", "t")
rangeEqual(t, locRanges[3].Ranges.ToRanges(), "v", "w")

locRanges, err = cache.SplitKeyRangesByLocationsWithoutBuckets(bo, NewKeyRanges(BuildKeyRanges("a", "b", "v", "w")), UnspecifiedLimit)
require.NoError(t, err)
require.Len(t, locRanges, 2)
rangeEqual(t, locRanges[0].Ranges.ToRanges(), "a", "b")
rangeEqual(t, locRanges[1].Ranges.ToRanges(), "v", "w")
}

func TestSplitKeyRanges(t *testing.T) {
Expand Down
11 changes: 7 additions & 4 deletions pkg/store/copr/region_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ func (c *RegionCache) splitKeyRangesByLocation(loc *tikv.KeyLocation, ranges *Ke
}
} else {
// rs[i] is not in the region.
taskRanges := ranges.Slice(0, i)
res = append(res, &LocationKeyRanges{Location: loc, Ranges: taskRanges})
ranges = ranges.Slice(i, ranges.Len())
if i > 0 {
taskRanges := ranges.Slice(0, i)
res = append(res, &LocationKeyRanges{Location: loc, Ranges: taskRanges})
ranges = ranges.Slice(i, ranges.Len())
}
}
return res, ranges, false
}
Expand Down Expand Up @@ -206,12 +208,12 @@ func (c *RegionCache) SplitKeyRangesByLocationsWithoutBuckets(bo *Backoffer, ran
}
res := make([]*LocationKeyRanges, 0, resCap)

nextLocIndex := 0
for ranges.Len() > 0 {
if limit != UnspecifiedLimit && len(res) >= limit {
break
}

nextLocIndex := len(res)
if nextLocIndex >= len(locs) {
err = errors.Errorf("Unexpected loc index %d, which should less than %d", nextLocIndex, len(locs))
return nil, err
Expand All @@ -223,6 +225,7 @@ func (c *RegionCache) SplitKeyRangesByLocationsWithoutBuckets(bo *Backoffer, ran
res = append(res, &LocationKeyRanges{Location: loc, Ranges: ranges})
break
}
nextLocIndex++

isBreak := false
res, ranges, isBreak = c.splitKeyRangesByLocation(loc, ranges, res)
Expand Down

0 comments on commit 6ed747b

Please sign in to comment.