Skip to content

Commit

Permalink
ddl: fix multi-schema change success when sub-job failed (pingcap#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 authored Apr 18, 2022
1 parent 619f939 commit b4b25ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ddl/multi_schema_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"sync"

"github.com/pingcap/errors"
ddlutil "github.com/pingcap/tidb/ddl/util"
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/model"
Expand All @@ -32,6 +33,7 @@ func (d *ddl) MultiSchemaChange(ctx sessionctx.Context, ti ast.Ident) error {
if err != nil {
return errors.Trace(err)
}
tzName, tzOffset := ddlutil.GetTimeZone(ctx)
job := &model.Job{
SchemaID: schema.ID,
TableID: t.Meta().ID,
Expand All @@ -40,6 +42,12 @@ func (d *ddl) MultiSchemaChange(ctx sessionctx.Context, ti ast.Ident) error {
BinlogInfo: &model.HistoryInfo{},
Args: nil,
MultiSchemaInfo: ctx.GetSessionVars().StmtCtx.MultiSchemaInfo,
ReorgMeta: &model.DDLReorgMeta{
SQLMode: ctx.GetSessionVars().SQLMode,
Warnings: make(map[errors.ErrorID]*terror.Error),
WarningsCount: make(map[errors.ErrorID]int64),
Location: &model.TimeZoneLocation{Name: tzName, Offset: tzOffset},
},
}
err = checkMultiSchemaInfo(ctx.GetSessionVars().StmtCtx.MultiSchemaInfo, t)
if err != nil {
Expand Down Expand Up @@ -298,11 +306,7 @@ func checkOperateSameColumn(info *model.MultiSchemaInfo) error {
if err := checkIndexes(info.AddIndexes, true); err != nil {
return err
}
if err := checkIndexes(info.DropIndexes, true); err != nil {
return err
}

return nil
return checkIndexes(info.DropIndexes, true)
}

func checkMultiSchemaInfo(info *model.MultiSchemaInfo, t table.Table) error {
Expand Down
5 changes: 5 additions & 0 deletions ddl/multi_schema_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,11 @@ func TestMultiSchemaChangeModifyColumns(t *testing.T) {
tk.MustQuery("select * from t use index(i1, i2);").Check(testkit.Rows("1 3 2", "11 33 22"))
tk.MustExec("admin check table t;")
checkDelRangeCnt(tk, jobIDExt.jobID, 1) // only i2 has tmp index.

tk.MustExec("drop table if exists t;")
tk.MustExec("create table t(a bigint null default '1761233443433596323', index t(a));")
tk.MustExec("insert into t set a = '-7184819032643664798';")
tk.MustGetErrCode("alter table t change column a b datetime null default '8972-12-24 10:56:03', rename index t to t1;", errno.ErrTruncatedWrongValue)
}

func TestMultiSchemaChangeModifyColumnsCancelled(t *testing.T) {
Expand Down

0 comments on commit b4b25ec

Please sign in to comment.