Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: upgrade x/exp/slices version #53785

Merged
merged 4 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1508,8 +1508,8 @@ def go_deps():
name = "com_github_google_go_cmp",
build_file_proto_mode = "disable_global",
importpath = "github.com/google/go-cmp",
sum = "h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=",
version = "v0.5.9",
sum = "h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=",
version = "v0.6.0",
)
go_repository(
name = "com_github_google_go_querystring",
Expand Down Expand Up @@ -5263,15 +5263,15 @@ def go_deps():
name = "org_golang_x_crypto",
build_file_proto_mode = "disable_global",
importpath = "golang.org/x/crypto",
sum = "h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=",
version = "v0.15.0",
sum = "h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=",
version = "v0.23.0",
)
go_repository(
name = "org_golang_x_exp",
build_file_proto_mode = "disable_global",
importpath = "golang.org/x/exp",
sum = "h1:SkwG94eNiiYJhbeDE018Grw09HIN/KB9NlRmZsrzfWs=",
version = "v0.0.0-20221023144134-a1e5550cf13e",
sum = "h1:O9NuF4s+E/PvMIy+9IUZB9znFwUIXEWSstNjek6VpVg=",
version = "v0.0.0-20240531132922-fd00a4e0eefc",
)
go_repository(
name = "org_golang_x_exp_typeparams",
Expand Down Expand Up @@ -5305,15 +5305,15 @@ def go_deps():
name = "org_golang_x_mod",
build_file_proto_mode = "disable_global",
importpath = "golang.org/x/mod",
sum = "h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=",
version = "v0.14.0",
sum = "h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=",
version = "v0.17.0",
)
go_repository(
name = "org_golang_x_net",
build_file_proto_mode = "disable_global",
importpath = "golang.org/x/net",
sum = "h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=",
version = "v0.18.0",
sum = "h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=",
version = "v0.25.0",
)
go_repository(
name = "org_golang_x_oauth2",
Expand All @@ -5326,29 +5326,36 @@ def go_deps():
name = "org_golang_x_sync",
build_file_proto_mode = "disable_global",
importpath = "golang.org/x/sync",
sum = "h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=",
version = "v0.5.0",
sum = "h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=",
version = "v0.7.0",
)
go_repository(
name = "org_golang_x_sys",
build_file_proto_mode = "disable_global",
importpath = "golang.org/x/sys",
sum = "h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=",
version = "v0.14.0",
sum = "h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=",
version = "v0.20.0",
)
go_repository(
name = "org_golang_x_telemetry",
build_file_proto_mode = "disable",
importpath = "golang.org/x/telemetry",
sum = "h1:IRJeR9r1pYWsHKTRe/IInb7lYvbBVIqOgsX/u0mbOWY=",
version = "v0.0.0-20240228155512-f48c80bd79b2",
)
go_repository(
name = "org_golang_x_term",
build_file_proto_mode = "disable_global",
importpath = "golang.org/x/term",
sum = "h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8=",
version = "v0.14.0",
sum = "h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=",
version = "v0.20.0",
)
go_repository(
name = "org_golang_x_text",
build_file_proto_mode = "disable_global",
importpath = "golang.org/x/text",
sum = "h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=",
version = "v0.14.0",
sum = "h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=",
version = "v0.15.0",
)
go_repository(
name = "org_golang_x_time",
Expand All @@ -5361,8 +5368,8 @@ def go_deps():
name = "org_golang_x_tools",
build_file_proto_mode = "disable_global",
importpath = "golang.org/x/tools",
sum = "h1:zdAyfUGbYmuVokhzVmghFl2ZJh5QhcfebBgmVPFYA+8=",
version = "v0.15.0",
sum = "h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=",
version = "v0.21.0",
)
go_repository(
name = "org_golang_x_xerrors",
Expand Down
1 change: 1 addition & 0 deletions br/pkg/lightning/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ go_library(
"//br/pkg/version/build",
"//expression",
"//planner/core",
"//util/cmp",
"//util/promutil",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_failpoint//:failpoint",
Expand Down
1 change: 1 addition & 0 deletions br/pkg/lightning/backend/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ go_library(
"//br/pkg/lightning/mydump",
"//parser/model",
"//table",
"//util/cmp",
"@com_github_google_uuid//:uuid",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_failpoint//:failpoint",
Expand Down
10 changes: 7 additions & 3 deletions br/pkg/lightning/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/pingcap/tidb/br/pkg/lightning/mydump"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/util/cmp"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)
Expand Down Expand Up @@ -311,11 +312,14 @@ func (be Backend) CheckDiskQuota(quota int64) (
totalMemSize int64,
) {
sizes := be.abstract.EngineFileSizes()
slices.SortFunc(sizes, func(i, j EngineFileSize) bool {
slices.SortFunc(sizes, func(i, j EngineFileSize) int {
if i.IsImporting != j.IsImporting {
return i.IsImporting
if i.IsImporting {
return -1
}
return 1
}
return i.DiskSize+i.MemSize < j.DiskSize+j.MemSize
return cmp.Compare(i.DiskSize+i.MemSize, j.DiskSize+j.MemSize)
})
for _, size := range sizes {
totalDiskSize += size.DiskSize
Expand Down
1 change: 1 addition & 0 deletions br/pkg/lightning/backend/kv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ go_library(
"//tablecodec",
"//types",
"//util/chunk",
"//util/cmp",
"//util/mathutil",
"//util/topsql/stmtstats",
"@com_github_docker_go_units//:go-units",
Expand Down
5 changes: 3 additions & 2 deletions br/pkg/lightning/backend/kv/sql2kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/cmp"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"golang.org/x/exp/slices"
Expand Down Expand Up @@ -186,8 +187,8 @@
}

// order the result by column offset so they match the evaluation order.
slices.SortFunc(genCols, func(i, j genCol) bool {
return cols[i.index].Offset < cols[j.index].Offset
slices.SortFunc(genCols, func(i, j genCol) int {
return cmp.Compare(cols[i.index].Offset, cols[j.index].Offset)

Check warning on line 191 in br/pkg/lightning/backend/kv/sql2kv.go

View check run for this annotation

Codecov / codecov/patch

br/pkg/lightning/backend/kv/sql2kv.go#L190-L191

Added lines #L190 - L191 were not covered by tests
})
return genCols, nil
}
Expand Down
12 changes: 6 additions & 6 deletions br/pkg/lightning/backend/local/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,8 @@
if len(metas) == 0 {
return nil
}
slices.SortFunc(metas, func(i, j *sstMeta) bool {
return bytes.Compare(i.minKey, j.minKey) < 0
slices.SortFunc(metas, func(i, j *sstMeta) int {
return bytes.Compare(i.minKey, j.minKey)

Check warning on line 756 in br/pkg/lightning/backend/local/engine.go

View check run for this annotation

Codecov / codecov/patch

br/pkg/lightning/backend/local/engine.go#L756

Added line #L756 was not covered by tests
})

metaLevels := make([][]*sstMeta, 0)
Expand Down Expand Up @@ -914,8 +914,8 @@
return ranges
}

slices.SortFunc(ranges, func(i, j Range) bool {
return bytes.Compare(i.start, j.start) < 0
slices.SortFunc(ranges, func(i, j Range) int {
return bytes.Compare(i.start, j.start)
})

curEnd := ranges[0].end
Expand Down Expand Up @@ -1181,8 +1181,8 @@
return errors.Trace(err)
}
if !w.isWriteBatchSorted {
slices.SortFunc(w.writeBatch[:w.batchCount], func(i, j common.KvPair) bool {
return bytes.Compare(i.Key, j.Key) < 0
slices.SortFunc(w.writeBatch[:w.batchCount], func(i, j common.KvPair) int {
return bytes.Compare(i.Key, j.Key)
})
w.isWriteBatchSorted = true
}
Expand Down
12 changes: 6 additions & 6 deletions br/pkg/lightning/backend/local/localhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ func (local *local) SplitAndScatterRegionByRanges(
var err1 error
region := sp.region
keys := sp.keys
slices.SortFunc(keys, func(i, j []byte) bool {
return bytes.Compare(i, j) < 0
slices.SortFunc(keys, func(i, j []byte) int {
return bytes.Compare(i, j)
})
splitRegion := region
startIdx := 0
Expand Down Expand Up @@ -247,8 +247,8 @@ func (local *local) SplitAndScatterRegionByRanges(
log.FromContext(ctx).Info("batch split region", zap.Uint64("region_id", splitRegion.Region.Id),
zap.Int("keys", endIdx-startIdx), zap.Binary("firstKey", keys[startIdx]),
zap.Binary("end", keys[endIdx-1]))
slices.SortFunc(newRegions, func(i, j *split.RegionInfo) bool {
return bytes.Compare(i.Region.StartKey, j.Region.StartKey) < 0
slices.SortFunc(newRegions, func(i, j *split.RegionInfo) int {
return bytes.Compare(i.Region.StartKey, j.Region.StartKey)
})
syncLock.Lock()
scatterRegions = append(scatterRegions, newRegions...)
Expand Down Expand Up @@ -293,8 +293,8 @@ func (local *local) SplitAndScatterRegionByRanges(
if len(retryKeys) == 0 {
break
}
slices.SortFunc(retryKeys, func(i, j []byte) bool {
return bytes.Compare(i, j) < 0
slices.SortFunc(retryKeys, func(i, j []byte) int {
return bytes.Compare(i, j)
})
minKey = codec.EncodeBytes([]byte{}, retryKeys[0])
maxKey = codec.EncodeBytes([]byte{}, nextKey(retryKeys[len(retryKeys)-1]))
Expand Down
1 change: 1 addition & 0 deletions br/pkg/lightning/checkpoints/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ go_library(
"//parser/model",
"//types",
"//util/chunk",
"//util/cmp",
"//util/mathutil",
"//util/sqlexec",
"@com_github_joho_sqltocsv//:sqltocsv",
Expand Down
12 changes: 10 additions & 2 deletions br/pkg/lightning/checkpoints/checkpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
verify "github.com/pingcap/tidb/br/pkg/lightning/verification"
"github.com/pingcap/tidb/br/pkg/storage"
"github.com/pingcap/tidb/br/pkg/version/build"
"github.com/pingcap/tidb/util/cmp"
"github.com/pingcap/tidb/util/mathutil"
"go.uber.org/zap"
"golang.org/x/exp/slices"
Expand Down Expand Up @@ -229,6 +230,13 @@
return fmt.Sprintf("%s:%d", key.Path, key.Offset)
}

func (key *ChunkCheckpointKey) compare(other *ChunkCheckpointKey) int {
if c := cmp.Compare(key.Path, other.Path); c != 0 {
return c
}
return cmp.Compare(key.Offset, other.Offset)

Check warning on line 237 in br/pkg/lightning/checkpoints/checkpoints.go

View check run for this annotation

Codecov / codecov/patch

br/pkg/lightning/checkpoints/checkpoints.go#L233-L237

Added lines #L233 - L237 were not covered by tests
}

func (key *ChunkCheckpointKey) less(other *ChunkCheckpointKey) bool {
switch {
case key.Path < other.Path:
Expand Down Expand Up @@ -1257,8 +1265,8 @@
})
}

slices.SortFunc(engine.Chunks, func(i, j *ChunkCheckpoint) bool {
return i.Key.less(&j.Key)
slices.SortFunc(engine.Chunks, func(i, j *ChunkCheckpoint) int {
return i.Key.compare(&j.Key)

Check warning on line 1269 in br/pkg/lightning/checkpoints/checkpoints.go

View check run for this annotation

Codecov / codecov/patch

br/pkg/lightning/checkpoints/checkpoints.go#L1269

Added line #L1269 was not covered by tests
})

cp.Engines[engineID] = engine
Expand Down
5 changes: 3 additions & 2 deletions br/pkg/lightning/lightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import (
"github.com/pingcap/tidb/br/pkg/version/build"
_ "github.com/pingcap/tidb/expression" // get rid of `import cycle`: just init expression.RewriteAstExpr,and called at package `backend.kv`.
_ "github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/util/cmp"
"github.com/pingcap/tidb/util/promutil"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
Expand Down Expand Up @@ -900,8 +901,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++ {
Expand Down
1 change: 1 addition & 0 deletions br/pkg/lightning/restore/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ go_library(
"//table",
"//table/tables",
"//types",
"//util/cmp",
"//util/collate",
"//util/dbterror",
"//util/engine",
Expand Down
5 changes: 3 additions & 2 deletions br/pkg/lightning/restore/precheck_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/pingcap/tidb/store/pdtypes"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/cmp"
"github.com/pingcap/tidb/util/engine"
"github.com/pingcap/tidb/util/mathutil"
"github.com/pingcap/tidb/util/set"
Expand Down Expand Up @@ -332,8 +333,8 @@ func (ci *regionDistributionCheckItem) Check(ctx context.Context) (*CheckResult,
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]
Expand Down
3 changes: 2 additions & 1 deletion br/pkg/lightning/restore/table_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/util/cmp"
"github.com/pingcap/tidb/util/mathutil"
clientv3 "go.etcd.io/etcd/client/v3"
"go.uber.org/multierr"
Expand Down Expand Up @@ -309,7 +310,7 @@ func (tr *TableRestore) restoreEngines(pCtx context.Context, rc *Controller, cp
for engineID, engine := range cp.Engines {
allEngines = append(allEngines, engineCheckpoint{engineID: engineID, checkpoint: engine})
}
slices.SortFunc(allEngines, func(i, j engineCheckpoint) bool { return i.engineID < j.engineID })
slices.SortFunc(allEngines, func(i, j engineCheckpoint) int { return cmp.Compare(i.engineID, j.engineID) })

for _, ecp := range allEngines {
engineID := ecp.engineID
Expand Down
1 change: 1 addition & 0 deletions br/pkg/restore/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ go_library(
"//store/pdtypes",
"//tablecodec",
"//util",
"//util/cmp",
"//util/codec",
"//util/collate",
"//util/hack",
Expand Down
Loading
Loading