Skip to content

Commit

Permalink
ddl: exit add index on generated column with case-when expression p…
Browse files Browse the repository at this point in the history
…arse error (pingcap#19330) (pingcap#19395)
  • Loading branch information
ti-srebot authored Aug 26, 2020
1 parent 0a26737 commit f22dc78
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4676,6 +4676,23 @@ func (s *testSerialDBSuite) TestDDLJobErrorCount(c *C) {
}
}

// TestAddIndexFailOnCaseWhenCanExit is used to close #19325.
func (s *testSerialDBSuite) TestAddIndexFailOnCaseWhenCanExit(c *C) {
c.Assert(failpoint.Enable("github.com/pingcap/tidb/ddl/MockCaseWhenParseFailure", `return(true)`), IsNil)
defer func() {
c.Assert(failpoint.Disable("github.com/pingcap/tidb/ddl/MockCaseWhenParseFailure"), IsNil)
}()
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, b int)")
tk.MustExec("insert into t values(1, 1)")
_, err := tk.Exec("alter table t add index idx(b)")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[ddl:8214]Cancelled DDL job")
tk.MustExec("drop table if exists t")
}

func init() {
// Make sure it will only be executed once.
domain.SchemaOutOfDateRetryInterval = int64(50 * time.Millisecond)
Expand Down
10 changes: 10 additions & 0 deletions ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,16 @@ func (w *worker) addPhysicalTableIndex(t table.PhysicalTable, indexInfo *model.I
logutil.BgLogger().Info("[ddl] start to add table index", zap.String("job", job.String()), zap.String("reorgInfo", reorgInfo.String()))
totalAddedCount := job.GetRowCount()

if err := w.isReorgRunnable(reorgInfo.d); err != nil {
return errors.Trace(err)
}

failpoint.Inject("MockCaseWhenParseFailure", func(val failpoint.Value) {
if val.(bool) {
failpoint.Return(errors.New("job.ErrCount:" + strconv.Itoa(int(job.ErrorCount)) + ", mock unknown type: ast.whenClause."))
}
})

startHandle, endHandle := reorgInfo.StartHandle, reorgInfo.EndHandle
sessCtx := newContext(reorgInfo.d.store)
decodeColMap, err := makeupDecodeColMap(sessCtx, t, indexInfo)
Expand Down

0 comments on commit f22dc78

Please sign in to comment.