From 42d2f9fd9b4c20aacfeb45cd36b3936dc6f5cac4 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Sun, 25 Jun 2023 11:46:14 +0800 Subject: [PATCH] store: key ranges should be sorted in batch cop retry (#44623) (#44634) close pingcap/tidb#44622 --- store/copr/batch_coprocessor.go | 4 ++++ 1 file changed, 4 insertions(+) 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) }