diff --git a/ddl/index.go b/ddl/index.go index 2d3b2ef5cd9c4..df8f77be9d5a5 100644 --- a/ddl/index.go +++ b/ddl/index.go @@ -16,12 +16,14 @@ package ddl import ( "bytes" + "cmp" "context" "encoding/hex" "encoding/json" "fmt" "os" "path/filepath" + "slices" "strings" "sync" "sync/atomic" @@ -61,7 +63,6 @@ import ( "github.com/tikv/client-go/v2/tikv" kvutil "github.com/tikv/client-go/v2/util" "go.uber.org/zap" - "golang.org/x/exp/slices" "golang.org/x/sync/errgroup" ) @@ -1152,7 +1153,7 @@ func RemoveDependentHiddenColumns(tblInfo *model.TableInfo, idxInfo *model.Index } } // Sort the offset in descending order. - slices.SortFunc(hiddenColOffs, func(a, b int) bool { return a > b }) + slices.SortFunc(hiddenColOffs, func(a, b int) int { return cmp.Compare(b, a) }) // Move all the dependent hidden columns to the end. endOffset := len(tblInfo.Columns) - 1 for _, offset := range hiddenColOffs { diff --git a/executor/table_reader.go b/executor/table_reader.go index bb5cb867a19f3..a4c015a174754 100644 --- a/executor/table_reader.go +++ b/executor/table_reader.go @@ -343,8 +343,8 @@ func (e *TableReaderExecutor) buildResp(ctx context.Context, ranges []*ranger.Ra if err != nil { return nil, err } - kvReq.KeyRanges.SortByFunc(func(i, j kv.KeyRange) bool { - return bytes.Compare(i.StartKey, j.StartKey) < 0 + kvReq.KeyRanges.SortByFunc(func(i, j kv.KeyRange) int { + return bytes.Compare(i.StartKey, j.StartKey) }) e.kvRanges = kvReq.KeyRanges.AppendSelfTo(e.kvRanges) diff --git a/kv/BUILD.bazel b/kv/BUILD.bazel index 1cf88273fdb78..76bc2d668d1b4 100644 --- a/kv/BUILD.bazel +++ b/kv/BUILD.bazel @@ -53,7 +53,6 @@ go_library( "@com_github_tikv_client_go_v2//tikvrpc/interceptor", "@com_github_tikv_client_go_v2//util", "@com_github_tikv_pd_client//:client", - "@org_golang_x_exp//slices", "@org_uber_go_atomic//:atomic", "@org_uber_go_zap//:zap", ], diff --git a/kv/kv.go b/kv/kv.go index d6fa06a9aa6d7..ec9570e83e120 100644 --- a/kv/kv.go +++ b/kv/kv.go @@ -18,6 +18,7 @@ import ( "bytes" "context" "crypto/tls" + "slices" "time" "github.com/pingcap/errors" @@ -37,7 +38,6 @@ import ( "github.com/tikv/client-go/v2/util" pd "github.com/tikv/pd/client" "go.uber.org/atomic" - "golang.org/x/exp/slices" ) // UnCommitIndexKVFlag uses to indicate the index key/value is no need to commit. @@ -427,20 +427,20 @@ func (rr *KeyRanges) AppendSelfTo(ranges []KeyRange) []KeyRange { // SortByFunc sorts each partition's ranges. // Since the ranges are sorted in most cases, we check it first. -func (rr *KeyRanges) SortByFunc(sortFunc func(i, j KeyRange) bool) { - if !slices.IsSortedFunc(rr.ranges, func(i, j []KeyRange) bool { +func (rr *KeyRanges) SortByFunc(sortFunc func(i, j KeyRange) int) { + if !slices.IsSortedFunc(rr.ranges, func(i, j []KeyRange) int { // A simple short-circuit since the empty range actually won't make anything wrong. if len(i) == 0 || len(j) == 0 { - return true + return -1 } return sortFunc(i[0], j[0]) }) { - slices.SortFunc(rr.ranges, func(i, j []KeyRange) bool { + slices.SortFunc(rr.ranges, func(i, j []KeyRange) int { if len(i) == 0 { - return true + return -1 } if len(j) == 0 { - return false + return 1 } return sortFunc(i[0], j[0]) }) @@ -481,19 +481,19 @@ func (rr *KeyRanges) PartitionNum() int { // IsFullySorted checks whether the ranges are sorted inside partition and each partition is also sorated. func (rr *KeyRanges) IsFullySorted() bool { - sortedByPartition := slices.IsSortedFunc(rr.ranges, func(i, j []KeyRange) bool { + sortedByPartition := slices.IsSortedFunc(rr.ranges, func(i, j []KeyRange) int { // A simple short-circuit since the empty range actually won't make anything wrong. if len(i) == 0 || len(j) == 0 { - return true + return -1 } - return bytes.Compare(i[0].StartKey, j[0].StartKey) < 0 + return bytes.Compare(i[0].StartKey, j[0].StartKey) }) if !sortedByPartition { return false } for _, ranges := range rr.ranges { - if !slices.IsSortedFunc(ranges, func(i, j KeyRange) bool { - return bytes.Compare(i.StartKey, j.StartKey) < 0 + if !slices.IsSortedFunc(ranges, func(i, j KeyRange) int { + return bytes.Compare(i.StartKey, j.StartKey) }) { return false } diff --git a/store/mockstore/unistore/util/lockwaiter/BUILD.bazel b/store/mockstore/unistore/util/lockwaiter/BUILD.bazel index 757f51ef806f0..8c873655987a6 100644 --- a/store/mockstore/unistore/util/lockwaiter/BUILD.bazel +++ b/store/mockstore/unistore/util/lockwaiter/BUILD.bazel @@ -9,7 +9,6 @@ go_library( "//store/mockstore/unistore/config", "@com_github_pingcap_kvproto//pkg/deadlock", "@com_github_pingcap_log//:log", - "@org_golang_x_exp//slices", "@org_uber_go_zap//:zap", ], ) diff --git a/store/mockstore/unistore/util/lockwaiter/lockwaiter.go b/store/mockstore/unistore/util/lockwaiter/lockwaiter.go index 979eed53652c2..88cddace6cca9 100644 --- a/store/mockstore/unistore/util/lockwaiter/lockwaiter.go +++ b/store/mockstore/unistore/util/lockwaiter/lockwaiter.go @@ -15,6 +15,8 @@ package lockwaiter import ( + "cmp" + "slices" "sync" "time" @@ -22,7 +24,6 @@ import ( "github.com/pingcap/log" "github.com/pingcap/tidb/store/mockstore/unistore/config" "go.uber.org/zap" - "golang.org/x/exp/slices" ) // LockNoWait is used for pessimistic lock wait time @@ -51,8 +52,8 @@ type queue struct { func (q *queue) getOldestWaiter() (*Waiter, []*Waiter) { // make the waiters in start ts order - slices.SortFunc(q.waiters, func(i, j *Waiter) bool { - return i.startTS < j.startTS + slices.SortFunc(q.waiters, func(i, j *Waiter) int { + return cmp.Compare(i.startTS, j.startTS) }) oldestWaiter := q.waiters[0] remainWaiter := q.waiters[1:] diff --git a/ttl/ttlworker/BUILD.bazel b/ttl/ttlworker/BUILD.bazel index 5073b9ca522b9..7b098f417cc6f 100644 --- a/ttl/ttlworker/BUILD.bazel +++ b/ttl/ttlworker/BUILD.bazel @@ -46,7 +46,6 @@ go_library( "@com_github_tikv_client_go_v2//tikvrpc", "@io_etcd_go_etcd_client_v3//:client", "@org_golang_x_exp//maps", - "@org_golang_x_exp//slices", "@org_golang_x_time//rate", "@org_uber_go_multierr//:multierr", "@org_uber_go_zap//:zap", diff --git a/ttl/ttlworker/timer_sync.go b/ttl/ttlworker/timer_sync.go index 41bb410a294f0..db2d1c1b7701e 100644 --- a/ttl/ttlworker/timer_sync.go +++ b/ttl/ttlworker/timer_sync.go @@ -18,6 +18,7 @@ import ( "context" "encoding/json" "fmt" + "slices" "time" "github.com/pingcap/errors" @@ -30,7 +31,6 @@ import ( "github.com/pingcap/tidb/util/logutil" "go.uber.org/zap" "golang.org/x/exp/maps" - "golang.org/x/exp/slices" ) const (