Skip to content

Commit

Permalink
Merge branch 'master' into info-store
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox authored Jul 6, 2022
2 parents b529f8f + c76d686 commit 464e829
Show file tree
Hide file tree
Showing 180 changed files with 1,882 additions and 1,277 deletions.
12 changes: 6 additions & 6 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2502,8 +2502,8 @@ def go_deps():
name = "com_github_pingcap_kvproto",
build_file_proto_mode = "disable_global",
importpath = "github.com/pingcap/kvproto",
sum = "h1:TZ0teMZoKHnZDlJxNkWrp5Sgv3w+ruNbrqtBYKsfaNw=",
version = "v0.0.0-20220525022339-6aaebf466305",
sum = "h1:nP2wmyw9JTRsk5rm+tZtfAso6c/1FvuaFNbXTaYz3FE=",
version = "v0.0.0-20220705053936-aa9c2d20cd2a",
)
go_repository(
name = "com_github_pingcap_log",
Expand All @@ -2523,8 +2523,8 @@ def go_deps():
name = "com_github_pingcap_tipb",
build_file_proto_mode = "disable_global",
importpath = "github.com/pingcap/tipb",
sum = "h1:L4nZwfYSrIsWPAZR8zMwHaNQJy0Rjy3Od6Smj5mlOms=",
version = "v0.0.0-20220602075447-4847c5d68e73",
sum = "h1:XaTE4ZhQbQtQZtAVzlZh/Pf6SjFfMSTe1ia2nGcl36Y=",
version = "v0.0.0-20220706024432-7be3cc83a7d5",
)
go_repository(
name = "com_github_pkg_browser",
Expand Down Expand Up @@ -3763,8 +3763,8 @@ def go_deps():
name = "org_golang_x_exp",
build_file_proto_mode = "disable_global",
importpath = "golang.org/x/exp",
sum = "h1:rxKZ2gOnYxjfmakvUUqh9Gyb6KXfrj7JWTxORTYqb0E=",
version = "v0.0.0-20220426173459-3bcf042a4bf5",
sum = "h1:TfdoLivD44QwvssI9Sv1xwa5DcL5XQr4au4sZ2F2NV4=",
version = "v0.0.0-20220428152302-39d4317da171",
)
go_repository(
name = "org_golang_x_exp_typeparams",
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 @@ -34,6 +34,7 @@ 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_zap//:zap",
"@org_uber_go_zap//zapcore",
],
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 @@ -18,6 +18,7 @@ go_library(
"@com_github_google_uuid//:uuid",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_failpoint//:failpoint",
"@org_golang_x_exp//slices",
"@org_uber_go_zap//:zap",
],
)
Expand Down
11 changes: 5 additions & 6 deletions br/pkg/lightning/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package backend
import (
"context"
"fmt"
"sort"
"time"

"github.com/google/uuid"
Expand All @@ -33,6 +32,7 @@ import (
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/table"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

const (
Expand Down Expand Up @@ -290,12 +290,11 @@ func (be Backend) CheckDiskQuota(quota int64) (
totalMemSize int64,
) {
sizes := be.abstract.EngineFileSizes()
sort.Slice(sizes, func(i, j int) bool {
a, b := &sizes[i], &sizes[j]
if a.IsImporting != b.IsImporting {
return a.IsImporting
slices.SortFunc(sizes, func(i, j EngineFileSize) bool {
if i.IsImporting != j.IsImporting {
return i.IsImporting
}
return a.DiskSize+a.MemSize < b.DiskSize+b.MemSize
return 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 @@ -37,6 +37,7 @@ 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",
],
Expand Down
6 changes: 3 additions & 3 deletions br/pkg/lightning/backend/kv/sql2kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"math"
"math/rand"
"sort"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/br/pkg/lightning/common"
Expand All @@ -44,6 +43,7 @@ import (
"github.com/pingcap/tidb/util/chunk"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"golang.org/x/exp/slices"
)

var ExtraHandleColumnInfo = model.NewExtraHandleColInfo()
Expand Down Expand Up @@ -188,8 +188,8 @@ func collectGeneratedColumns(se *session, meta *model.TableInfo, cols []*table.C
}

// order the result by column offset so they match the evaluation order.
sort.Slice(genCols, func(i, j int) bool {
return cols[genCols[i].index].Offset < cols[genCols[j].index].Offset
slices.SortFunc(genCols, func(i, j genCol) bool {
return cols[i.index].Offset < cols[j.index].Offset
})
return genCols, nil
}
Expand Down
1 change: 1 addition & 0 deletions br/pkg/lightning/backend/local/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ go_library(
"@org_golang_google_grpc//credentials",
"@org_golang_google_grpc//keepalive",
"@org_golang_google_grpc//status",
"@org_golang_x_exp//slices",
"@org_golang_x_sync//errgroup",
"@org_golang_x_time//rate",
"@org_uber_go_atomic//:atomic",
Expand Down
14 changes: 7 additions & 7 deletions br/pkg/lightning/backend/local/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"io"
"os"
"path/filepath"
"sort"
"sync"
"time"

Expand All @@ -45,6 +44,7 @@ import (
"github.com/pingcap/tidb/util/hack"
"go.uber.org/atomic"
"go.uber.org/zap"
"golang.org/x/exp/slices"
"golang.org/x/sync/errgroup"
)

Expand Down Expand Up @@ -732,8 +732,8 @@ func (e *Engine) batchIngestSSTs(metas []*sstMeta) error {
if len(metas) == 0 {
return nil
}
sort.Slice(metas, func(i, j int) bool {
return bytes.Compare(metas[i].minKey, metas[j].minKey) < 0
slices.SortFunc(metas, func(i, j *sstMeta) bool {
return bytes.Compare(i.minKey, j.minKey) < 0
})

metaLevels := make([][]*sstMeta, 0)
Expand Down Expand Up @@ -894,8 +894,8 @@ func sortAndMergeRanges(ranges []Range) []Range {
return ranges
}

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

curEnd := ranges[0].end
Expand Down Expand Up @@ -1161,8 +1161,8 @@ func (w *Writer) flushKVs(ctx context.Context) error {
return errors.Trace(err)
}
if !w.isWriteBatchSorted {
sort.Slice(w.writeBatch[:w.batchCount], func(i, j int) bool {
return bytes.Compare(w.writeBatch[i].Key, w.writeBatch[j].Key) < 0
slices.SortFunc(w.writeBatch[:w.batchCount], func(i, j common.KvPair) bool {
return bytes.Compare(i.Key, j.Key) < 0
})
w.isWriteBatchSorted = true
}
Expand Down
13 changes: 7 additions & 6 deletions br/pkg/lightning/backend/local/localhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/pingcap/tidb/util/mathutil"
"go.uber.org/multierr"
"go.uber.org/zap"
"golang.org/x/exp/slices"
"golang.org/x/sync/errgroup"
"golang.org/x/time/rate"
)
Expand Down Expand Up @@ -220,8 +221,8 @@ func (local *local) SplitAndScatterRegionByRanges(
var err1 error
region := sp.region
keys := sp.keys
sort.Slice(keys, func(i, j int) bool {
return bytes.Compare(keys[i], keys[j]) < 0
slices.SortFunc(keys, func(i, j []byte) bool {
return bytes.Compare(i, j) < 0
})
splitRegion := region
startIdx := 0
Expand Down Expand Up @@ -264,8 +265,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]))
sort.Slice(newRegions, func(i, j int) bool {
return bytes.Compare(newRegions[i].Region.StartKey, newRegions[j].Region.StartKey) < 0
slices.SortFunc(newRegions, func(i, j *split.RegionInfo) bool {
return bytes.Compare(i.Region.StartKey, j.Region.StartKey) < 0
})
syncLock.Lock()
scatterRegions = append(scatterRegions, newRegions...)
Expand Down Expand Up @@ -319,8 +320,8 @@ func (local *local) SplitAndScatterRegionByRanges(
if len(retryKeys) == 0 {
break
} else {
sort.Slice(retryKeys, func(i, j int) bool {
return bytes.Compare(retryKeys[i], retryKeys[j]) < 0
slices.SortFunc(retryKeys, func(i, j []byte) bool {
return bytes.Compare(i, j) < 0
})
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 @@ -26,6 +26,7 @@ go_library(
"//util/sqlexec",
"@com_github_joho_sqltocsv//:sqltocsv",
"@com_github_pingcap_errors//:errors",
"@org_golang_x_exp//slices",
"@org_uber_go_zap//:zap",
],
)
Expand Down
5 changes: 3 additions & 2 deletions br/pkg/lightning/checkpoints/checkpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/pingcap/tidb/br/pkg/version/build"
"github.com/pingcap/tidb/util/mathutil"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

type CheckpointStatus uint8
Expand Down Expand Up @@ -1217,8 +1218,8 @@ func (cpdb *FileCheckpointsDB) Get(_ context.Context, tableName string) (*TableC
})
}

sort.Slice(engine.Chunks, func(i, j int) bool {
return engine.Chunks[i].Key.less(&engine.Chunks[j].Key)
slices.SortFunc(engine.Chunks, func(i, j *ChunkCheckpoint) bool {
return i.Key.less(&j.Key)
})

cp.Engines[engineID] = engine
Expand Down
6 changes: 3 additions & 3 deletions br/pkg/lightning/lightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"net/http"
"net/http/pprof"
"os"
"sort"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -59,6 +58,7 @@ import (
"github.com/shurcooL/httpgzip"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"golang.org/x/exp/slices"
)

type Lightning struct {
Expand Down Expand Up @@ -870,8 +870,8 @@ func checkSystemRequirement(cfg *config.Config, dbsMeta []*mydump.MDDatabaseMeta
tableTotalSizes = append(tableTotalSizes, tb.TotalSize)
}
}
sort.Slice(tableTotalSizes, func(i, j int) bool {
return tableTotalSizes[i] > tableTotalSizes[j]
slices.SortFunc(tableTotalSizes, func(i, j int64) bool {
return i > j
})
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 @@ -66,6 +66,7 @@ go_library(
"@com_github_tikv_client_go_v2//oracle",
"@com_github_tikv_pd_client//:client",
"@org_golang_x_exp//maps",
"@org_golang_x_exp//slices",
"@org_golang_x_sync//errgroup",
"@org_uber_go_atomic//:atomic",
"@org_uber_go_multierr//:multierr",
Expand Down
8 changes: 4 additions & 4 deletions br/pkg/lightning/restore/check_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"io"
"path/filepath"
"reflect"
"sort"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -50,6 +49,7 @@ import (
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/mathutil"
"go.uber.org/zap"
"golang.org/x/exp/slices"
"golang.org/x/sync/errgroup"
)

Expand Down Expand Up @@ -291,8 +291,8 @@ func (rc *Controller) checkRegionDistribution(ctx context.Context) error {
if len(stores) <= 1 {
return nil
}
sort.Slice(stores, func(i, j int) bool {
return stores[i].Status.RegionCount < stores[j].Status.RegionCount
slices.SortFunc(stores, func(i, j *pdtypes.StoreInfo) bool {
return i.Status.RegionCount < j.Status.RegionCount
})
minStore := stores[0]
maxStore := stores[len(stores)-1]
Expand Down Expand Up @@ -1156,7 +1156,7 @@ loop:

if len(tableNames) > 0 {
// sort the failed names
sort.Strings(tableNames)
slices.Sort(tableNames)
msg := fmt.Sprintf("table(s) [%s] are not empty", strings.Join(tableNames, ", "))
rc.checkTemplate.Collect(Critical, false, msg)
}
Expand Down
4 changes: 2 additions & 2 deletions br/pkg/lightning/restore/table_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package restore

import (
"context"
"sort"
"strings"
"sync"
"time"
Expand All @@ -43,6 +42,7 @@ import (
"github.com/pingcap/tidb/util/mathutil"
"go.uber.org/multierr"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

type TableRestore struct {
Expand Down Expand Up @@ -285,7 +285,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})
}
sort.Slice(allEngines, func(i, j int) bool { return allEngines[i].engineID < allEngines[j].engineID })
slices.SortFunc(allEngines, func(i, j engineCheckpoint) bool { return 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 @@ -73,6 +73,7 @@ go_library(
"@org_golang_google_grpc//credentials",
"@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
10 changes: 5 additions & 5 deletions br/pkg/restore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"encoding/json"
"fmt"
"math"
"sort"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -52,6 +51,7 @@ 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 @@ -582,8 +582,8 @@ func (rc *Client) CreateTables(
newTables = append(newTables, et.Table)
}
// Let's ensure that it won't break the original order.
sort.Slice(newTables, func(i, j int) bool {
return tbMapping[newTables[i].Name.String()] < tbMapping[newTables[j].Name.String()]
slices.SortFunc(newTables, func(i, j *model.TableInfo) bool {
return tbMapping[i.Name.String()] < tbMapping[j.Name.String()]
})

select {
Expand Down Expand Up @@ -826,8 +826,8 @@ func (rc *Client) createTablesInWorkerPool(ctx context.Context, dom *domain.Doma
// 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.
sort.Slice(ddlJobs, func(i, j int) bool {
return ddlJobs[i].BinlogInfo.SchemaVersion < ddlJobs[j].BinlogInfo.SchemaVersion
slices.SortFunc(ddlJobs, func(i, j *model.Job) bool {
return i.BinlogInfo.SchemaVersion < j.BinlogInfo.SchemaVersion
})

for _, job := range ddlJobs {
Expand Down
Loading

0 comments on commit 464e829

Please sign in to comment.