Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: fix the issue that tiflash cop throw exception Income key ranges is empty for region: 211 (#52763) #52773

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions 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
18 changes: 15 additions & 3 deletions store/copr/region_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,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 @@ -248,11 +250,16 @@ 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
}
<<<<<<< HEAD:store/copr/region_cache.go
nextLocIndex := len(res)
=======

>>>>>>> 6ed747b46da (executor: fix the issue that tiflash cop throw exception `Income key ranges is empty for region: 211` (#52763)):pkg/store/copr/region_cache.go
if nextLocIndex >= len(locs) {
err = errors.Errorf("Unexpected loc index %d, which should less than %d", nextLocIndex, len(locs))
return nil, err
Expand All @@ -264,6 +271,11 @@ func (c *RegionCache) SplitKeyRangesByLocationsWithoutBuckets(bo *Backoffer, ran
res = append(res, &LocationKeyRanges{Location: loc, Ranges: ranges})
break
}
<<<<<<< HEAD:store/copr/region_cache.go
=======
nextLocIndex++

>>>>>>> 6ed747b46da (executor: fix the issue that tiflash cop throw exception `Income key ranges is empty for region: 211` (#52763)):pkg/store/copr/region_cache.go
isBreak := false
res, ranges, isBreak = c.splitKeyRangesByLocation(loc, ranges, res)
if isBreak {
Expand Down