diff --git a/br/pkg/lightning/BUILD.bazel b/br/pkg/lightning/BUILD.bazel index 2333617f8dd90..7721acebf1551 100644 --- a/br/pkg/lightning/BUILD.bazel +++ b/br/pkg/lightning/BUILD.bazel @@ -39,7 +39,6 @@ go_library( "@com_github_prometheus_client_golang//prometheus/collectors", "@com_github_prometheus_client_golang//prometheus/promhttp", "@com_github_shurcool_httpgzip//:httpgzip", - "@org_golang_x_exp//slices", "@org_uber_go_atomic//:atomic", "@org_uber_go_zap//:zap", "@org_uber_go_zap//zapcore", diff --git a/br/pkg/lightning/backend/kv/BUILD.bazel b/br/pkg/lightning/backend/kv/BUILD.bazel index d9ad7497ca579..72ee0992dfcb2 100644 --- a/br/pkg/lightning/backend/kv/BUILD.bazel +++ b/br/pkg/lightning/backend/kv/BUILD.bazel @@ -38,7 +38,6 @@ go_library( "//util/topsql/stmtstats", "@com_github_docker_go_units//:go-units", "@com_github_pingcap_errors//:errors", - "@org_golang_x_exp//slices", "@org_uber_go_zap//:zap", "@org_uber_go_zap//zapcore", ], diff --git a/br/pkg/lightning/backend/kv/sql2kv.go b/br/pkg/lightning/backend/kv/sql2kv.go index bd5c65aaf0382..b30452cfa00b5 100644 --- a/br/pkg/lightning/backend/kv/sql2kv.go +++ b/br/pkg/lightning/backend/kv/sql2kv.go @@ -17,9 +17,11 @@ package kv import ( + "cmp" "context" "fmt" "math" + "slices" "github.com/pingcap/errors" "github.com/pingcap/tidb/br/pkg/lightning/backend/encode" @@ -35,7 +37,6 @@ import ( "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/types" - "golang.org/x/exp/slices" ) type tableKVEncoder struct { @@ -126,8 +127,8 @@ func CollectGeneratedColumns(se *Session, meta *model.TableInfo, cols []*table.C } // order the result by column offset so they match the evaluation order. - slices.SortFunc(genCols, func(i, j GeneratedCol) bool { - return cols[i.Index].Offset < cols[j.Index].Offset + slices.SortFunc(genCols, func(i, j GeneratedCol) int { + return cmp.Compare(cols[i.Index].Offset, cols[j.Index].Offset) }) return genCols, nil } diff --git a/br/pkg/lightning/duplicate/BUILD.bazel b/br/pkg/lightning/duplicate/BUILD.bazel index ff7566cabaa1a..58ef3bbe4369a 100644 --- a/br/pkg/lightning/duplicate/BUILD.bazel +++ b/br/pkg/lightning/duplicate/BUILD.bazel @@ -35,6 +35,5 @@ go_test( "//br/pkg/lightning/log", "//util/extsort", "@com_github_stretchr_testify//require", - "@org_golang_x_exp//slices", ], ) diff --git a/br/pkg/lightning/duplicate/detector_test.go b/br/pkg/lightning/duplicate/detector_test.go index f314f8b223279..91625406e98e1 100644 --- a/br/pkg/lightning/duplicate/detector_test.go +++ b/br/pkg/lightning/duplicate/detector_test.go @@ -20,6 +20,7 @@ import ( "encoding/binary" "errors" "math/rand" + "slices" "sync" "testing" @@ -27,7 +28,6 @@ import ( "github.com/pingcap/tidb/br/pkg/lightning/log" "github.com/pingcap/tidb/util/extsort" "github.com/stretchr/testify/require" - "golang.org/x/exp/slices" ) func TestDetector(t *testing.T) { @@ -92,20 +92,17 @@ func TestDetector(t *testing.T) { } func verifyResults(t *testing.T, keys [][]byte, results []result) { - less := func(a, b []byte) bool { - return bytes.Compare(a, b) < 0 - } for _, r := range results { require.GreaterOrEqual(t, len(r.keyIDs), 2, "keyIDs should have at least 2 elements") - require.True(t, slices.IsSortedFunc(r.keyIDs, less), "keyIDs should be sorted") + require.True(t, slices.IsSortedFunc(r.keyIDs, bytes.Compare), "keyIDs should be sorted") } - slices.SortFunc(results, func(a, b result) bool { - return bytes.Compare(a.key, b.key) < 0 + slices.SortFunc(results, func(a, b result) int { + return bytes.Compare(a.key, b.key) }) sortedKeys := make([][]byte, len(keys)) copy(sortedKeys, keys) - slices.SortFunc(sortedKeys, less) + slices.SortFunc(sortedKeys, bytes.Compare) for i := 0; i < len(sortedKeys); { j := i + 1 diff --git a/br/pkg/lightning/importer/dup_detect.go b/br/pkg/lightning/importer/dup_detect.go index 3d143961d7c6b..1e72ebaeb6cc9 100644 --- a/br/pkg/lightning/importer/dup_detect.go +++ b/br/pkg/lightning/importer/dup_detect.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "io" + "slices" "github.com/pingcap/errors" "github.com/pingcap/tidb/br/pkg/lightning/backend/encode" @@ -34,7 +35,6 @@ import ( "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/extsort" "go.uber.org/zap" - "golang.org/x/exp/slices" "golang.org/x/sync/errgroup" ) diff --git a/br/pkg/lightning/importer/precheck_impl.go b/br/pkg/lightning/importer/precheck_impl.go index 0f5c40100cf65..ed3b034555906 100644 --- a/br/pkg/lightning/importer/precheck_impl.go +++ b/br/pkg/lightning/importer/precheck_impl.go @@ -14,10 +14,12 @@ package importer import ( + "cmp" "context" "fmt" "path/filepath" "reflect" + "slices" "strconv" "strings" "sync" @@ -47,7 +49,6 @@ import ( "github.com/pingcap/tidb/util/set" clientv3 "go.etcd.io/etcd/client/v3" "go.uber.org/zap" - "golang.org/x/exp/slices" "golang.org/x/sync/errgroup" "google.golang.org/grpc" ) @@ -361,8 +362,8 @@ func (ci *regionDistributionCheckItem) Check(ctx context.Context) (*precheck.Che if len(stores) <= 1 { return theResult, nil } - slices.SortFunc(stores, func(i, j *pdtypes.StoreInfo) bool { - return i.Status.RegionCount < j.Status.RegionCount + slices.SortFunc(stores, func(i, j *pdtypes.StoreInfo) int { + return cmp.Compare(i.Status.RegionCount, j.Status.RegionCount) }) minStore := stores[0] maxStore := stores[len(stores)-1] diff --git a/br/pkg/lightning/lightning.go b/br/pkg/lightning/lightning.go index 27bf951dc9f81..236df11f8b061 100644 --- a/br/pkg/lightning/lightning.go +++ b/br/pkg/lightning/lightning.go @@ -15,6 +15,7 @@ package lightning import ( + "cmp" "compress/gzip" "context" "crypto/ecdsa" @@ -29,6 +30,7 @@ import ( "net/http" "net/http/pprof" "os" + "slices" "strconv" "strings" "sync" @@ -65,7 +67,6 @@ import ( "go.uber.org/atomic" "go.uber.org/zap" "go.uber.org/zap/zapcore" - "golang.org/x/exp/slices" ) // Lightning is the main struct of the lightning package. @@ -960,8 +961,8 @@ func checkSystemRequirement(cfg *config.Config, dbsMeta []*mydump.MDDatabaseMeta tableTotalSizes = append(tableTotalSizes, tb.TotalSize) } } - slices.SortFunc(tableTotalSizes, func(i, j int64) bool { - return i > j + slices.SortFunc(tableTotalSizes, func(i, j int64) int { + return cmp.Compare(j, i) }) topNTotalSize := int64(0) for i := 0; i < len(tableTotalSizes) && i < cfg.App.TableConcurrency; i++ { diff --git a/br/pkg/restore/db.go b/br/pkg/restore/db.go index f095166c4e233..3bbaae026a865 100644 --- a/br/pkg/restore/db.go +++ b/br/pkg/restore/db.go @@ -3,8 +3,10 @@ package restore import ( + "cmp" "context" "fmt" + "slices" "sync" "github.com/pingcap/errors" @@ -21,7 +23,6 @@ import ( "github.com/pingcap/tidb/sessionctx/variable" tidbutil "github.com/pingcap/tidb/util" "go.uber.org/zap" - "golang.org/x/exp/slices" ) // DB is a TiDB instance, not thread-safe. @@ -403,8 +404,8 @@ func (db *DB) ensureTablePlacementPolicies(ctx context.Context, tableInfo *model // FilterDDLJobs filters ddl jobs. func FilterDDLJobs(allDDLJobs []*model.Job, tables []*metautil.Table) (ddlJobs []*model.Job) { // Sort the ddl jobs by schema version in descending order. - slices.SortFunc(allDDLJobs, func(i, j *model.Job) bool { - return i.BinlogInfo.SchemaVersion > j.BinlogInfo.SchemaVersion + slices.SortFunc(allDDLJobs, func(i, j *model.Job) int { + return cmp.Compare(j.BinlogInfo.SchemaVersion, i.BinlogInfo.SchemaVersion) }) dbs := getDatabases(tables) for _, db := range dbs { diff --git a/br/pkg/task/BUILD.bazel b/br/pkg/task/BUILD.bazel index eb57947e7eda9..192c59a9d006a 100644 --- a/br/pkg/task/BUILD.bazel +++ b/br/pkg/task/BUILD.bazel @@ -81,7 +81,6 @@ go_library( "@org_golang_google_grpc//:grpc", "@org_golang_google_grpc//backoff", "@org_golang_google_grpc//keepalive", - "@org_golang_x_exp//slices", "@org_golang_x_sync//errgroup", "@org_uber_go_multierr//:multierr", "@org_uber_go_zap//:zap", diff --git a/br/pkg/task/stream.go b/br/pkg/task/stream.go index 53ff04f079232..b4a7693097ec6 100644 --- a/br/pkg/task/stream.go +++ b/br/pkg/task/stream.go @@ -20,6 +20,7 @@ import ( "encoding/binary" "fmt" "net/http" + "slices" "strings" "sync" "time" @@ -58,7 +59,6 @@ import ( "github.com/tikv/client-go/v2/oracle" clientv3 "go.etcd.io/etcd/client/v3" "go.uber.org/zap" - "golang.org/x/exp/slices" ) const ( @@ -414,8 +414,8 @@ func (s *streamMgr) buildObserveRanges(ctx context.Context) ([]kv.KeyRange, erro mRange := stream.BuildObserveMetaRange() rs := append([]kv.KeyRange{*mRange}, dRanges...) - slices.SortFunc(rs, func(i, j kv.KeyRange) bool { - return bytes.Compare(i.StartKey, j.StartKey) < 0 + slices.SortFunc(rs, func(i, j kv.KeyRange) int { + return bytes.Compare(i.StartKey, j.StartKey) }) return rs, nil diff --git a/br/pkg/trace/BUILD.bazel b/br/pkg/trace/BUILD.bazel index f59c79a5d17f4..c8bcdd2a1c267 100644 --- a/br/pkg/trace/BUILD.bazel +++ b/br/pkg/trace/BUILD.bazel @@ -11,7 +11,6 @@ go_library( "@com_github_pingcap_log//:log", "@com_sourcegraph_sourcegraph_appdash//:appdash", "@com_sourcegraph_sourcegraph_appdash//opentracing", - "@org_golang_x_exp//slices", "@org_uber_go_zap//:zap", ], ) diff --git a/br/pkg/trace/tracing.go b/br/pkg/trace/tracing.go index ff961367ff282..68045c0b93aa3 100644 --- a/br/pkg/trace/tracing.go +++ b/br/pkg/trace/tracing.go @@ -7,6 +7,7 @@ import ( "fmt" "os" "path/filepath" + "slices" "text/tabwriter" "time" @@ -14,7 +15,6 @@ import ( "github.com/opentracing/opentracing-go" "github.com/pingcap/log" "go.uber.org/zap" - "golang.org/x/exp/slices" "sourcegraph.com/sourcegraph/appdash" traceImpl "sourcegraph.com/sourcegraph/appdash/opentracing" ) @@ -88,7 +88,7 @@ func dfsTree(t *appdash.Trace, prefix string, isLast bool, tub *tabby.Tabby) { tub.AddLine(prefix+suffix+t.Span.Name(), start.Format("15:04:05.000000"), duration.String()) // Sort events by their start time - slices.SortFunc(t.Sub, func(i, j *appdash.Trace) bool { + slices.SortFunc(t.Sub, func(i, j *appdash.Trace) int { var istart, jstart time.Time if ievent, err := i.TimespanEvent(); err == nil { istart = ievent.Start() @@ -96,7 +96,7 @@ func dfsTree(t *appdash.Trace, prefix string, isLast bool, tub *tabby.Tabby) { if jevent, err := j.TimespanEvent(); err == nil { jstart = jevent.Start() } - return istart.Before(jstart) + return istart.Compare(jstart) }) for i, sp := range t.Sub {