diff --git a/ddl/db_test.go b/ddl/db_test.go index d4d116cf54450..53091c994c740 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -6590,3 +6590,37 @@ func (s *testSerialDBSuite) TestIssue22819(c *C) { _, err := tk1.Exec("commit") c.Assert(err, ErrorMatches, ".*8028.*Information schema is changed during the execution of the statement.*") } +<<<<<<< HEAD +======= + +func (s *testSerialSuite) TestTruncateAllPartitions(c *C) { + tk1 := testkit.NewTestKit(c, s.store) + tk1.MustExec("use test;") + tk1.MustExec("drop table if exists partition_table;") + defer func() { + tk1.MustExec("drop table if exists partition_table;") + }() + tk1.MustExec("create table partition_table (v int) partition by hash (v) partitions 10;") + tk1.MustExec("insert into partition_table values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10);") + tk1.MustExec("alter table partition_table truncate partition all;") + tk1.MustQuery("select count(*) from partition_table;").Check(testkit.Rows("0")) +} + +// Close issue #23321. +// See https://github.com/pingcap/tidb/issues/23321 +func (s *testSerialDBSuite) TestJsonUnmarshalErrWhenPanicInCancellingPath(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + + tk.MustExec("drop table if exists test_add_index_after_add_col") + tk.MustExec("create table test_add_index_after_add_col(a int, b int not null default '0');") + tk.MustExec("insert into test_add_index_after_add_col values(1, 2),(2,2);") + tk.MustExec("alter table test_add_index_after_add_col add column c int not null default '0';") + + c.Assert(failpoint.Enable("github.com/pingcap/tidb/ddl/mockExceedErrorLimit", `return(true)`), IsNil) + defer c.Assert(failpoint.Disable("github.com/pingcap/tidb/ddl/mockExceedErrorLimit"), IsNil) + + _, err := tk.Exec("alter table test_add_index_after_add_col add unique index cc(c);") + c.Assert(err.Error(), Equals, "[kv:1062]Duplicate entry '0' for key 'cc'") +} +>>>>>>> 552503442... ddl: rollingback add index meets panic leads json unmarshal object error-2 master (#23913) diff --git a/ddl/ddl_worker.go b/ddl/ddl_worker.go index 1c263821b932b..33ebaea2c5f6f 100644 --- a/ddl/ddl_worker.go +++ b/ddl/ddl_worker.go @@ -624,7 +624,11 @@ func chooseLeaseTime(t, max time.Duration) time.Duration { // countForPanic records the error count for DDL job. func (w *worker) countForPanic(job *model.Job) { // If run DDL job panic, just cancel the DDL jobs. - job.State = model.JobStateCancelling + if job.State == model.JobStateRollingback { + job.State = model.JobStateCancelled + } else { + job.State = model.JobStateCancelling + } job.ErrorCount++ // Load global DDL variables.