From a4105e7059665dd1ae5878ab5403a8bccceb33be Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Mon, 8 Aug 2022 10:46:46 +0800 Subject: [PATCH] *: enable deprecated linter (#36946) ref pingcap/tidb#35345 --- build/BUILD.bazel | 1 + build/nogo_config.json | 10 ++++++++++ ddl/column_modify_test.go | 6 ++---- ddl/column_type_change_test.go | 8 ++++---- ddl/ddl_api.go | 7 +++++-- ddl/serial_test.go | 7 ++++--- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/build/BUILD.bazel b/build/BUILD.bazel index 0532961efab6b..eb97275d1fd58 100644 --- a/build/BUILD.bazel +++ b/build/BUILD.bazel @@ -54,6 +54,7 @@ STATICHECK_ANALYZERS = [ "S1038", "S1039", "S1040", + "SA1019", "SA2000", "SA2001", "SA2003", diff --git a/build/nogo_config.json b/build/nogo_config.json index 8a2674d69691f..077611331f298 100644 --- a/build/nogo_config.json +++ b/build/nogo_config.json @@ -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", diff --git a/ddl/column_modify_test.go b/ddl/column_modify_test.go index 2ccdf96a24916..926ed6b13cdb3 100644 --- a/ddl/column_modify_test.go +++ b/ddl/column_modify_test.go @@ -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" @@ -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 { @@ -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 { diff --git a/ddl/column_type_change_test.go b/ddl/column_type_change_test.go index 72d3ffd6a06af..2fed091c5be3f 100644 --- a/ddl/column_type_change_test.go +++ b/ddl/column_type_change_test.go @@ -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) { diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index fecd6946a8ecf..1ce0bee545791 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -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" @@ -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)) } @@ -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)) diff --git a/ddl/serial_test.go b/ddl/serial_test.go index 322a30fdbb9a1..98b18417d90e8 100644 --- a/ddl/serial_test.go +++ b/ddl/serial_test.go @@ -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" @@ -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 { @@ -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() @@ -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()