diff --git a/store/copr/batch_coprocessor.go b/store/copr/batch_coprocessor.go index dae965d912900..c719aea90b3b0 100644 --- a/store/copr/batch_coprocessor.go +++ b/store/copr/batch_coprocessor.go @@ -768,6 +768,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) }