Skip to content

Commit

Permalink
*: use std/slices to replace exp/slices (#46373)
Browse files Browse the repository at this point in the history
ref #45933
  • Loading branch information
hawkingrei authored Aug 24, 2023
1 parent 0ac705f commit 3352a61
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 31 deletions.
1 change: 0 additions & 1 deletion br/pkg/restore/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
39 changes: 14 additions & 25 deletions br/pkg/restore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ package restore

import (
"bytes"
"cmp"
"context"
"crypto/tls"
"encoding/hex"
"encoding/json"
"fmt"
"math"
"slices"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ddl/job_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package ddl_test
import (
"context"
"fmt"
"slices"
"sync"
"testing"
"time"
Expand All @@ -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.
Expand Down
1 change: 0 additions & 1 deletion parser/charset/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions parser/charset/charset.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
package charset

import (
"cmp"
"slices"
"strings"

"github.com/pingcap/errors"
"github.com/pingcap/log"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/parser/terror"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

var (
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 3352a61

Please sign in to comment.