From f9ad7b5665a92b36104f8f02bc9d5b2c56b4beb3 Mon Sep 17 00:00:00 2001 From: xufei Date: Tue, 13 Jun 2023 17:17:57 +0800 Subject: [PATCH] key ranges should be sorted in batch cop retry Signed-off-by: xufei --- store/copr/batch_coprocessor.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/store/copr/batch_coprocessor.go b/store/copr/batch_coprocessor.go index 957f120b4568c..c0b1412597272 100644 --- a/store/copr/batch_coprocessor.go +++ b/store/copr/batch_coprocessor.go @@ -1099,6 +1099,10 @@ func (b *batchCopIterator) retryBatchCopTask(ctx context.Context, bo *backoff.Ba ranges = append(ranges, *ran) }) } + // need to make sure the key ranges is sorted + slices.SortFunc(ranges, func(i, j kv.KeyRange) bool { + return bytes.Compare(i.StartKey, j.StartKey) < 0 + }) ret, err := buildBatchCopTasksForNonPartitionedTable(ctx, bo, b.store, NewKeyRanges(ranges), b.req.StoreType, false, 0, false, 0, tiflashcompute.DispatchPolicyInvalid) return ret, err } @@ -1116,6 +1120,10 @@ func (b *batchCopIterator) retryBatchCopTask(ctx context.Context, bo *backoff.Ba }) } } + // need to make sure the key ranges is sorted + slices.SortFunc(ranges, func(i, j kv.KeyRange) bool { + return bytes.Compare(i.StartKey, j.StartKey) < 0 + }) keyRanges = append(keyRanges, NewKeyRanges(ranges)) } ret, err := buildBatchCopTasksForPartitionedTable(ctx, bo, b.store, keyRanges, b.req.StoreType, false, 0, false, 0, pid, tiflashcompute.DispatchPolicyInvalid)