diff --git a/store/copr/batch_coprocessor.go b/store/copr/batch_coprocessor.go index 984739d70d954..41591b76de831 100644 --- a/store/copr/batch_coprocessor.go +++ b/store/copr/batch_coprocessor.go @@ -771,6 +771,10 @@ func (b *batchCopIterator) retryBatchCopTask(ctx context.Context, bo *backoff.Ba ranges = append(ranges, *ran) }) } + // need to make sure the key ranges is sorted + sort.Slice(ranges, func(i, j int) bool { + return bytes.Compare(ranges[i].StartKey, ranges[j].StartKey) < 0 + }) return buildBatchCopTasks(bo, b.store, NewKeyRanges(ranges), b.req.StoreType, nil, 0, false, 0) }