From 3352a6127534b69c2e90bceba661be5921aaffc1 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 24 Aug 2023 11:47:06 +0800 Subject: [PATCH] *: use std/slices to replace exp/slices (#46373) ref pingcap/tidb#45933 --- br/pkg/restore/BUILD.bazel | 1 - br/pkg/restore/client.go | 39 ++++++++++++++------------------------ ddl/job_table_test.go | 2 +- parser/charset/BUILD.bazel | 1 - parser/charset/charset.go | 7 ++++--- 5 files changed, 19 insertions(+), 31 deletions(-) diff --git a/br/pkg/restore/BUILD.bazel b/br/pkg/restore/BUILD.bazel index a31820a376b16..9e264b1c348f7 100644 --- a/br/pkg/restore/BUILD.bazel +++ b/br/pkg/restore/BUILD.bazel @@ -98,7 +98,6 @@ go_library( "@org_golang_google_grpc//credentials/insecure", "@org_golang_google_grpc//keepalive", "@org_golang_google_grpc//status", - "@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/restore/client.go b/br/pkg/restore/client.go index 34e74c1039005..5bb09c84695dc 100644 --- a/br/pkg/restore/client.go +++ b/br/pkg/restore/client.go @@ -4,12 +4,14 @@ package restore import ( "bytes" + "cmp" "context" "crypto/tls" "encoding/hex" "encoding/json" "fmt" "math" + "slices" "strconv" "strings" "sync" @@ -65,7 +67,6 @@ import ( pd "github.com/tikv/pd/client" "go.uber.org/zap" "go.uber.org/zap/zapcore" - "golang.org/x/exp/slices" "golang.org/x/sync/errgroup" "google.golang.org/grpc" "google.golang.org/grpc/backoff" @@ -822,8 +823,8 @@ func (rc *Client) CreateTables( newTables = append(newTables, et.Table) } // Let's ensure that it won't break the original order. - slices.SortFunc(newTables, func(i, j *model.TableInfo) bool { - return tbMapping[i.Name.String()] < tbMapping[j.Name.String()] + slices.SortFunc(newTables, func(i, j *model.TableInfo) int { + return cmp.Compare(tbMapping[i.Name.String()], tbMapping[j.Name.String()]) }) select { @@ -1193,8 +1194,8 @@ func (rc *Client) CheckSysTableCompatibility(dom *domain.Domain, tables []*metau // ExecDDLs executes the queries of the ddl jobs. func (rc *Client) ExecDDLs(ctx context.Context, ddlJobs []*model.Job) error { // Sort the ddl jobs by schema version in ascending order. - slices.SortFunc(ddlJobs, func(i, j *model.Job) bool { - return i.BinlogInfo.SchemaVersion < j.BinlogInfo.SchemaVersion + slices.SortFunc(ddlJobs, func(i, j *model.Job) int { + return cmp.Compare(i.BinlogInfo.SchemaVersion, j.BinlogInfo.SchemaVersion) }) for _, job := range ddlJobs { @@ -2822,26 +2823,14 @@ func (rc *Client) InitSchemasReplaceForDDL( } func SortMetaKVFiles(files []*backuppb.DataFileInfo) []*backuppb.DataFileInfo { - slices.SortFunc(files, func(i, j *backuppb.DataFileInfo) bool { - if i.GetMinTs() < j.GetMinTs() { - return true - } else if i.GetMinTs() > j.GetMinTs() { - return false + slices.SortFunc(files, func(i, j *backuppb.DataFileInfo) int { + if c := cmp.Compare(i.GetMinTs(), j.GetMinTs()); c != 0 { + return c } - - if i.GetMaxTs() < j.GetMaxTs() { - return true - } else if i.GetMaxTs() > j.GetMaxTs() { - return false + if c := cmp.Compare(i.GetMaxTs(), j.GetMaxTs()); c != 0 { + return c } - - if i.GetResolvedTs() < j.GetResolvedTs() { - return true - } else if i.GetResolvedTs() > j.GetResolvedTs() { - return false - } - - return true + return cmp.Compare(i.GetResolvedTs(), j.GetResolvedTs()) }) return files } @@ -3088,8 +3077,8 @@ func (rc *Client) RestoreBatchMetaKVFiles( } // sort these entries. - slices.SortFunc(curKvEntries, func(i, j *KvEntryWithTS) bool { - return i.ts < j.ts + slices.SortFunc(curKvEntries, func(i, j *KvEntryWithTS) int { + return cmp.Compare(i.ts, j.ts) }) // restore these entries with rawPut() method. diff --git a/ddl/job_table_test.go b/ddl/job_table_test.go index 61cad73cc81e2..d1f8a619335c4 100644 --- a/ddl/job_table_test.go +++ b/ddl/job_table_test.go @@ -17,6 +17,7 @@ package ddl_test import ( "context" "fmt" + "slices" "sync" "testing" "time" @@ -30,7 +31,6 @@ import ( "github.com/pingcap/tidb/testkit" "github.com/pingcap/tidb/util" "github.com/stretchr/testify/require" - "golang.org/x/exp/slices" ) // TestDDLScheduling tests the DDL scheduling. See Concurrent DDL RFC for the rules of DDL scheduling. diff --git a/parser/charset/BUILD.bazel b/parser/charset/BUILD.bazel index c437ee959cf28..dfc5896188a3b 100644 --- a/parser/charset/BUILD.bazel +++ b/parser/charset/BUILD.bazel @@ -20,7 +20,6 @@ go_library( "//parser/terror", "@com_github_pingcap_errors//:errors", "@com_github_pingcap_log//:log", - "@org_golang_x_exp//slices", "@org_golang_x_text//encoding", "@org_golang_x_text//encoding/charmap", "@org_golang_x_text//encoding/japanese", diff --git a/parser/charset/charset.go b/parser/charset/charset.go index 668acefcac239..0ba86f1edf460 100644 --- a/parser/charset/charset.go +++ b/parser/charset/charset.go @@ -14,6 +14,8 @@ package charset import ( + "cmp" + "slices" "strings" "github.com/pingcap/errors" @@ -21,7 +23,6 @@ import ( "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/parser/terror" "go.uber.org/zap" - "golang.org/x/exp/slices" ) var ( @@ -91,8 +92,8 @@ func GetSupportedCharsets() []*Charset { } // sort charset by name. - slices.SortFunc(charsets, func(i, j *Charset) bool { - return i.Name < j.Name + slices.SortFunc(charsets, func(i, j *Charset) int { + return cmp.Compare(i.Name, j.Name) }) return charsets }