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

ddl: fix error code and error name #13329

Merged
merged 9 commits into from Nov 12, 2019
4 changes: 2 additions & 2 deletions ddl/column.go
Expand Up @@ -221,7 +221,7 @@ func onAddColumn(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, err error)
job.FinishTableJob(model.JobStateDone, model.StatePublic, ver, tblInfo)
asyncNotifyEvent(d, &util.Event{Tp: model.ActionAddColumn, TableInfo: tblInfo, ColumnInfo: columnInfo})
default:
err = ErrInvalidColumnState.GenWithStack("invalid column state %v", columnInfo.State)
err = ErrInvalidDDLState.GenWithStackByArgs("column", columnInfo.State)
}

return ver, errors.Trace(err)
Expand Down Expand Up @@ -284,7 +284,7 @@ func onDropColumn(t *meta.Meta, job *model.Job) (ver int64, _ error) {
job.FinishTableJob(model.JobStateDone, model.StateNone, ver, tblInfo)
}
default:
err = ErrInvalidTableState.GenWithStack("invalid table state %v", tblInfo.State)
err = errInvalidDDLJob.GenWithStackByArgs("table", tblInfo.State)
}
return ver, errors.Trace(err)
}
Expand Down
2 changes: 1 addition & 1 deletion ddl/column_test.go
Expand Up @@ -950,7 +950,7 @@ func (s *testColumnSuite) TestModifyColumn(c *C) {
{"varchar(10)", "varchar(8)", errUnsupportedModifyColumn.GenWithStackByArgs("length 8 is less than origin 10")},
{"varchar(10)", "varchar(11)", nil},
{"varchar(10) character set utf8 collate utf8_bin", "varchar(10) character set utf8", nil},
{"decimal(2,1)", "decimal(3,2)", errUnsupportedModifyColumn.GenWithStack("unsupported modify decimal column precision")},
{"decimal(2,1)", "decimal(3,2)", errUnsupportedModifyColumn.GenWithStackByArgs("can't change decimal column precision")},
{"decimal(2,1)", "decimal(2,1)", nil},
}
for _, tt := range tests {
Expand Down
4 changes: 2 additions & 2 deletions ddl/db_change_test.go
Expand Up @@ -450,10 +450,10 @@ func (s *testStateChangeSuite) TestAppendEnum(c *C) {
c.Assert(err.Error(), Equals, "[table:1366]Incorrect enum value: 'A' for column 'c2' at row 1")
failAlterTableSQL1 := "alter table t change c2 c2 enum('N') DEFAULT 'N'"
_, err = s.se.Execute(context.Background(), failAlterTableSQL1)
c.Assert(err.Error(), Equals, "[ddl:203]unsupported modify column the number of enum column's elements is less than the original: 2")
c.Assert(err.Error(), Equals, "[ddl:8200]Unsupported modify column: the number of enum column's elements is less than the original: 2")
failAlterTableSQL2 := "alter table t change c2 c2 int default 0"
_, err = s.se.Execute(context.Background(), failAlterTableSQL2)
c.Assert(err.Error(), Equals, "[ddl:210]unsupported modify charset from utf8 to binary")
c.Assert(err.Error(), Equals, "[ddl:8200]Unsupported modify charset from utf8 to binary")
alterTableSQL := "alter table t change c2 c2 enum('N','Y','A') DEFAULT 'A'"
_, err = s.se.Execute(context.Background(), alterTableSQL)
c.Assert(err, IsNil)
Expand Down
14 changes: 7 additions & 7 deletions ddl/db_integration_test.go
Expand Up @@ -463,7 +463,7 @@ func (s *testIntegrationSuite5) TestMySQLErrorCode(c *C) {
sql = "alter table test_error_code_succ drop index idx_not_exist"
tk.MustGetErrCode(sql, tmysql.ErrCantDropFieldOrKey)
sql = "alter table test_error_code_succ drop column c3"
tk.MustGetErrCode(sql, int(tmysql.ErrUnknown))
tk.MustGetErrCode(sql, int(tmysql.ErrUnsupportedDDLOperation))
// modify column
sql = "alter table test_error_code_succ modify testx.test_error_code_succ.c1 bigint"
tk.MustGetErrCode(sql, tmysql.ErrWrongDBName)
Expand Down Expand Up @@ -635,13 +635,13 @@ func (s *testIntegrationSuite3) TestChangingCharsetToUtf8(c *C) {
rs.Close()
}
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[ddl:210]unsupported modify charset from latin1 to utf8")
c.Assert(err.Error(), Equals, "[ddl:8200]Unsupported modify charset from latin1 to utf8")
rs, err = tk.Exec("alter table t modify column a varchar(20) charset utf8mb4")
if rs != nil {
rs.Close()
}
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[ddl:210]unsupported modify charset from latin1 to utf8mb4")
c.Assert(err.Error(), Equals, "[ddl:8200]Unsupported modify charset from latin1 to utf8mb4")

rs, err = tk.Exec("alter table t modify column a varchar(20) charset utf8mb4 collate utf8bin")
if rs != nil {
Expand Down Expand Up @@ -675,7 +675,7 @@ func (s *testIntegrationSuite4) TestChangingTableCharset(c *C) {
if rs != nil {
rs.Close()
}
c.Assert(err.Error(), Equals, "[ddl:210]unsupported modify charset from latin1 to utf8")
c.Assert(err.Error(), Equals, "[ddl:8200]Unsupported modify charset from latin1 to utf8")

rs, err = tk.Exec("alter table t charset utf8 collate latin1_bin")
if rs != nil {
Expand All @@ -686,7 +686,7 @@ func (s *testIntegrationSuite4) TestChangingTableCharset(c *C) {
if rs != nil {
rs.Close()
}
c.Assert(err.Error(), Equals, "[ddl:210]unsupported modify charset from latin1 to utf8mb4")
c.Assert(err.Error(), Equals, "[ddl:8200]Unsupported modify charset from latin1 to utf8mb4")

rs, err = tk.Exec("alter table t charset utf8mb4 collate utf8mb4_bin")
c.Assert(err, NotNil)
Expand Down Expand Up @@ -736,7 +736,7 @@ func (s *testIntegrationSuite4) TestChangingTableCharset(c *C) {
tk.MustExec("create table t(a varchar(10) character set ascii) charset utf8mb4")
_, err = tk.Exec("alter table t convert to charset utf8mb4;")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[ddl:210]unsupported modify charset from ascii to utf8mb4")
c.Assert(err.Error(), Equals, "[ddl:8200]Unsupported modify charset from ascii to utf8mb4")

tk.MustExec("drop table t;")
tk.MustExec("create table t(a varchar(10) character set utf8) charset utf8")
Expand Down Expand Up @@ -813,7 +813,7 @@ func (s *testIntegrationSuite5) TestModifyingColumnOption(c *C) {
tk.MustExec("create database if not exists test")
tk.MustExec("use test")

errMsg := "[ddl:203]" // unsupported modify column with references
errMsg := "[ddl:8200]" // unsupported modify column with references
assertErrCode := func(sql string, errCodeStr string) {
_, err := tk.Exec(sql)
c.Assert(err, NotNil)
Expand Down
4 changes: 2 additions & 2 deletions ddl/db_partition_test.go
Expand Up @@ -1688,9 +1688,9 @@ func (s *testIntegrationSuite3) TestUnsupportedPartitionManagementDDLs(c *C) {
`)

_, err := tk.Exec("alter table test_1465 truncate partition p1, p2")
c.Assert(err, ErrorMatches, ".*can't run multi schema change")
c.Assert(err, ErrorMatches, ".*Unsupported multi schema change")
_, err = tk.Exec("alter table test_1465 drop partition p1, p2")
c.Assert(err, ErrorMatches, ".*can't run multi schema change")
c.Assert(err, ErrorMatches, ".*Unsupported multi schema change")

_, err = tk.Exec("alter table test_1465 partition by hash(a)")
c.Assert(err, ErrorMatches, ".*alter table partition is unsupported")
Expand Down
28 changes: 14 additions & 14 deletions ddl/db_test.go
Expand Up @@ -332,7 +332,7 @@ LOOP:
case err := <-done:
c.Assert(checkErr, IsNil)
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[ddl:12]cancelled DDL job")
c.Assert(err.Error(), Equals, "[ddl:8214]Cancelled DDL job")
break LOOP
case <-ticker.C:
if times >= 10 {
Expand Down Expand Up @@ -414,7 +414,7 @@ func (s *testDBSuite4) TestCancelAddIndex1(c *C) {
}
c.Assert(checkErr, IsNil)
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[ddl:12]cancelled DDL job")
c.Assert(err.Error(), Equals, "[ddl:8214]Cancelled DDL job")

s.dom.DDL().(ddl.DDLForTest).SetHook(originalHook)
t := s.testGetTable(c, "t")
Expand Down Expand Up @@ -495,7 +495,7 @@ func (s *testDBSuite5) TestCancelDropIndex(c *C) {
if testCase.cancelSucc {
c.Assert(checkErr, IsNil)
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[ddl:12]cancelled DDL job")
c.Assert(err.Error(), Equals, "[ddl:8214]Cancelled DDL job")
c.Assert(indexInfo, NotNil)
c.Assert(indexInfo.State, Equals, model.StatePublic)
} else {
Expand Down Expand Up @@ -553,7 +553,7 @@ func (s *testDBSuite5) TestCancelTruncateTable(c *C) {
_, err := s.tk.Exec("truncate table t")
c.Assert(checkErr, IsNil)
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[ddl:12]cancelled DDL job")
c.Assert(err.Error(), Equals, "[ddl:8214]Cancelled DDL job")
s.dom.DDL().(ddl.DDLForTest).SetHook(originalHook)
}

Expand Down Expand Up @@ -606,7 +606,7 @@ func (s *testDBSuite1) TestCancelRenameIndex(c *C) {
}
c.Assert(checkErr, IsNil)
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[ddl:12]cancelled DDL job")
c.Assert(err.Error(), Equals, "[ddl:8214]Cancelled DDL job")
s.dom.DDL().(ddl.DDLForTest).SetHook(originalHook)
t := s.testGetTable(c, "t")
for _, idx := range t.Indices() {
Expand Down Expand Up @@ -696,7 +696,7 @@ func (s *testDBSuite2) TestCancelDropTableAndSchema(c *C) {
if testCase.cancelSucc {
c.Assert(checkErr, IsNil)
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[ddl:12]cancelled DDL job")
c.Assert(err.Error(), Equals, "[ddl:8214]Cancelled DDL job")
s.mustExec(c, "insert into t values (?, ?)", i, i)
} else {
c.Assert(err, IsNil)
Expand Down Expand Up @@ -1205,7 +1205,7 @@ func (s *testDBSuite3) TestCancelDropColumn(c *C) {
c.Assert(checkErr, IsNil)
c.Assert(col1, NotNil)
c.Assert(col1.Name.L, Equals, "c3")
c.Assert(err1.Error(), Equals, "[ddl:12]cancelled DDL job")
c.Assert(err1.Error(), Equals, "[ddl:8214]Cancelled DDL job")
} else {
c.Assert(col1, IsNil)
c.Assert(err1, IsNil)
Expand Down Expand Up @@ -1459,11 +1459,11 @@ LOOP:
// test add unsupported constraint
s.mustExec(c, "create table t_add_unsupported_constraint (a int);")
_, err = s.tk.Exec("ALTER TABLE t_add_unsupported_constraint ADD id int AUTO_INCREMENT;")
c.Assert(err.Error(), Equals, "[ddl:202]unsupported add column 'id' constraint AUTO_INCREMENT when altering 'test_db.t_add_unsupported_constraint'")
c.Assert(err.Error(), Equals, "[ddl:8200]unsupported add column 'id' constraint AUTO_INCREMENT when altering 'test_db.t_add_unsupported_constraint'")
_, err = s.tk.Exec("ALTER TABLE t_add_unsupported_constraint ADD id int KEY;")
c.Assert(err.Error(), Equals, "[ddl:202]unsupported add column 'id' constraint PRIMARY KEY when altering 'test_db.t_add_unsupported_constraint'")
c.Assert(err.Error(), Equals, "[ddl:8200]unsupported add column 'id' constraint PRIMARY KEY when altering 'test_db.t_add_unsupported_constraint'")
_, err = s.tk.Exec("ALTER TABLE t_add_unsupported_constraint ADD id int UNIQUE;")
c.Assert(err.Error(), Equals, "[ddl:202]unsupported add column 'id' constraint UNIQUE KEY when altering 'test_db.t_add_unsupported_constraint'")
c.Assert(err.Error(), Equals, "[ddl:8200]unsupported add column 'id' constraint UNIQUE KEY when altering 'test_db.t_add_unsupported_constraint'")
}

func (s *testDBSuite) testDropColumn(c *C) {
Expand Down Expand Up @@ -1635,7 +1635,7 @@ func (s *testDBSuite4) TestChangeColumn(c *C) {
sql = "alter table t4 change c2 a bigint not null;"
s.tk.MustGetErrCode(sql, tmysql.WarnDataTruncated)
sql = "alter table t3 modify en enum('a', 'z', 'b', 'c') not null default 'a'"
s.tk.MustGetErrCode(sql, tmysql.ErrUnknown)
s.tk.MustGetErrCode(sql, tmysql.ErrUnsupportedDDLOperation)
// Rename to an existing column.
s.mustExec(c, "alter table t3 add column a bigint")
sql = "alter table t3 change aa a bigint"
Expand Down Expand Up @@ -2403,7 +2403,7 @@ func (s *testDBSuite4) TestRebaseAutoID(c *C) {
s.tk.MustQuery("select * from tidb.test").Check(testkit.Rows("1 1", "6000 1", "11000 1", "16000 1"))

s.tk.MustExec("create table tidb.test2 (a int);")
s.tk.MustGetErrCode("alter table tidb.test2 add column b int auto_increment key, auto_increment=10;", tmysql.ErrUnknown)
s.tk.MustGetErrCode("alter table tidb.test2 add column b int auto_increment key, auto_increment=10;", tmysql.ErrUnsupportedDDLOperation)
}

func (s *testDBSuite5) TestCheckColumnDefaultValue(c *C) {
Expand Down Expand Up @@ -2655,7 +2655,7 @@ LOOP:
select {
case err := <-done:
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[ddl:12]cancelled DDL job")
c.Assert(err.Error(), Equals, "[ddl:8214]Cancelled DDL job")
break LOOP
case <-ticker.C:
s.mustExec(c, "insert into t1(c2) values (null);")
Expand Down Expand Up @@ -3012,7 +3012,7 @@ func (s *testDBSuite5) TestAddIndexForGeneratedColumn(c *C) {
s.tk.MustExec("insert into t values()")
s.tk.MustExec("ALTER TABLE t ADD COLUMN y1 year as (y + 2)")
_, err := s.tk.Exec("ALTER TABLE t ADD INDEX idx_y(y1)")
c.Assert(err.Error(), Equals, "[ddl:15]cannot decode index value, because cannot convert datum from unsigned bigint to type year.")
c.Assert(err.Error(), Equals, "[ddl:8202]Cannot decode index value, because cannot convert datum from unsigned bigint to type year.")

t := s.testGetTable(c, "t")
for _, idx := range t.Indices() {
Expand Down