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

*: enable deprecated linter #36946

Merged
merged 9 commits into from
Aug 8, 2022
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
1 change: 1 addition & 0 deletions build/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ STATICHECK_ANALYZERS = [
"S1038",
"S1039",
"S1040",
"SA1019",
"SA2000",
"SA2001",
"SA2003",
Expand Down
10 changes: 10 additions & 0 deletions build/nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,16 @@
"parser/parser.go": "ignore generated code"
}
},
"SA1019": {
"exclude_files": {
"/build/": "no need to linter code",
"/external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
},
"only_files": {
"ddl/": "enable to ddl"
}
},
"SA2000": {
"exclude_files": {
"/external/": "no need to vet third party code",
Expand Down
6 changes: 2 additions & 4 deletions ddl/column_modify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ import (
testddlutil "github.com/pingcap/tidb/ddl/testutil"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessiontxn"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/table"
Expand Down Expand Up @@ -447,7 +445,7 @@ func TestVirtualColumnDDL(t *testing.T) {
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`create global temporary table test_gv_ddl(a int, b int as (a+8) virtual, c int as (b + 2) stored) on commit delete rows;`)
is := tk.Session().(sessionctx.Context).GetInfoSchema().(infoschema.InfoSchema)
is := sessiontxn.GetTxnManager(tk.Session()).GetTxnInfoSchema()
tbl, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("test_gv_ddl"))
require.NoError(t, err)
testCases := []struct {
Expand All @@ -471,7 +469,7 @@ func TestVirtualColumnDDL(t *testing.T) {

// for local temporary table
tk.MustExec(`create temporary table test_local_gv_ddl(a int, b int as (a+8) virtual, c int as (b + 2) stored);`)
is = tk.Session().(sessionctx.Context).GetInfoSchema().(infoschema.InfoSchema)
is = sessiontxn.GetTxnManager(tk.Session()).GetTxnInfoSchema()
tbl, err = is.TableByName(model.NewCIStr("test"), model.NewCIStr("test_local_gv_ddl"))
require.NoError(t, err)
for i, column := range tbl.Meta().Columns {
Expand Down
8 changes: 4 additions & 4 deletions ddl/column_type_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ var mockTerrorMap = make(map[string]*terror.Error)

func init() {
// Since terror new action will cause data race with other test suite (getTerrorCode) in parallel, we init it all here.
mockTerrorMap[model.StateNone.String()] = dbterror.ClassDDL.New(1, "MockRollingBackInCallBack-"+model.StateNone.String())
mockTerrorMap[model.StateDeleteOnly.String()] = dbterror.ClassDDL.New(1, "MockRollingBackInCallBack-"+model.StateDeleteOnly.String())
mockTerrorMap[model.StateWriteOnly.String()] = dbterror.ClassDDL.New(1, "MockRollingBackInCallBack-"+model.StateWriteOnly.String())
mockTerrorMap[model.StateWriteReorganization.String()] = dbterror.ClassDDL.New(1, "MockRollingBackInCallBack-"+model.StateWriteReorganization.String())
mockTerrorMap[model.StateNone.String()] = dbterror.ClassDDL.NewStdErr(1, mysql.Message("MockRollingBackInCallBack-"+model.StateNone.String(), nil))
mockTerrorMap[model.StateDeleteOnly.String()] = dbterror.ClassDDL.NewStdErr(1, mysql.Message("MockRollingBackInCallBack-"+model.StateDeleteOnly.String(), nil))
mockTerrorMap[model.StateWriteOnly.String()] = dbterror.ClassDDL.NewStdErr(1, mysql.Message("MockRollingBackInCallBack-"+model.StateWriteOnly.String(), nil))
mockTerrorMap[model.StateWriteReorganization.String()] = dbterror.ClassDDL.NewStdErr(1, mysql.Message("MockRollingBackInCallBack-"+model.StateWriteReorganization.String(), nil))
}

func TestColumnTypeChangeFromIntegerToOthers(t *testing.T) {
Expand Down
7 changes: 5 additions & 2 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
field_types "github.com/pingcap/tidb/parser/types"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/sessiontxn"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/tablecodec"
Expand Down Expand Up @@ -493,7 +494,7 @@ func checkAndNormalizePlacementPolicy(ctx sessionctx.Context, placementPolicyRef
return nil, nil
}

policy, ok := ctx.GetInfoSchema().(infoschema.InfoSchema).PolicyByName(placementPolicyRef.Name)
policy, ok := sessiontxn.GetTxnManager(ctx).GetTxnInfoSchema().PolicyByName(placementPolicyRef.Name)
if !ok {
return nil, errors.Trace(infoschema.ErrPlacementPolicyNotExists.GenWithStackByArgs(placementPolicyRef.Name))
}
Expand Down Expand Up @@ -761,7 +762,9 @@ func ResolveCharsetCollation(charsetOpts ...ast.CharsetOpt) (string, string, err
}

// OverwriteCollationWithBinaryFlag is used to handle the case like
// CREATE TABLE t (a VARCHAR(255) BINARY) CHARSET utf8 COLLATE utf8_general_ci;
//
// CREATE TABLE t (a VARCHAR(255) BINARY) CHARSET utf8 COLLATE utf8_general_ci;
//
// The 'BINARY' sets the column collation to *_bin according to the table charset.
func OverwriteCollationWithBinaryFlag(colDef *ast.ColumnDef, chs, coll string) (newChs string, newColl string) {
ignoreBinFlag := colDef.Tp.GetCharset() != "" && (colDef.Tp.GetCollate() != "" || containsColumnOption(colDef, ast.ColumnOptionCollate))
Expand Down
7 changes: 4 additions & 3 deletions ddl/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/sessiontxn"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/testkit"
Expand Down Expand Up @@ -271,7 +272,7 @@ func TestCreateTableWithLikeAtTemporaryMode(t *testing.T) {
tk.MustExec(`create table test_gv_ddl(a int, b int as (a+8) virtual, c int as (b + 2) stored)`)
tk.MustExec(`create global temporary table test_gv_ddl_temp like test_gv_ddl on commit delete rows;`)
defer tk.MustExec("drop table if exists test_gv_ddl_temp, test_gv_ddl")
is := tk.Session().GetInfoSchema().(infoschema.InfoSchema)
is := sessiontxn.GetTxnManager(tk.Session()).GetTxnInfoSchema()
table, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("test_gv_ddl"))
require.NoError(t, err)
testCases := []struct {
Expand Down Expand Up @@ -300,7 +301,7 @@ func TestCreateTableWithLikeAtTemporaryMode(t *testing.T) {
tk.MustExec("create table test_foreign_key (c int,d int,foreign key (d) references t1 (b))")
defer tk.MustExec("drop table if exists test_foreign_key, t1")
tk.MustExec("create global temporary table test_foreign_key_temp like test_foreign_key on commit delete rows")
is = tk.Session().GetInfoSchema().(infoschema.InfoSchema)
is = sessiontxn.GetTxnManager(tk.Session()).GetTxnInfoSchema()
table, err = is.TableByName(model.NewCIStr("test"), model.NewCIStr("test_foreign_key_temp"))
require.NoError(t, err)
tableInfo := table.Meta()
Expand Down Expand Up @@ -384,7 +385,7 @@ func TestCreateTableWithLikeAtTemporaryMode(t *testing.T) {
tk.MustExec("create table foreign_key_table1 (a int, b int)")
tk.MustExec("create table foreign_key_table2 (c int,d int,foreign key (d) references foreign_key_table1 (b))")
tk.MustExec("create temporary table foreign_key_tmp like foreign_key_table2")
is = tk.Session().GetInfoSchema().(infoschema.InfoSchema)
is = sessiontxn.GetTxnManager(tk.Session()).GetTxnInfoSchema()
table, err = is.TableByName(model.NewCIStr("test"), model.NewCIStr("foreign_key_tmp"))
require.NoError(t, err)
tableInfo = table.Meta()
Expand Down