Skip to content

Commit

Permalink
ddl: persist index info after changing backfill state (#40229) (#40305)
Browse files Browse the repository at this point in the history
close #40217
  • Loading branch information
ti-chi-bot authored Jan 29, 2023
1 parent d1dcac6 commit 14c7dce
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 222 deletions.
26 changes: 0 additions & 26 deletions ddl/concurrentddltest/BUILD.bazel

This file was deleted.

45 changes: 0 additions & 45 deletions ddl/concurrentddltest/main_test.go

This file was deleted.

149 changes: 0 additions & 149 deletions ddl/concurrentddltest/switch_test.go

This file was deleted.

5 changes: 4 additions & 1 deletion ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,9 @@ func doReorgWorkForCreateIndexMultiSchema(w *worker, d *ddlCtx, t *meta.Meta, jo
done, ver, err = doReorgWorkForCreateIndex(w, d, t, job, tbl, indexInfo)
if done {
job.MarkNonRevertible()
if err == nil {
ver, err = updateVersionAndTableInfo(d, t, job, tbl.Meta(), true)
}
}
// We need another round to wait for all the others sub-jobs to finish.
return false, ver, err
Expand Down Expand Up @@ -857,7 +860,7 @@ func doReorgWorkForCreateIndex(w *worker, d *ddlCtx, t *meta.Meta, job *model.Jo
return false, ver, err
}
indexInfo.BackfillState = model.BackfillStateInapplicable // Prevent double-write on this index.
return true, ver, nil
return true, ver, err
default:
return false, 0, dbterror.ErrInvalidDDLState.GenWithStackByArgs("backfill", indexInfo.BackfillState)
}
Expand Down
11 changes: 11 additions & 0 deletions ddl/multi_schema_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,17 @@ func TestMultiSchemaChangeSchemaVersion(t *testing.T) {
dom.DDL().SetHook(originHook)
}

func TestMultiSchemaChangeAddIndexChangeColumn(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
tk.MustExec("CREATE TABLE t (a SMALLINT DEFAULT '30219', b TIME NULL DEFAULT '02:45:06', PRIMARY KEY (a));")
tk.MustExec("ALTER TABLE t ADD unique INDEX idx4 (b), change column a e MEDIUMINT DEFAULT '5280454' FIRST;")
tk.MustExec("insert ignore into t (e) values (5586359),(501788),(-5961048),(220083),(-4917129),(-7267211),(7750448);")
tk.MustQuery("select * from t;").Check(testkit.Rows("5586359 02:45:06"))
tk.MustExec("admin check table t;")
}

func TestMultiSchemaChangeMixedWithUpdate(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)
Expand Down
2 changes: 1 addition & 1 deletion executor/batch_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func getKeysNeedCheckOneRow(ctx sessionctx.Context, t table.Table, row []types.D
continue
}
// If index is used ingest ways, then we should check key from temp index.
if v.Meta().BackfillState != model.BackfillStateInapplicable {
if v.Meta().State != model.StatePublic && v.Meta().BackfillState != model.BackfillStateInapplicable {
_, key, _ = tables.GenTempIdxKeyByState(v.Meta(), key)
}
colValStr, err1 := formatDataForDupError(colVals)
Expand Down

0 comments on commit 14c7dce

Please sign in to comment.