From a472abe08380f0f4a53a94174bf13467df52944d Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 29 Jun 2022 19:32:13 +0800 Subject: [PATCH] *: enable gci and replacec goimports in nogo Signed-off-by: Weizhen Wang --- DEPS.bzl | 16 +++++ br/pkg/lightning/backend/kv/sql2kv.go | 7 +- br/pkg/lightning/backend/local/engine_test.go | 3 +- br/pkg/lightning/errormanager/errormanager.go | 7 +- .../errormanager/errormanager_test.go | 5 +- br/pkg/lightning/mydump/charset_convertor.go | 3 +- br/pkg/lightning/mydump/router.go | 5 +- .../lightning/restore/restore_schema_test.go | 7 +- br/pkg/restore/rawkv_client_test.go | 3 +- br/pkg/storage/azblob.go | 5 +- br/pkg/storage/compress.go | 1 - br/pkg/storage/s3.go | 5 +- br/pkg/stream/client.go | 5 +- br/pkg/stream/integration_test.go | 3 +- br/pkg/task/stream_test.go | 1 - build/BUILD.bazel | 1 + build/linter/gci/BUILD.bazel | 13 ++++ build/linter/gci/analysis.go | 65 +++++++++++++++++++ build/nogo_config.json | 12 ++++ cmd/benchraw/main.go | 1 - ddl/serial_test.go | 5 +- ddl/table_split_test.go | 4 +- distsql/select_result_test.go | 1 - dumpling/cli/versions.go | 3 +- dumpling/cmd/dumpling/main.go | 5 +- dumpling/export/block_allow_list.go | 3 +- dumpling/export/block_allow_list_test.go | 5 +- dumpling/export/config.go | 7 +- dumpling/export/conn.go | 3 +- dumpling/export/consistency.go | 1 - dumpling/export/consistency_test.go | 3 +- dumpling/export/dump.go | 7 +- dumpling/export/dump_test.go | 8 +-- dumpling/export/http_handler.go | 5 +- dumpling/export/ir.go | 1 - dumpling/export/ir_impl.go | 3 +- dumpling/export/metadata.go | 3 +- dumpling/export/metadata_test.go | 3 +- dumpling/export/prepare.go | 1 - dumpling/export/prepare_test.go | 3 +- dumpling/export/retry.go | 5 +- dumpling/export/sql.go | 5 +- dumpling/export/sql_test.go | 8 +-- dumpling/export/status.go | 3 +- dumpling/export/util.go | 3 +- dumpling/export/util_for_test.go | 1 - dumpling/export/util_test.go | 3 +- dumpling/export/writer.go | 3 +- dumpling/export/writer_serial_test.go | 5 +- dumpling/export/writer_test.go | 3 +- dumpling/export/writer_util.go | 5 +- executor/benchmark_test.go | 5 +- executor/opt_rule_blacklist.go | 1 - executor/simple.go | 11 ++-- expression/constant_test.go | 3 +- expression/helper_test.go | 3 +- go.mod | 6 +- go.sum | 4 ++ infoschema/tables.go | 15 ++--- owner/manager_test.go | 21 +++--- parser/ast/ddl_test.go | 3 +- parser/charset/encoding_latin1.go | 1 + parser/hintparser_test.go | 3 +- parser/types/field_type_test.go | 5 +- planner/core/fragment_test.go | 4 +- planner/core/planbuilder_test.go | 1 - server/server.go | 3 +- session/session.go | 45 +++++++------ sessiontxn/isolation/optimistic_test.go | 3 +- store/mockstore/unistore/tikv/deadlock.go | 5 +- store/mockstore/unistore/tikv/mvcc/mvcc.go | 1 - tidb-binlog/pump_client/client_test.go | 53 ++++++++------- util/generatedexpr/gen_expr_test.go | 3 +- util/logutil/hex_test.go | 3 +- util/mock/iter_test.go | 1 - util/sem/sem_test.go | 1 - 76 files changed, 268 insertions(+), 222 deletions(-) create mode 100644 build/linter/gci/BUILD.bazel create mode 100644 build/linter/gci/analysis.go diff --git a/DEPS.bzl b/DEPS.bzl index 528f216b3a59d..4b36dbcba743c 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -473,6 +473,14 @@ def go_deps(): sum = "h1:0rkFMAbn5KBKNpJyHQ6Prb95vIKanmAe62KxsrN+sqA=", version = "v0.0.0-20171016134553-529a34b1c186", ) + go_repository( + name = "com_github_daixiang0_gci", + build_file_proto_mode = "disable", + importpath = "github.com/daixiang0/gci", + sum = "h1:+EZ83znNs73C9ZBTM7xhNagMP6gJs5wlptiFiuce5BM=", + version = "v0.3.4", + ) + go_repository( name = "com_github_danjacques_gofslock", build_file_proto_mode = "disable_global", @@ -1250,6 +1258,14 @@ def go_deps(): sum = "h1:5IcZpTvzydCQeHzK4Ef/D5rrSqwxob0t8PQPMybUNFM=", version = "v1.1.2", ) + go_repository( + name = "com_github_hexops_gotextdiff", + build_file_proto_mode = "disable", + importpath = "github.com/hexops/gotextdiff", + sum = "h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=", + version = "v1.0.3", + ) + go_repository( name = "com_github_hpcloud_tail", build_file_proto_mode = "disable_global", diff --git a/br/pkg/lightning/backend/kv/sql2kv.go b/br/pkg/lightning/backend/kv/sql2kv.go index 8a10ce607d9f7..6423e59bcb65a 100644 --- a/br/pkg/lightning/backend/kv/sql2kv.go +++ b/br/pkg/lightning/backend/kv/sql2kv.go @@ -33,7 +33,9 @@ import ( "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/meta/autoid" "github.com/pingcap/tidb/parser/model" - "github.com/pingcap/tidb/parser/mysql" + "github.com/pingcap/tidb/parser/mysql" //nolint: goimports + // Import tidb/planner/core to initialize expression.RewriteAstExpr + _ "github.com/pingcap/tidb/planner/core" "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/table" "github.com/pingcap/tidb/table/tables" @@ -42,9 +44,6 @@ import ( "github.com/pingcap/tidb/util/chunk" "go.uber.org/zap" "go.uber.org/zap/zapcore" - - // Import tidb/planner/core to initialize expression.RewriteAstExpr - _ "github.com/pingcap/tidb/planner/core" ) var ExtraHandleColumnInfo = model.NewExtraHandleColInfo() diff --git a/br/pkg/lightning/backend/local/engine_test.go b/br/pkg/lightning/backend/local/engine_test.go index a0d8592d5398f..c7ffe04b95285 100644 --- a/br/pkg/lightning/backend/local/engine_test.go +++ b/br/pkg/lightning/backend/local/engine_test.go @@ -26,10 +26,9 @@ import ( "github.com/cockroachdb/pebble" "github.com/cockroachdb/pebble/sstable" "github.com/google/uuid" + "github.com/pingcap/tidb/br/pkg/lightning/backend" "github.com/pingcap/tidb/br/pkg/lightning/log" "github.com/stretchr/testify/require" - - "github.com/pingcap/tidb/br/pkg/lightning/backend" ) func TestIngestSSTWithClosedEngine(t *testing.T) { diff --git a/br/pkg/lightning/errormanager/errormanager.go b/br/pkg/lightning/errormanager/errormanager.go index b900d19c3a431..43035716d729c 100644 --- a/br/pkg/lightning/errormanager/errormanager.go +++ b/br/pkg/lightning/errormanager/errormanager.go @@ -25,15 +25,14 @@ import ( "github.com/jedib0t/go-pretty/v6/table" "github.com/jedib0t/go-pretty/v6/text" "github.com/pingcap/errors" - "go.uber.org/multierr" - "go.uber.org/zap" - "golang.org/x/sync/errgroup" - "github.com/pingcap/tidb/br/pkg/lightning/common" "github.com/pingcap/tidb/br/pkg/lightning/config" "github.com/pingcap/tidb/br/pkg/lightning/log" "github.com/pingcap/tidb/br/pkg/redact" "github.com/pingcap/tidb/br/pkg/utils" + "go.uber.org/multierr" + "go.uber.org/zap" + "golang.org/x/sync/errgroup" ) const ( diff --git a/br/pkg/lightning/errormanager/errormanager_test.go b/br/pkg/lightning/errormanager/errormanager_test.go index 38f81b51f0299..88808e35628b8 100644 --- a/br/pkg/lightning/errormanager/errormanager_test.go +++ b/br/pkg/lightning/errormanager/errormanager_test.go @@ -25,12 +25,11 @@ import ( "testing" "github.com/DATA-DOG/go-sqlmock" + "github.com/pingcap/tidb/br/pkg/lightning/config" "github.com/pingcap/tidb/br/pkg/lightning/log" + "github.com/pingcap/tidb/br/pkg/utils" "github.com/stretchr/testify/require" "go.uber.org/atomic" - - "github.com/pingcap/tidb/br/pkg/lightning/config" - "github.com/pingcap/tidb/br/pkg/utils" ) func TestInit(t *testing.T) { diff --git a/br/pkg/lightning/mydump/charset_convertor.go b/br/pkg/lightning/mydump/charset_convertor.go index 53a77816bb5e3..fa5f1ee5ef540 100644 --- a/br/pkg/lightning/mydump/charset_convertor.go +++ b/br/pkg/lightning/mydump/charset_convertor.go @@ -19,10 +19,9 @@ import ( "unicode/utf8" "github.com/pingcap/errors" + "github.com/pingcap/tidb/br/pkg/lightning/config" "golang.org/x/text/encoding" "golang.org/x/text/encoding/simplifiedchinese" - - "github.com/pingcap/tidb/br/pkg/lightning/config" ) // CharsetConvertor is used to convert a character set to utf8mb4 encoding. diff --git a/br/pkg/lightning/mydump/router.go b/br/pkg/lightning/mydump/router.go index c3a6ff3aae161..98ecd4c63e08a 100644 --- a/br/pkg/lightning/mydump/router.go +++ b/br/pkg/lightning/mydump/router.go @@ -7,12 +7,11 @@ import ( "strings" "github.com/pingcap/errors" + "github.com/pingcap/tidb/br/pkg/lightning/config" + "github.com/pingcap/tidb/br/pkg/lightning/log" "github.com/pingcap/tidb/util/filter" "github.com/pingcap/tidb/util/slice" "go.uber.org/zap" - - "github.com/pingcap/tidb/br/pkg/lightning/config" - "github.com/pingcap/tidb/br/pkg/lightning/log" ) type SourceType int diff --git a/br/pkg/lightning/restore/restore_schema_test.go b/br/pkg/lightning/restore/restore_schema_test.go index 7bce917eb828c..d7a585f0c10a3 100644 --- a/br/pkg/lightning/restore/restore_schema_test.go +++ b/br/pkg/lightning/restore/restore_schema_test.go @@ -23,10 +23,6 @@ import ( "github.com/DATA-DOG/go-sqlmock" "github.com/golang/mock/gomock" "github.com/pingcap/errors" - filter "github.com/pingcap/tidb/util/table-filter" - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" - "github.com/pingcap/tidb/br/pkg/lightning/backend" "github.com/pingcap/tidb/br/pkg/lightning/checkpoints" "github.com/pingcap/tidb/br/pkg/lightning/config" @@ -39,6 +35,9 @@ import ( "github.com/pingcap/tidb/parser/model" "github.com/pingcap/tidb/parser/mysql" tmock "github.com/pingcap/tidb/util/mock" + filter "github.com/pingcap/tidb/util/table-filter" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" ) type restoreSchemaSuite struct { diff --git a/br/pkg/restore/rawkv_client_test.go b/br/pkg/restore/rawkv_client_test.go index 1864aca1b0a77..1458ce04ff822 100644 --- a/br/pkg/restore/rawkv_client_test.go +++ b/br/pkg/restore/rawkv_client_test.go @@ -12,10 +12,9 @@ import ( berrors "github.com/pingcap/tidb/br/pkg/errors" "github.com/pingcap/tidb/br/pkg/restore" "github.com/pingcap/tidb/kv" + "github.com/pingcap/tidb/util/codec" "github.com/stretchr/testify/require" "github.com/tikv/client-go/v2/rawkv" - - "github.com/pingcap/tidb/util/codec" ) // fakeRawkvClient is a mock for rawkv.client diff --git a/br/pkg/storage/azblob.go b/br/pkg/storage/azblob.go index 08f25cbe06bf1..24c3b06930025 100644 --- a/br/pkg/storage/azblob.go +++ b/br/pkg/storage/azblob.go @@ -12,15 +12,14 @@ import ( "path" "strings" - "github.com/google/uuid" - "github.com/spf13/pflag" - "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" + "github.com/google/uuid" "github.com/pingcap/errors" backuppb "github.com/pingcap/kvproto/pkg/brpb" "github.com/pingcap/log" berrors "github.com/pingcap/tidb/br/pkg/errors" + "github.com/spf13/pflag" "go.uber.org/zap" ) diff --git a/br/pkg/storage/compress.go b/br/pkg/storage/compress.go index 34e4796b34810..fc0976420996b 100644 --- a/br/pkg/storage/compress.go +++ b/br/pkg/storage/compress.go @@ -8,7 +8,6 @@ import ( "io" "github.com/pingcap/errors" - berrors "github.com/pingcap/tidb/br/pkg/errors" ) diff --git a/br/pkg/storage/s3.go b/br/pkg/storage/s3.go index b75da76505123..3bdcf7cab4d2b 100644 --- a/br/pkg/storage/s3.go +++ b/br/pkg/storage/s3.go @@ -27,11 +27,10 @@ import ( "github.com/pingcap/errors" backuppb "github.com/pingcap/kvproto/pkg/brpb" "github.com/pingcap/log" - "github.com/spf13/pflag" - "go.uber.org/zap" - berrors "github.com/pingcap/tidb/br/pkg/errors" "github.com/pingcap/tidb/br/pkg/logutil" + "github.com/spf13/pflag" + "go.uber.org/zap" ) const ( diff --git a/br/pkg/stream/client.go b/br/pkg/stream/client.go index 5eadee73af36d..3ae88605ca7f1 100644 --- a/br/pkg/stream/client.go +++ b/br/pkg/stream/client.go @@ -10,14 +10,13 @@ import ( "github.com/gogo/protobuf/proto" "github.com/pingcap/errors" - "github.com/pingcap/log" - "go.uber.org/zap" - backuppb "github.com/pingcap/kvproto/pkg/brpb" + "github.com/pingcap/log" berrors "github.com/pingcap/tidb/br/pkg/errors" "github.com/pingcap/tidb/br/pkg/redact" "github.com/pingcap/tidb/kv" clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" ) // MetaDataClient is the client for operations over metadata. diff --git a/br/pkg/stream/integration_test.go b/br/pkg/stream/integration_test.go index cbb253b1fcc60..92a465172afec 100644 --- a/br/pkg/stream/integration_test.go +++ b/br/pkg/stream/integration_test.go @@ -10,10 +10,9 @@ import ( "net/url" "testing" - berrors "github.com/pingcap/tidb/br/pkg/errors" - "github.com/pingcap/errors" "github.com/pingcap/log" + berrors "github.com/pingcap/tidb/br/pkg/errors" "github.com/pingcap/tidb/br/pkg/logutil" "github.com/pingcap/tidb/br/pkg/storage" "github.com/pingcap/tidb/br/pkg/stream" diff --git a/br/pkg/task/stream_test.go b/br/pkg/task/stream_test.go index 3b13f8657c0e2..3313351132585 100644 --- a/br/pkg/task/stream_test.go +++ b/br/pkg/task/stream_test.go @@ -25,7 +25,6 @@ import ( "github.com/pingcap/errors" backuppb "github.com/pingcap/kvproto/pkg/brpb" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/tidb/br/pkg/conn" "github.com/pingcap/tidb/br/pkg/pdutil" diff --git a/build/BUILD.bazel b/build/BUILD.bazel index ea8958f219b75..215244513658f 100644 --- a/build/BUILD.bazel +++ b/build/BUILD.bazel @@ -124,6 +124,7 @@ nogo( "//build/linter/durationcheck:durationcheck", "//build/linter/exportloopref:exportloopref", "//build/linter/gofmt:gofmt", + "//build/linter/gci:gci", "//build/linter/ineffassign:ineffassign", "//build/linter/misspell:misspell", "//build/linter/prealloc:prealloc", diff --git a/build/linter/gci/BUILD.bazel b/build/linter/gci/BUILD.bazel new file mode 100644 index 0000000000000..9318955d516bd --- /dev/null +++ b/build/linter/gci/BUILD.bazel @@ -0,0 +1,13 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "gci", + srcs = ["analysis.go"], + importpath = "github.com/pingcap/tidb/build/linter/gci", + visibility = ["//visibility:public"], + deps = [ + "@com_github_daixiang0_gci//pkg/configuration", + "@com_github_daixiang0_gci//pkg/gci", + "@org_golang_x_tools//go/analysis", + ], +) diff --git a/build/linter/gci/analysis.go b/build/linter/gci/analysis.go new file mode 100644 index 0000000000000..6ac0854302160 --- /dev/null +++ b/build/linter/gci/analysis.go @@ -0,0 +1,65 @@ +// Copyright 2022 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package gci + +import ( + "fmt" + "sync" + + "github.com/daixiang0/gci/pkg/configuration" + "github.com/daixiang0/gci/pkg/gci" + "golang.org/x/tools/go/analysis" +) + +// Analyzer is the analyzer struct of gci. +var Analyzer = &analysis.Analyzer{ + Name: "gci", + Doc: "Gci controls golang package import order and makes it always deterministic.", + Run: run, +} + +func run(pass *analysis.Pass) (any, error) { + fileNames := make([]string, 0, len(pass.Files)) + for _, f := range pass.Files { + pos := pass.Fset.PositionFor(f.Pos(), false) + fileNames = append(fileNames, pos.Filename) + } + var rawCfg gci.GciStringConfiguration + rawCfg.Cfg = configuration.FormatterConfiguration{ + NoInlineComments: false, + NoPrefixComments: false, + Debug: false, + } + cfg, _ := rawCfg.Parse() + var diffs []string + var lock sync.Mutex + err := gci.DiffFormattedFilesToArray(fileNames, *cfg, &diffs, &lock) + if err != nil { + return nil, err + } + + for _, diff := range diffs { + if diff == "" { + continue + } + + pass.Report(analysis.Diagnostic{ + Pos: 1, + Message: fmt.Sprintf("\n%s", diff), + }) + } + + return nil, nil +} diff --git a/build/nogo_config.json b/build/nogo_config.json index b5edb72788f4f..bd890a8f55832 100644 --- a/build/nogo_config.json +++ b/build/nogo_config.json @@ -142,6 +142,18 @@ ".*failpoint_binding__.go$": "ignore generated code" } }, + "gci": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code", + "/cgo/": "ignore cgo code", + ".*\\.pb\\.go$": "generated code", + "/rules_go_work-*": "ignore generated code", + ".*test_/testmain\\.go$": "ignore generated code", + ".*failpoint_binding__.go$": "ignore generated code", + "util/printer/printer.go": "ignore util/printer code" + } + }, "httpresponse": { "exclude_files": { "/external/": "no need to vet third party code", diff --git a/cmd/benchraw/main.go b/cmd/benchraw/main.go index 3bcce7dec621c..80f1a1d2289bc 100644 --- a/cmd/benchraw/main.go +++ b/cmd/benchraw/main.go @@ -30,7 +30,6 @@ import ( "github.com/pingcap/tidb/parser/terror" "github.com/tikv/client-go/v2/config" "github.com/tikv/client-go/v2/rawkv" - "go.uber.org/zap" ) diff --git a/ddl/serial_test.go b/ddl/serial_test.go index a588b8a16169a..7d5c2c55a2d89 100644 --- a/ddl/serial_test.go +++ b/ddl/serial_test.go @@ -28,7 +28,6 @@ import ( "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/ddl" "github.com/pingcap/tidb/ddl/util" - ddlutil "github.com/pingcap/tidb/ddl/util" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/infoschema" @@ -726,7 +725,7 @@ func TestCancelJobByErrorCountLimit(t *testing.T) { limit := variable.GetDDLErrorCountLimit() tk.MustExec("set @@global.tidb_ddl_error_count_limit = 16") - err := ddlutil.LoadDDLVars(tk.Session()) + err := util.LoadDDLVars(tk.Session()) require.NoError(t, err) defer tk.MustExec(fmt.Sprintf("set @@global.tidb_ddl_error_count_limit = %d", limit)) @@ -744,7 +743,7 @@ func TestTruncateTableUpdateSchemaVersionErr(t *testing.T) { limit := variable.GetDDLErrorCountLimit() tk.MustExec("set @@global.tidb_ddl_error_count_limit = 5") - err := ddlutil.LoadDDLVars(tk.Session()) + err := util.LoadDDLVars(tk.Session()) require.NoError(t, err) defer tk.MustExec(fmt.Sprintf("set @@global.tidb_ddl_error_count_limit = %d", limit)) diff --git a/ddl/table_split_test.go b/ddl/table_split_test.go index 299abe09fb686..ad944215a6550 100644 --- a/ddl/table_split_test.go +++ b/ddl/table_split_test.go @@ -26,10 +26,8 @@ import ( "github.com/pingcap/tidb/store/mockstore" "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/testkit" - - "github.com/tikv/client-go/v2/tikv" - "github.com/stretchr/testify/require" + "github.com/tikv/client-go/v2/tikv" ) func TestTableSplit(t *testing.T) { diff --git a/distsql/select_result_test.go b/distsql/select_result_test.go index 622e672e1ee9d..c12892083d641 100644 --- a/distsql/select_result_test.go +++ b/distsql/select_result_test.go @@ -24,7 +24,6 @@ import ( "github.com/pingcap/tidb/util/execdetails" "github.com/pingcap/tidb/util/mock" "github.com/pingcap/tipb/go-tipb" - "github.com/stretchr/testify/require" ) diff --git a/dumpling/cli/versions.go b/dumpling/cli/versions.go index 2d29dd1296bd6..ad55c6ae9539f 100644 --- a/dumpling/cli/versions.go +++ b/dumpling/cli/versions.go @@ -16,9 +16,8 @@ package cli import ( "fmt" - "go.uber.org/zap" - "github.com/pingcap/tidb/dumpling/log" + "go.uber.org/zap" ) var ( diff --git a/dumpling/cmd/dumpling/main.go b/dumpling/cmd/dumpling/main.go index 3d72df1e694ea..5e4b8d8f0521b 100644 --- a/dumpling/cmd/dumpling/main.go +++ b/dumpling/cmd/dumpling/main.go @@ -18,13 +18,12 @@ import ( "fmt" "os" + "github.com/pingcap/tidb/dumpling/cli" + "github.com/pingcap/tidb/dumpling/export" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/collectors" "github.com/spf13/pflag" "go.uber.org/zap" - - "github.com/pingcap/tidb/dumpling/cli" - "github.com/pingcap/tidb/dumpling/export" ) func main() { diff --git a/dumpling/export/block_allow_list.go b/dumpling/export/block_allow_list.go index 2ce925abe02da..a3d4852b50c65 100644 --- a/dumpling/export/block_allow_list.go +++ b/dumpling/export/block_allow_list.go @@ -3,9 +3,8 @@ package export import ( - "go.uber.org/zap" - tcontext "github.com/pingcap/tidb/dumpling/context" + "go.uber.org/zap" ) func filterDatabases(tctx *tcontext.Context, conf *Config, databases []string) []string { diff --git a/dumpling/export/block_allow_list_test.go b/dumpling/export/block_allow_list_test.go index 640e9cef7e4dc..28faa4e95f261 100644 --- a/dumpling/export/block_allow_list_test.go +++ b/dumpling/export/block_allow_list_test.go @@ -6,12 +6,11 @@ import ( "strings" "testing" + "github.com/pingcap/tidb/br/pkg/version" + tcontext "github.com/pingcap/tidb/dumpling/context" "github.com/pingcap/tidb/util/filter" tf "github.com/pingcap/tidb/util/table-filter" "github.com/stretchr/testify/require" - - "github.com/pingcap/tidb/br/pkg/version" - tcontext "github.com/pingcap/tidb/dumpling/context" ) func TestFilterTables(t *testing.T) { diff --git a/dumpling/export/config.go b/dumpling/export/config.go index b74799c39d8d2..d9fa184643415 100644 --- a/dumpling/export/config.go +++ b/dumpling/export/config.go @@ -17,15 +17,14 @@ import ( "github.com/docker/go-units" "github.com/go-sql-driver/mysql" "github.com/pingcap/errors" - "github.com/prometheus/client_golang/prometheus" - "github.com/spf13/pflag" - "go.uber.org/zap" - "github.com/pingcap/tidb/br/pkg/storage" "github.com/pingcap/tidb/br/pkg/version" "github.com/pingcap/tidb/util" "github.com/pingcap/tidb/util/promutil" filter "github.com/pingcap/tidb/util/table-filter" + "github.com/prometheus/client_golang/prometheus" + "github.com/spf13/pflag" + "go.uber.org/zap" ) const ( diff --git a/dumpling/export/conn.go b/dumpling/export/conn.go index c6723865b7003..c981febe19450 100644 --- a/dumpling/export/conn.go +++ b/dumpling/export/conn.go @@ -6,10 +6,9 @@ import ( "database/sql" "github.com/pingcap/errors" - "go.uber.org/zap" - "github.com/pingcap/tidb/br/pkg/utils" tcontext "github.com/pingcap/tidb/dumpling/context" + "go.uber.org/zap" ) // BaseConn wraps connection instance. diff --git a/dumpling/export/consistency.go b/dumpling/export/consistency.go index 2af2abaa7d19c..6e0f65960f275 100644 --- a/dumpling/export/consistency.go +++ b/dumpling/export/consistency.go @@ -7,7 +7,6 @@ import ( "database/sql" "github.com/pingcap/errors" - "github.com/pingcap/tidb/br/pkg/utils" "github.com/pingcap/tidb/br/pkg/version" tcontext "github.com/pingcap/tidb/dumpling/context" diff --git a/dumpling/export/consistency_test.go b/dumpling/export/consistency_test.go index cd81d27db11f5..97f94a16a0334 100644 --- a/dumpling/export/consistency_test.go +++ b/dumpling/export/consistency_test.go @@ -10,11 +10,10 @@ import ( "github.com/DATA-DOG/go-sqlmock" "github.com/go-sql-driver/mysql" - "github.com/stretchr/testify/require" - "github.com/pingcap/tidb/br/pkg/version" dbconfig "github.com/pingcap/tidb/config" tcontext "github.com/pingcap/tidb/dumpling/context" + "github.com/stretchr/testify/require" ) func TestConsistencyController(t *testing.T) { diff --git a/dumpling/export/dump.go b/dumpling/export/dump.go index 43d801430e6e8..50a55646e6967 100755 --- a/dumpling/export/dump.go +++ b/dumpling/export/dump.go @@ -20,10 +20,6 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/failpoint" pclog "github.com/pingcap/log" - pd "github.com/tikv/pd/client" - "go.uber.org/zap" - "golang.org/x/sync/errgroup" - "github.com/pingcap/tidb/br/pkg/storage" "github.com/pingcap/tidb/br/pkg/summary" "github.com/pingcap/tidb/br/pkg/version" @@ -36,6 +32,9 @@ import ( "github.com/pingcap/tidb/store/helper" "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/util/codec" + pd "github.com/tikv/pd/client" + "go.uber.org/zap" + "golang.org/x/sync/errgroup" ) var openDBFunc = sql.Open diff --git a/dumpling/export/dump_test.go b/dumpling/export/dump_test.go index b059a1ae28ac2..51e522bf4824b 100644 --- a/dumpling/export/dump_test.go +++ b/dumpling/export/dump_test.go @@ -9,15 +9,13 @@ import ( "time" "github.com/DATA-DOG/go-sqlmock" - "github.com/pingcap/tidb/util/promutil" - "github.com/stretchr/testify/require" - "golang.org/x/sync/errgroup" - "github.com/pingcap/errors" - "github.com/pingcap/tidb/br/pkg/version" tcontext "github.com/pingcap/tidb/dumpling/context" "github.com/pingcap/tidb/parser" + "github.com/pingcap/tidb/util/promutil" + "github.com/stretchr/testify/require" + "golang.org/x/sync/errgroup" ) func TestDumpBlock(t *testing.T) { diff --git a/dumpling/export/http_handler.go b/dumpling/export/http_handler.go index 91332736f17f2..ca861dd11e8bc 100644 --- a/dumpling/export/http_handler.go +++ b/dumpling/export/http_handler.go @@ -10,11 +10,10 @@ import ( "time" "github.com/pingcap/errors" - "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/soheilhy/cmux" - tcontext "github.com/pingcap/tidb/dumpling/context" "github.com/pingcap/tidb/dumpling/log" + "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/soheilhy/cmux" ) var cmuxReadTimeout = 10 * time.Second diff --git a/dumpling/export/ir.go b/dumpling/export/ir.go index b74d7dc1dfef3..4b98019605e9c 100644 --- a/dumpling/export/ir.go +++ b/dumpling/export/ir.go @@ -8,7 +8,6 @@ import ( "strings" "github.com/pingcap/errors" - tcontext "github.com/pingcap/tidb/dumpling/context" ) diff --git a/dumpling/export/ir_impl.go b/dumpling/export/ir_impl.go index 57a14f5a66d11..d51462b59ab01 100644 --- a/dumpling/export/ir_impl.go +++ b/dumpling/export/ir_impl.go @@ -7,9 +7,8 @@ import ( "strings" "github.com/pingcap/errors" - "go.uber.org/zap" - tcontext "github.com/pingcap/tidb/dumpling/context" + "go.uber.org/zap" ) // rowIter implements the SQLRowIter interface. diff --git a/dumpling/export/metadata.go b/dumpling/export/metadata.go index d4ffa3c7aa3d2..7d2cf53128688 100644 --- a/dumpling/export/metadata.go +++ b/dumpling/export/metadata.go @@ -11,11 +11,10 @@ import ( "time" "github.com/pingcap/errors" - "go.uber.org/zap" - "github.com/pingcap/tidb/br/pkg/storage" "github.com/pingcap/tidb/br/pkg/version" tcontext "github.com/pingcap/tidb/dumpling/context" + "go.uber.org/zap" ) type globalMetadata struct { diff --git a/dumpling/export/metadata_test.go b/dumpling/export/metadata_test.go index dc67c73628b87..90099bbf00acd 100644 --- a/dumpling/export/metadata_test.go +++ b/dumpling/export/metadata_test.go @@ -10,11 +10,10 @@ import ( "testing" "github.com/DATA-DOG/go-sqlmock" - "github.com/stretchr/testify/require" - "github.com/pingcap/tidb/br/pkg/storage" "github.com/pingcap/tidb/br/pkg/version" tcontext "github.com/pingcap/tidb/dumpling/context" + "github.com/stretchr/testify/require" ) const ( diff --git a/dumpling/export/prepare.go b/dumpling/export/prepare.go index 1d9d05304c7cf..0878ce31f8666 100644 --- a/dumpling/export/prepare.go +++ b/dumpling/export/prepare.go @@ -10,7 +10,6 @@ import ( "text/template" "github.com/pingcap/errors" - tcontext "github.com/pingcap/tidb/dumpling/context" ) diff --git a/dumpling/export/prepare_test.go b/dumpling/export/prepare_test.go index ad326a412c4a3..f9f559448d078 100644 --- a/dumpling/export/prepare_test.go +++ b/dumpling/export/prepare_test.go @@ -9,9 +9,8 @@ import ( "testing" "github.com/DATA-DOG/go-sqlmock" - "github.com/stretchr/testify/require" - tcontext "github.com/pingcap/tidb/dumpling/context" + "github.com/stretchr/testify/require" ) func TestPrepareDumpingDatabases(t *testing.T) { diff --git a/dumpling/export/retry.go b/dumpling/export/retry.go index f2bd998df8ccb..ad49f46b76c65 100644 --- a/dumpling/export/retry.go +++ b/dumpling/export/retry.go @@ -8,11 +8,10 @@ import ( "github.com/go-sql-driver/mysql" "github.com/pingcap/errors" - "github.com/pingcap/tidb/util/dbutil" - "go.uber.org/zap" - "github.com/pingcap/tidb/br/pkg/utils" tcontext "github.com/pingcap/tidb/dumpling/context" + "github.com/pingcap/tidb/util/dbutil" + "go.uber.org/zap" ) const ( diff --git a/dumpling/export/sql.go b/dumpling/export/sql.go index 9f866209241b5..ad78158bb27a8 100644 --- a/dumpling/export/sql.go +++ b/dumpling/export/sql.go @@ -17,9 +17,6 @@ import ( "github.com/go-sql-driver/mysql" "github.com/pingcap/errors" "github.com/pingcap/failpoint" - "go.uber.org/multierr" - "go.uber.org/zap" - "github.com/pingcap/tidb/br/pkg/version" dbconfig "github.com/pingcap/tidb/config" tcontext "github.com/pingcap/tidb/dumpling/context" @@ -27,6 +24,8 @@ import ( "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/parser/model" "github.com/pingcap/tidb/store/helper" + "go.uber.org/multierr" + "go.uber.org/zap" ) const ( diff --git a/dumpling/export/sql_test.go b/dumpling/export/sql_test.go index a752df681c146..d79f74993c10b 100644 --- a/dumpling/export/sql_test.go +++ b/dumpling/export/sql_test.go @@ -15,16 +15,14 @@ import ( "strings" "testing" - "github.com/go-sql-driver/mysql" - "github.com/pingcap/tidb/util/promutil" - "github.com/DATA-DOG/go-sqlmock" + "github.com/go-sql-driver/mysql" "github.com/pingcap/errors" - "github.com/stretchr/testify/require" - "github.com/pingcap/tidb/br/pkg/version" dbconfig "github.com/pingcap/tidb/config" tcontext "github.com/pingcap/tidb/dumpling/context" + "github.com/pingcap/tidb/util/promutil" + "github.com/stretchr/testify/require" ) var showIndexHeaders = []string{ diff --git a/dumpling/export/status.go b/dumpling/export/status.go index 4b7e706898724..e7d708bb49f2f 100644 --- a/dumpling/export/status.go +++ b/dumpling/export/status.go @@ -8,9 +8,8 @@ import ( "time" "github.com/docker/go-units" - "go.uber.org/zap" - tcontext "github.com/pingcap/tidb/dumpling/context" + "go.uber.org/zap" ) const logProgressTick = 2 * time.Minute diff --git a/dumpling/export/util.go b/dumpling/export/util.go index 1506a424946f3..5d43a1cf5a1d9 100644 --- a/dumpling/export/util.go +++ b/dumpling/export/util.go @@ -10,10 +10,9 @@ import ( "time" "github.com/pingcap/errors" - clientv3 "go.etcd.io/etcd/client/v3" - "github.com/pingcap/tidb/br/pkg/version" tcontext "github.com/pingcap/tidb/dumpling/context" + clientv3 "go.etcd.io/etcd/client/v3" ) const tidbServerInformationPath = "/tidb/server/info" diff --git a/dumpling/export/util_for_test.go b/dumpling/export/util_for_test.go index 67d7f62f9fcfb..739a431b2230e 100644 --- a/dumpling/export/util_for_test.go +++ b/dumpling/export/util_for_test.go @@ -9,7 +9,6 @@ import ( "fmt" "github.com/DATA-DOG/go-sqlmock" - tcontext "github.com/pingcap/tidb/dumpling/context" ) diff --git a/dumpling/export/util_test.go b/dumpling/export/util_test.go index 5932dcc9888f4..1686a24902825 100644 --- a/dumpling/export/util_test.go +++ b/dumpling/export/util_test.go @@ -6,9 +6,8 @@ import ( "fmt" "testing" - "github.com/stretchr/testify/require" - "github.com/pingcap/tidb/br/pkg/version" + "github.com/stretchr/testify/require" ) func TestRepeatableRead(t *testing.T) { diff --git a/dumpling/export/writer.go b/dumpling/export/writer.go index 06ba5a1605b29..d3545aa2e4f18 100644 --- a/dumpling/export/writer.go +++ b/dumpling/export/writer.go @@ -10,11 +10,10 @@ import ( "text/template" "github.com/pingcap/errors" - "go.uber.org/zap" - "github.com/pingcap/tidb/br/pkg/storage" "github.com/pingcap/tidb/br/pkg/utils" tcontext "github.com/pingcap/tidb/dumpling/context" + "go.uber.org/zap" ) // Writer is the abstraction that keep pulling data from database and write to files. diff --git a/dumpling/export/writer_serial_test.go b/dumpling/export/writer_serial_test.go index d08015cb9d0c0..2290ca86cdfa2 100644 --- a/dumpling/export/writer_serial_test.go +++ b/dumpling/export/writer_serial_test.go @@ -9,11 +9,10 @@ import ( "testing" "github.com/pingcap/errors" - "github.com/pingcap/tidb/util/promutil" - "github.com/stretchr/testify/require" - "github.com/pingcap/tidb/br/pkg/storage" tcontext "github.com/pingcap/tidb/dumpling/context" + "github.com/pingcap/tidb/util/promutil" + "github.com/stretchr/testify/require" ) func TestWriteMeta(t *testing.T) { diff --git a/dumpling/export/writer_test.go b/dumpling/export/writer_test.go index 93fde0ebdd5e4..4192a86179163 100644 --- a/dumpling/export/writer_test.go +++ b/dumpling/export/writer_test.go @@ -12,10 +12,9 @@ import ( "testing" "github.com/DATA-DOG/go-sqlmock" + tcontext "github.com/pingcap/tidb/dumpling/context" "github.com/pingcap/tidb/util/promutil" "github.com/stretchr/testify/require" - - tcontext "github.com/pingcap/tidb/dumpling/context" ) func TestWriteDatabaseMeta(t *testing.T) { diff --git a/dumpling/export/writer_util.go b/dumpling/export/writer_util.go index d3aa417d550b8..c43a1d140cab4 100755 --- a/dumpling/export/writer_util.go +++ b/dumpling/export/writer_util.go @@ -13,13 +13,12 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/failpoint" - "github.com/prometheus/client_golang/prometheus" - "go.uber.org/zap" - "github.com/pingcap/tidb/br/pkg/storage" "github.com/pingcap/tidb/br/pkg/summary" tcontext "github.com/pingcap/tidb/dumpling/context" "github.com/pingcap/tidb/dumpling/log" + "github.com/prometheus/client_golang/prometheus" + "go.uber.org/zap" ) const lengthLimit = 1048576 diff --git a/executor/benchmark_test.go b/executor/benchmark_test.go index d843da3b3d415..bba2c176d2877 100644 --- a/executor/benchmark_test.go +++ b/executor/benchmark_test.go @@ -34,7 +34,6 @@ import ( "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/planner/core" - plannercore "github.com/pingcap/tidb/planner/core" "github.com/pingcap/tidb/planner/property" "github.com/pingcap/tidb/planner/util" "github.com/pingcap/tidb/sessionctx" @@ -567,8 +566,8 @@ func buildWindowExecutor(ctx sessionctx.Context, windowFunc string, funcs int, f plan = core.PhysicalShuffle{ Concurrency: concurrency, - Tails: []plannercore.PhysicalPlan{tail}, - DataSources: []plannercore.PhysicalPlan{src}, + Tails: []core.PhysicalPlan{tail}, + DataSources: []core.PhysicalPlan{src}, SplitterType: core.PartitionHashSplitterType, ByItemArrays: [][]expression.Expression{byItems}, }.Init(ctx, nil, 0) diff --git a/executor/opt_rule_blacklist.go b/executor/opt_rule_blacklist.go index 2b80adecd4383..f711d2feacb03 100644 --- a/executor/opt_rule_blacklist.go +++ b/executor/opt_rule_blacklist.go @@ -18,7 +18,6 @@ import ( "context" "github.com/pingcap/tidb/kv" - plannercore "github.com/pingcap/tidb/planner/core" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/util/chunk" diff --git a/executor/simple.go b/executor/simple.go index 5568ab5c5b4d9..a7794d4fb8498 100644 --- a/executor/simple.go +++ b/executor/simple.go @@ -39,7 +39,6 @@ import ( "github.com/pingcap/tidb/parser/model" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/planner/core" - plannercore "github.com/pingcap/tidb/planner/core" "github.com/pingcap/tidb/plugin" "github.com/pingcap/tidb/privilege" "github.com/pingcap/tidb/sessionctx" @@ -953,13 +952,13 @@ func (e *SimpleExec) executeAlterUser(ctx context.Context, s *ast.AlterUserStmt) // For simplicity: RESTRICTED_USER_ADMIN also counts for SYSTEM_USER here. if !(hasCreateUserPriv || hasSystemSchemaPriv) { - return plannercore.ErrSpecificAccessDenied.GenWithStackByArgs("CREATE USER") + return core.ErrSpecificAccessDenied.GenWithStackByArgs("CREATE USER") } if checker.RequestDynamicVerificationWithUser("SYSTEM_USER", false, spec.User) && !(hasSystemUserPriv || hasRestrictedUserPriv) { - return plannercore.ErrSpecificAccessDenied.GenWithStackByArgs("SYSTEM_USER or SUPER") + return core.ErrSpecificAccessDenied.GenWithStackByArgs("SYSTEM_USER or SUPER") } if sem.IsEnabled() && checker.RequestDynamicVerificationWithUser("RESTRICTED_USER_ADMIN", false, spec.User) && !hasRestrictedUserPriv { - return plannercore.ErrSpecificAccessDenied.GenWithStackByArgs("RESTRICTED_USER_ADMIN") + return core.ErrSpecificAccessDenied.GenWithStackByArgs("RESTRICTED_USER_ADMIN") } } @@ -1270,7 +1269,7 @@ func (e *SimpleExec) executeDropUser(ctx context.Context, s *ast.DropUserStmt) e if _, err := sqlExecutor.ExecuteInternal(internalCtx, "rollback"); err != nil { return err } - return plannercore.ErrSpecificAccessDenied.GenWithStackByArgs("SYSTEM_USER or SUPER") + return core.ErrSpecificAccessDenied.GenWithStackByArgs("SYSTEM_USER or SUPER") } // begin a transaction to delete a user. @@ -1738,7 +1737,7 @@ func (e *SimpleExec) executeAdminFlushPlanCache(s *ast.AdminStmt) error { if s.StatementScope == ast.StatementScopeGlobal { return errors.New("Do not support the 'admin flush global scope.'") } - if !plannercore.PreparedPlanCacheEnabled() { + if !core.PreparedPlanCacheEnabled() { e.ctx.GetSessionVars().StmtCtx.AppendWarning(errors.New("The plan cache is disable. So there no need to flush the plan cache")) return nil } diff --git a/expression/constant_test.go b/expression/constant_test.go index 50e5c5ce98ecc..e118fdd6a125a 100644 --- a/expression/constant_test.go +++ b/expression/constant_test.go @@ -21,14 +21,13 @@ import ( "testing" "time" - "github.com/stretchr/testify/require" - "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/mock" + "github.com/stretchr/testify/require" ) func newColumn(id int) *Column { diff --git a/expression/helper_test.go b/expression/helper_test.go index beb69528b02cf..ed75ca82f2c25 100644 --- a/expression/helper_test.go +++ b/expression/helper_test.go @@ -20,8 +20,6 @@ import ( "testing" "time" - "github.com/stretchr/testify/require" - "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/charset" "github.com/pingcap/tidb/parser/model" @@ -30,6 +28,7 @@ import ( "github.com/pingcap/tidb/types" driver "github.com/pingcap/tidb/types/parser_driver" "github.com/pingcap/tidb/util/mock" + "github.com/stretchr/testify/require" ) func TestGetTimeValue(t *testing.T) { diff --git a/go.mod b/go.mod index 64211d111e21b..fdf5368b379f2 100644 --- a/go.mod +++ b/go.mod @@ -98,6 +98,7 @@ require ( require ( github.com/aliyun/alibaba-cloud-sdk-go v1.61.1581 github.com/charithe/durationcheck v0.0.9 + github.com/daixiang0/gci v0.3.4 github.com/golangci/gofmt v0.0.0-20190930125516-244bba706f1a github.com/golangci/misspell v0.3.5 github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4 @@ -109,7 +110,10 @@ require ( honnef.co/go/tools v0.0.1-2020.1.4 ) -require github.com/kisielk/gotool v1.0.0 // indirect +require ( + github.com/hexops/gotextdiff v1.0.3 // indirect + github.com/kisielk/gotool v1.0.0 // indirect +) require ( cloud.google.com/go v0.100.2 // indirect diff --git a/go.sum b/go.sum index efdf0b627e904..5d700817a2652 100644 --- a/go.sum +++ b/go.sum @@ -193,6 +193,8 @@ github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 h1:iwZdTE0PVqJCos1v github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548/go.mod h1:e6NPNENfs9mPDVNRekM7lKScauxd5kXTr1Mfyig6TDM= github.com/cznic/sortutil v0.0.0-20181122101858-f5f958428db8/go.mod h1:q2w6Bg5jeox1B+QkJ6Wp/+Vn0G/bo3f1uY7Fn3vivIQ= github.com/cznic/strutil v0.0.0-20171016134553-529a34b1c186/go.mod h1:AHHPPPXTw0h6pVabbcbyGRK1DckRn7r/STdZEeIDzZc= +github.com/daixiang0/gci v0.3.4 h1:+EZ83znNs73C9ZBTM7xhNagMP6gJs5wlptiFiuce5BM= +github.com/daixiang0/gci v0.3.4/go.mod h1:pB1j339Q+2sv/EyKd4dgvGXcaBGIErim+dlhLDtqeW4= github.com/danjacques/gofslock v0.0.0-20191023191349-0a45f885bc37 h1:X6mKGhCFOxrKeeHAjv/3UvT6e5RRxW6wRdlqlV6/H4w= github.com/danjacques/gofslock v0.0.0-20191023191349-0a45f885bc37/go.mod h1:DC3JtzuG7kxMvJ6dZmf2ymjNyoXwgtklr7FN+Um2B0U= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -450,6 +452,8 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= +github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hydrogen18/memlistener v0.0.0-20141126152155-54553eb933fb/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE= github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0= diff --git a/infoschema/tables.go b/infoschema/tables.go index 622eb1ef9452c..b71646f1f0043 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -27,19 +27,15 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/metapb" - "github.com/pingcap/tidb/parser/charset" - "github.com/pingcap/tidb/parser/model" - "github.com/pingcap/tidb/parser/mysql" - "github.com/pingcap/tidb/parser/terror" - "github.com/pingcap/tidb/util/logutil" - "github.com/pingcap/tidb/util/stmtsummary" - "go.uber.org/zap" - "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/ddl/placement" "github.com/pingcap/tidb/domain/infosync" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta/autoid" + "github.com/pingcap/tidb/parser/charset" + "github.com/pingcap/tidb/parser/model" + "github.com/pingcap/tidb/parser/mysql" + "github.com/pingcap/tidb/parser/terror" "github.com/pingcap/tidb/session/txninfo" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/sessionctx/variable" @@ -48,8 +44,11 @@ import ( "github.com/pingcap/tidb/util" "github.com/pingcap/tidb/util/deadlockhistory" "github.com/pingcap/tidb/util/execdetails" + "github.com/pingcap/tidb/util/logutil" "github.com/pingcap/tidb/util/pdapi" + "github.com/pingcap/tidb/util/stmtsummary" "github.com/tikv/client-go/v2/tikv" + "go.uber.org/zap" ) const ( diff --git a/owner/manager_test.go b/owner/manager_test.go index 3668c4d060ad2..24627750d855d 100644 --- a/owner/manager_test.go +++ b/owner/manager_test.go @@ -16,7 +16,6 @@ package owner_test import ( "context" - goctx "context" "fmt" "runtime" "testing" @@ -54,7 +53,7 @@ func TestSingle(t *testing.T) { defer cluster.Terminate(t) client := cluster.RandClient() - ctx := goctx.Background() + ctx := context.Background() ic := infoschema.NewCache(2) ic.Insert(infoschema.MockInfoSchemaWithSchemaVer(nil, 0), 0) d := NewDDL( @@ -69,13 +68,13 @@ func TestSingle(t *testing.T) { require.True(t, isOwner) // test for newSession failed - ctx, cancel := goctx.WithCancel(ctx) + ctx, cancel := context.WithCancel(ctx) manager := owner.NewOwnerManager(ctx, client, "ddl", "ddl_id", DDLOwnerKey) cancel() err = manager.CampaignOwner() comment := fmt.Sprintf("campaigned result don't match, err %v", err) - require.True(t, terror.ErrorEqual(err, goctx.Canceled) || terror.ErrorEqual(err, goctx.DeadlineExceeded), comment) + require.True(t, terror.ErrorEqual(err, context.Canceled) || terror.ErrorEqual(err, context.DeadlineExceeded), comment) isOwner = checkOwner(d, true) require.True(t, isOwner) @@ -88,7 +87,7 @@ func TestSingle(t *testing.T) { time.Sleep(200 * time.Millisecond) // err is ok to be not nil since we canceled the manager. - ownerID, _ := manager.GetOwnerID(goctx.Background()) + ownerID, _ := manager.GetOwnerID(context.Background()) require.Equal(t, "", ownerID) } @@ -118,7 +117,7 @@ func TestCluster(t *testing.T) { ic := infoschema.NewCache(2) ic.Insert(infoschema.MockInfoSchemaWithSchemaVer(nil, 0), 0) d := NewDDL( - goctx.Background(), + context.Background(), WithEtcdClient(cli), WithStore(store), WithLease(testLease), @@ -136,7 +135,7 @@ func TestCluster(t *testing.T) { ic2 := infoschema.NewCache(2) ic2.Insert(infoschema.MockInfoSchemaWithSchemaVer(nil, 0), 0) d1 := NewDDL( - goctx.Background(), + context.Background(), WithEtcdClient(cli1), WithStore(store), WithLease(testLease), @@ -163,7 +162,7 @@ func TestCluster(t *testing.T) { ic3 := infoschema.NewCache(2) ic3.Insert(infoschema.MockInfoSchemaWithSchemaVer(nil, 0), 0) d3 := NewDDL( - goctx.Background(), + context.Background(), WithEtcdClient(cli3), WithStore(store), WithLease(testLease), @@ -186,7 +185,7 @@ func TestCluster(t *testing.T) { election := concurrency.NewElection(session, DDLOwnerKey) logPrefix := fmt.Sprintf("[ddl] %s ownerManager %s", DDLOwnerKey, "useless id") logCtx := logutil.WithKeyValue(context.Background(), "owner info", logPrefix) - _, err = owner.GetOwnerInfo(goctx.Background(), logCtx, election, "useless id") + _, err = owner.GetOwnerInfo(context.Background(), logCtx, election, "useless id") require.Truef(t, terror.ErrorEqual(err, concurrency.ErrElectionNoLeader), "get owner info result don't match, err %v", err) } @@ -213,10 +212,10 @@ func deleteLeader(cli *clientv3.Client, prefixKey string) error { _ = session.Close() }() election := concurrency.NewElection(session, prefixKey) - resp, err := election.Leader(goctx.Background()) + resp, err := election.Leader(context.Background()) if err != nil { return errors.Trace(err) } - _, err = cli.Delete(goctx.Background(), string(resp.Kvs[0].Key)) + _, err = cli.Delete(context.Background(), string(resp.Kvs[0].Key)) return errors.Trace(err) } diff --git a/parser/ast/ddl_test.go b/parser/ast/ddl_test.go index beb3a27b97370..25af0b1fe0485 100644 --- a/parser/ast/ddl_test.go +++ b/parser/ast/ddl_test.go @@ -16,10 +16,9 @@ package ast_test import ( "testing" - "github.com/stretchr/testify/require" - . "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/format" + "github.com/stretchr/testify/require" ) func TestDDLVisitorCover(t *testing.T) { diff --git a/parser/charset/encoding_latin1.go b/parser/charset/encoding_latin1.go index db7b66ed101af..38f9bb601ac4e 100644 --- a/parser/charset/encoding_latin1.go +++ b/parser/charset/encoding_latin1.go @@ -15,6 +15,7 @@ package charset import ( "bytes" + "golang.org/x/text/encoding" ) diff --git a/parser/hintparser_test.go b/parser/hintparser_test.go index 5c252b2d4af78..2c9156f579128 100644 --- a/parser/hintparser_test.go +++ b/parser/hintparser_test.go @@ -16,12 +16,11 @@ package parser_test import ( "testing" - "github.com/stretchr/testify/require" - "github.com/pingcap/tidb/parser" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/model" "github.com/pingcap/tidb/parser/mysql" + "github.com/stretchr/testify/require" ) func TestParseHint(t *testing.T) { diff --git a/parser/types/field_type_test.go b/parser/types/field_type_test.go index e258e75787313..6310dbb102bc9 100644 --- a/parser/types/field_type_test.go +++ b/parser/types/field_type_test.go @@ -21,11 +21,10 @@ import ( "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/charset" "github.com/pingcap/tidb/parser/mysql" - . "github.com/pingcap/tidb/parser/types" - "github.com/stretchr/testify/require" - // import parser_driver _ "github.com/pingcap/tidb/parser/test_driver" + . "github.com/pingcap/tidb/parser/types" + "github.com/stretchr/testify/require" ) func TestFieldType(t *testing.T) { diff --git a/planner/core/fragment_test.go b/planner/core/fragment_test.go index fa8ec9e99763c..ee01ddf8133c4 100644 --- a/planner/core/fragment_test.go +++ b/planner/core/fragment_test.go @@ -15,10 +15,10 @@ package core import ( + "testing" + "github.com/pingcap/tipb/go-tipb" "github.com/stretchr/testify/require" - - "testing" ) func TestFragmentInitSingleton(t *testing.T) { diff --git a/planner/core/planbuilder_test.go b/planner/core/planbuilder_test.go index e793d51a68f23..13494433f0fbe 100644 --- a/planner/core/planbuilder_test.go +++ b/planner/core/planbuilder_test.go @@ -21,7 +21,6 @@ import ( "strings" "testing" "unsafe" - _ "unsafe" // required by go:linkname "github.com/pingcap/errors" "github.com/pingcap/tidb/expression" diff --git a/server/server.go b/server/server.go index 63406905b5a3b..dde54399a7cd9 100644 --- a/server/server.go +++ b/server/server.go @@ -36,8 +36,7 @@ import ( "io" "math/rand" "net" - "net/http" - + "net/http" //nolint:goimports // For pprof _ "net/http/pprof" // #nosec G108 "os" diff --git a/session/session.go b/session/session.go index a00b269d2ee06..41b26e1b8ec7b 100644 --- a/session/session.go +++ b/session/session.go @@ -41,29 +41,6 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/kvrpcpb" - "github.com/pingcap/tidb/parser" - "github.com/pingcap/tidb/parser/ast" - "github.com/pingcap/tidb/parser/auth" - "github.com/pingcap/tidb/parser/charset" - "github.com/pingcap/tidb/parser/model" - "github.com/pingcap/tidb/parser/mysql" - "github.com/pingcap/tidb/parser/terror" - "github.com/pingcap/tidb/sessionctx/sessionstates" - "github.com/pingcap/tidb/sessiontxn" - "github.com/pingcap/tidb/sessiontxn/staleread" - "github.com/pingcap/tidb/store/driver/txn" - "github.com/pingcap/tidb/store/helper" - "github.com/pingcap/tidb/table" - "github.com/pingcap/tidb/table/temptable" - "github.com/pingcap/tidb/util/logutil/consistency" - "github.com/pingcap/tidb/util/sem" - "github.com/pingcap/tidb/util/topsql" - topsqlstate "github.com/pingcap/tidb/util/topsql/state" - "github.com/pingcap/tidb/util/topsql/stmtstats" - "github.com/pingcap/tipb/go-binlog" - tikverr "github.com/tikv/client-go/v2/error" - "go.uber.org/zap" - "github.com/pingcap/tidb/bindinfo" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/ddl/placement" @@ -75,6 +52,13 @@ import ( "github.com/pingcap/tidb/meta" "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/owner" + "github.com/pingcap/tidb/parser" + "github.com/pingcap/tidb/parser/ast" + "github.com/pingcap/tidb/parser/auth" + "github.com/pingcap/tidb/parser/charset" + "github.com/pingcap/tidb/parser/model" + "github.com/pingcap/tidb/parser/mysql" + "github.com/pingcap/tidb/parser/terror" "github.com/pingcap/tidb/planner" plannercore "github.com/pingcap/tidb/planner/core" "github.com/pingcap/tidb/plugin" @@ -83,11 +67,18 @@ import ( "github.com/pingcap/tidb/session/txninfo" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/sessionctx/binloginfo" + "github.com/pingcap/tidb/sessionctx/sessionstates" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/sessionctx/variable" + "github.com/pingcap/tidb/sessiontxn" + "github.com/pingcap/tidb/sessiontxn/staleread" "github.com/pingcap/tidb/statistics" "github.com/pingcap/tidb/statistics/handle" storeerr "github.com/pingcap/tidb/store/driver/error" + "github.com/pingcap/tidb/store/driver/txn" + "github.com/pingcap/tidb/store/helper" + "github.com/pingcap/tidb/table" + "github.com/pingcap/tidb/table/temptable" "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/telemetry" "github.com/pingcap/tidb/types" @@ -98,14 +89,22 @@ import ( "github.com/pingcap/tidb/util/execdetails" "github.com/pingcap/tidb/util/kvcache" "github.com/pingcap/tidb/util/logutil" + "github.com/pingcap/tidb/util/logutil/consistency" + "github.com/pingcap/tidb/util/sem" "github.com/pingcap/tidb/util/sli" "github.com/pingcap/tidb/util/sqlexec" "github.com/pingcap/tidb/util/tableutil" "github.com/pingcap/tidb/util/timeutil" + "github.com/pingcap/tidb/util/topsql" + topsqlstate "github.com/pingcap/tidb/util/topsql/state" + "github.com/pingcap/tidb/util/topsql/stmtstats" + "github.com/pingcap/tipb/go-binlog" + tikverr "github.com/tikv/client-go/v2/error" tikvstore "github.com/tikv/client-go/v2/kv" "github.com/tikv/client-go/v2/oracle" "github.com/tikv/client-go/v2/tikv" tikvutil "github.com/tikv/client-go/v2/util" + "go.uber.org/zap" ) var ( diff --git a/sessiontxn/isolation/optimistic_test.go b/sessiontxn/isolation/optimistic_test.go index 134833c8823e8..d6b4d9b3b7d26 100644 --- a/sessiontxn/isolation/optimistic_test.go +++ b/sessiontxn/isolation/optimistic_test.go @@ -22,9 +22,8 @@ import ( "testing" "time" - "github.com/pingcap/tidb/config" - "github.com/pingcap/kvproto/pkg/kvrpcpb" + "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/parser" diff --git a/store/mockstore/unistore/tikv/deadlock.go b/store/mockstore/unistore/tikv/deadlock.go index 90f0c5b226a56..7eeb1fb2c5b64 100644 --- a/store/mockstore/unistore/tikv/deadlock.go +++ b/store/mockstore/unistore/tikv/deadlock.go @@ -20,14 +20,13 @@ import ( "sync/atomic" "time" - "go.uber.org/zap" - "google.golang.org/grpc" - deadlockPb "github.com/pingcap/kvproto/pkg/deadlock" "github.com/pingcap/log" "github.com/pingcap/tidb/store/mockstore/unistore/pd" "github.com/pingcap/tidb/store/mockstore/unistore/tikv/kverrors" "github.com/pingcap/tidb/store/mockstore/unistore/util/lockwaiter" + "go.uber.org/zap" + "google.golang.org/grpc" ) // Follower will send detection rpc to Leader diff --git a/store/mockstore/unistore/tikv/mvcc/mvcc.go b/store/mockstore/unistore/tikv/mvcc/mvcc.go index a8ae16a9321d6..b7185766bfeeb 100644 --- a/store/mockstore/unistore/tikv/mvcc/mvcc.go +++ b/store/mockstore/unistore/tikv/mvcc/mvcc.go @@ -19,7 +19,6 @@ import ( "unsafe" "github.com/pingcap/kvproto/pkg/kvrpcpb" - "github.com/pingcap/tidb/util/codec" ) diff --git a/tidb-binlog/pump_client/client_test.go b/tidb-binlog/pump_client/client_test.go index 866c91693ff27..ac287773072ed 100644 --- a/tidb-binlog/pump_client/client_test.go +++ b/tidb-binlog/pump_client/client_test.go @@ -24,8 +24,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/tidb/tidb-binlog/node" - binlog "github.com/pingcap/tipb/go-binlog" - pb "github.com/pingcap/tipb/go-binlog" + "github.com/pingcap/tipb/go-binlog" "github.com/stretchr/testify/require" "google.golang.org/grpc" ) @@ -36,7 +35,7 @@ var ( ) type testCase struct { - binlogs []*pb.Binlog + binlogs []*binlog.Binlog choosePumps []*PumpStatus setAvliable []bool setNodeID []string @@ -61,7 +60,7 @@ func testSelector(t *testing.T, strategy string) { pump.NodeID = fmt.Sprintf("pump%d", i) pump.State = node.Offline // set pump client to avoid create grpc client. - pump.Client = pb.NewPumpClient(nil) + pump.Client = binlog.NewPumpClient(nil) } for _, pump := range pumps { @@ -71,26 +70,26 @@ func testSelector(t *testing.T, strategy string) { tCase := &testCase{} - tCase.binlogs = []*pb.Binlog{ + tCase.binlogs = []*binlog.Binlog{ { - Tp: pb.BinlogType_Prewrite, + Tp: binlog.BinlogType_Prewrite, StartTs: 1, }, { - Tp: pb.BinlogType_Commit, + Tp: binlog.BinlogType_Commit, StartTs: 1, CommitTs: 2, }, { - Tp: pb.BinlogType_Prewrite, + Tp: binlog.BinlogType_Prewrite, StartTs: 3, }, { - Tp: pb.BinlogType_Commit, + Tp: binlog.BinlogType_Commit, StartTs: 3, CommitTs: 4, }, { - Tp: pb.BinlogType_Prewrite, + Tp: binlog.BinlogType_Prewrite, StartTs: 5, }, { - Tp: pb.BinlogType_Commit, + Tp: binlog.BinlogType_Commit, StartTs: 5, CommitTs: 6, }, @@ -111,12 +110,12 @@ func testSelector(t *testing.T, strategy string) { } for j := 0; j < 10; j++ { - prewriteBinlog := &pb.Binlog{ - Tp: pb.BinlogType_Prewrite, + prewriteBinlog := &binlog.Binlog{ + Tp: binlog.BinlogType_Prewrite, StartTs: int64(j), } - commitBinlog := &pb.Binlog{ - Tp: pb.BinlogType_Commit, + commitBinlog := &binlog.Binlog{ + Tp: binlog.BinlogType_Commit, StartTs: int64(j), } @@ -180,20 +179,20 @@ func TestWriteBinlog(t *testing.T) { clientCon, err := grpc.Dial(cfg.addr, opt, grpc.WithInsecure()) require.NoError(t, err) require.NotNil(t, clientCon) - pumpClient := mockPumpsClient(pb.NewPumpClient(clientCon), true) + pumpClient := mockPumpsClient(binlog.NewPumpClient(clientCon), true) // test binlog size bigger than grpc's MaxRecvMsgSize - blog := &pb.Binlog{ - Tp: pb.BinlogType_Prewrite, + blog := &binlog.Binlog{ + Tp: binlog.BinlogType_Prewrite, PrewriteValue: make([]byte, testMaxRecvMsgSize+1), } err = pumpClient.WriteBinlog(blog) require.Error(t, err) for i := 0; i < 10; i++ { - // test binlog size small than grpc's MaxRecvMsgSize - blog = &pb.Binlog{ - Tp: pb.BinlogType_Prewrite, + // test binlog size smaller than grpc's MaxRecvMsgSize + blog = &binlog.Binlog{ + Tp: binlog.BinlogType_Prewrite, PrewriteValue: make([]byte, 1), } err = pumpClient.WriteBinlog(blog) @@ -204,13 +203,13 @@ func TestWriteBinlog(t *testing.T) { require.Len(t, pumpClient.Pumps.UnAvaliablePumps, 1) // test write commit binlog, will not return error although write binlog failed. - preWriteBinlog := &pb.Binlog{ - Tp: pb.BinlogType_Prewrite, + preWriteBinlog := &binlog.Binlog{ + Tp: binlog.BinlogType_Prewrite, StartTs: 123, PrewriteValue: make([]byte, 1), } - commitBinlog := &pb.Binlog{ - Tp: pb.BinlogType_Commit, + commitBinlog := &binlog.Binlog{ + Tp: binlog.BinlogType_Commit, StartTs: 123, CommitTs: 123, PrewriteValue: make([]byte, 1), @@ -284,14 +283,14 @@ func createMockPumpServer(addr string, mode string, withError bool) (*mockPumpSe server: serv, withError: withError, } - pb.RegisterPumpServer(serv, pump) + binlog.RegisterPumpServer(serv, pump) go serv.Serve(l) return pump, nil } // mockPumpsClient creates a PumpsClient, used for test. -func mockPumpsClient(client pb.PumpClient, withBadPump bool) *PumpsClient { +func mockPumpsClient(client binlog.PumpClient, withBadPump bool) *PumpsClient { // add a available pump nodeID1 := "pump-1" pump1 := &PumpStatus{ diff --git a/util/generatedexpr/gen_expr_test.go b/util/generatedexpr/gen_expr_test.go index 484453466e7eb..6b1d39f2c2490 100644 --- a/util/generatedexpr/gen_expr_test.go +++ b/util/generatedexpr/gen_expr_test.go @@ -18,9 +18,8 @@ import ( "testing" "github.com/pingcap/tidb/parser/ast" - "github.com/stretchr/testify/require" - _ "github.com/pingcap/tidb/types/parser_driver" + "github.com/stretchr/testify/require" ) func TestParseExpression(t *testing.T) { diff --git a/util/logutil/hex_test.go b/util/logutil/hex_test.go index c9ce8713fe7ea..9351b0216cf52 100644 --- a/util/logutil/hex_test.go +++ b/util/logutil/hex_test.go @@ -21,10 +21,9 @@ import ( "testing" "github.com/pingcap/kvproto/pkg/metapb" - "github.com/stretchr/testify/require" - "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/util/logutil" + "github.com/stretchr/testify/require" ) func TestHex(t *testing.T) { diff --git a/util/mock/iter_test.go b/util/mock/iter_test.go index 9e142973185ea..e99e9d17745cb 100644 --- a/util/mock/iter_test.go +++ b/util/mock/iter_test.go @@ -17,7 +17,6 @@ import ( "testing" "github.com/pingcap/tidb/kv" - "github.com/stretchr/testify/assert" ) diff --git a/util/sem/sem_test.go b/util/sem/sem_test.go index f7f8d20f6ee89..cb0c47ad9225d 100644 --- a/util/sem/sem_test.go +++ b/util/sem/sem_test.go @@ -19,7 +19,6 @@ import ( "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/sessionctx/variable" - "github.com/stretchr/testify/assert" )