From 560b0da8919063b02273d09876a11406eeb251bb Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Sat, 18 Sep 2021 19:00:43 +0800 Subject: [PATCH] ddl, executor: fix test race in terror (#25405) (#28198) --- ddl/ddl_api.go | 8 ++------ ddl/error.go | 4 +++- executor/errors.go | 3 +++ executor/insert_common.go | 7 +------ 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 9c4eac7a422f3..88395d67fe521 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -39,7 +39,6 @@ import ( field_types "github.com/pingcap/parser/types" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/ddl/placement" - "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" "github.com/pingcap/tidb/kv" @@ -55,7 +54,6 @@ import ( "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/collate" - "github.com/pingcap/tidb/util/dbterror" "github.com/pingcap/tidb/util/domainutil" "github.com/pingcap/tidb/util/logutil" "github.com/pingcap/tidb/util/mock" @@ -1410,8 +1408,7 @@ func buildTableInfo( // Check clustered on non-primary key. if constr.Option != nil && constr.Option.PrimaryKeyTp != model.PrimaryKeyTypeDefault && constr.Tp != ast.ConstraintPrimaryKey { - msg := mysql.Message("CLUSTERED/NONCLUSTERED keyword is only supported for primary key", nil) - return nil, dbterror.ClassDDL.NewStdErr(errno.ErrUnsupportedDDLOperation, msg) + return nil, errUnsupportedClusteredSecondaryKey } if constr.Tp == ast.ConstraintForeignKey { for _, fk := range tbInfo.ForeignKeys { @@ -1440,8 +1437,7 @@ func buildTableInfo( } else { hasBinlog := ctx.GetSessionVars().BinlogClient != nil if hasBinlog { - msg := mysql.Message("Cannot create clustered index table when the binlog is ON", nil) - return nil, dbterror.ClassDDL.NewStdErr(errno.ErrUnsupportedDDLOperation, msg) + return nil, errUnsupportedClusteredIndexWhenBinlogIsOn } tbInfo.IsCommonHandle = true tbInfo.CommonHandleVersion = 1 diff --git a/ddl/error.go b/ddl/error.go index 852d2218c6275..f36a550d9f15a 100644 --- a/ddl/error.go +++ b/ddl/error.go @@ -273,5 +273,7 @@ var ( // ErrUnknownEngine is returned when the table engine is unknown. ErrUnknownEngine = dbterror.ClassDDL.NewStd(mysql.ErrUnknownStorageEngine) - errExchangePartitionDisabled = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("Exchange Partition is disabled, please set 'tidb_enable_exchange_partition' if you need to need to enable it", nil)) + errExchangePartitionDisabled = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("Exchange Partition is disabled, please set 'tidb_enable_exchange_partition' if you need to need to enable it", nil)) + errUnsupportedClusteredSecondaryKey = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("CLUSTERED/NONCLUSTERED keyword is only supported for primary key", nil)) + errUnsupportedClusteredIndexWhenBinlogIsOn = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message("Cannot create clustered index table when the binlog is ON", nil)) ) diff --git a/executor/errors.go b/executor/errors.go index afc64276900a7..20e251d3bcb45 100644 --- a/executor/errors.go +++ b/executor/errors.go @@ -14,6 +14,7 @@ package executor import ( + parser_mysql "github.com/pingcap/parser/mysql" mysql "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/util/dbterror" ) @@ -49,4 +50,6 @@ var ( ErrBRIERestoreFailed = dbterror.ClassExecutor.NewStd(mysql.ErrBRIERestoreFailed) ErrBRIEImportFailed = dbterror.ClassExecutor.NewStd(mysql.ErrBRIEImportFailed) ErrBRIEExportFailed = dbterror.ClassExecutor.NewStd(mysql.ErrBRIEExportFailed) + + errTruncateWrongInsertValue = dbterror.ClassTable.NewStdErr(mysql.ErrTruncatedWrongValue, parser_mysql.Message("Incorrect %-.32s value: '%-.128s' for column '%.192s' at row %d", nil)) ) diff --git a/executor/insert_common.go b/executor/insert_common.go index f7402c2c816e8..0b0975fd75048 100644 --- a/executor/insert_common.go +++ b/executor/insert_common.go @@ -28,7 +28,6 @@ import ( "github.com/pingcap/parser/mysql" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/ddl" - "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta/autoid" @@ -38,7 +37,6 @@ import ( "github.com/pingcap/tidb/table/tables" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" - "github.com/pingcap/tidb/util/dbterror" "github.com/pingcap/tidb/util/execdetails" "github.com/pingcap/tidb/util/logutil" "github.com/pingcap/tidb/util/memory" @@ -308,10 +306,7 @@ func (e *InsertValues) handleErr(col *table.Column, val *types.Datum, rowIdx int if err1 != nil { logutil.BgLogger().Debug("time truncated error", zap.Error(err1)) } - err = dbterror.ClassTable.NewStdErr( - errno.ErrTruncatedWrongValue, - mysql.Message("Incorrect %-.32s value: '%-.128s' for column '%.192s' at row %d", nil), - ).GenWithStackByArgs(types.TypeStr(colTp), valStr, colName, rowIdx+1) + err = errTruncateWrongInsertValue.GenWithStackByArgs(types.TypeStr(colTp), valStr, colName, rowIdx+1) } else if types.ErrTruncatedWrongVal.Equal(err) || types.ErrWrongValue.Equal(err) { valStr, err1 := val.ToString() if err1 != nil {