From 4de1cab422ffdf5076049c5d1aeaaec6a5f742ad Mon Sep 17 00:00:00 2001 From: SeaRise Date: Fri, 19 Apr 2024 18:15:08 +0800 Subject: [PATCH 1/2] This is an automated cherry-pick of #52763 Signed-off-by: ti-chi-bot --- store/copr/coprocessor_test.go | 6 ++++++ store/copr/region_cache.go | 18 +++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/store/copr/coprocessor_test.go b/store/copr/coprocessor_test.go index 2fbfcde027fd1..e7d93f34dd4f8 100644 --- a/store/copr/coprocessor_test.go +++ b/store/copr/coprocessor_test.go @@ -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) { diff --git a/store/copr/region_cache.go b/store/copr/region_cache.go index 5bc656dfa6080..89faa7afc234f 100644 --- a/store/copr/region_cache.go +++ b/store/copr/region_cache.go @@ -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 } @@ -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 @@ -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 { From 1168c155f61a41fda6e8217978a0cfc3fdd0b86f Mon Sep 17 00:00:00 2001 From: SeaRise Date: Mon, 22 Apr 2024 10:37:36 +0800 Subject: [PATCH 2/2] Update region_cache.go --- store/copr/region_cache.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/store/copr/region_cache.go b/store/copr/region_cache.go index 89faa7afc234f..d35cc8c4a32c2 100644 --- a/store/copr/region_cache.go +++ b/store/copr/region_cache.go @@ -255,11 +255,7 @@ func (c *RegionCache) SplitKeyRangesByLocationsWithoutBuckets(bo *Backoffer, ran 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 @@ -271,11 +267,8 @@ 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 {