Skip to content

Commit

Permalink
store: key ranges should be sorted in batch cop retry (#44623) (#44636)
Browse files Browse the repository at this point in the history
close #44622
  • Loading branch information
ti-chi-bot authored Jun 15, 2023
1 parent c6cf580 commit 7bfa8e6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions store/copr/batch_coprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/tikv/client-go/v2/tikv"
"github.com/tikv/client-go/v2/tikvrpc"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

// batchCopTask comprises of multiple copTask that will send to same store.
Expand Down Expand Up @@ -840,6 +841,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(bo, b.store, NewKeyRanges(ranges), b.req.StoreType, nil, 0, false, 0)
return ret, err
}
Expand All @@ -857,6 +862,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(bo, b.store, keyRanges, b.req.StoreType, nil, 0, false, 0, pid)
Expand Down

0 comments on commit 7bfa8e6

Please sign in to comment.