diff --git a/pkg/ddl/column.go b/pkg/ddl/column.go index e7f8efa4744a1..206b64d5137df 100644 --- a/pkg/ddl/column.go +++ b/pkg/ddl/column.go @@ -172,6 +172,7 @@ func onAddColumn(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, err error) case model.StateWriteReorganization: // reorganization -> public // Adjust table column offset. + failpoint.InjectCall("onAddColumnStateWriteReorg") offset, err := LocateOffsetToMove(columnInfo.Offset, pos, tblInfo) if err != nil { return ver, errors.Trace(err) @@ -271,6 +272,7 @@ func onDropColumn(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error) } case model.StateWriteOnly: // write only -> delete only + failpoint.InjectCall("onDropColumnStateWriteOnly") colInfo.State = model.StateDeleteOnly tblInfo.MoveColumnInfo(colInfo.Offset, len(tblInfo.Columns)-1) if len(idxInfos) > 0 { diff --git a/pkg/executor/BUILD.bazel b/pkg/executor/BUILD.bazel index 884e22d90b624..d68fcaf601852 100644 --- a/pkg/executor/BUILD.bazel +++ b/pkg/executor/BUILD.bazel @@ -426,6 +426,7 @@ go_test( "//pkg/testkit", "//pkg/testkit/external", "//pkg/testkit/testdata", + "//pkg/testkit/testfailpoint", "//pkg/testkit/testmain", "//pkg/testkit/testsetup", "//pkg/types", diff --git a/pkg/executor/executor_txn_test.go b/pkg/executor/executor_txn_test.go index bf63b8d072f8c..76f5773ceca7e 100644 --- a/pkg/executor/executor_txn_test.go +++ b/pkg/executor/executor_txn_test.go @@ -18,12 +18,15 @@ import ( "fmt" "strconv" "strings" + "sync" "testing" "time" + "github.com/pingcap/tidb/pkg/errno" "github.com/pingcap/tidb/pkg/executor" "github.com/pingcap/tidb/pkg/sessionctx/binloginfo" "github.com/pingcap/tidb/pkg/testkit" + "github.com/pingcap/tidb/pkg/testkit/testfailpoint" "github.com/stretchr/testify/require" ) @@ -694,3 +697,40 @@ func TestSavepointWithBinlog(t *testing.T) { tk.MustExec("commit") tk.MustQuery("select * from t").Check(testkit.Rows("1 1")) } + +func TestColumnNotMatchError(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.Session().GetSessionVars().BinlogClient = binloginfo.MockPumpsClient(&testkit.MockPumpClient{}) + tk.MustExec("set @@global.tidb_enable_metadata_lock=0") + tk.MustExec("use test") + tk2 := testkit.NewTestKit(t, store) + tk2.MustExec("use test") + tk.MustExec("create table t(id int primary key, a int)") + tk.MustExec("insert into t values(1, 2)") + + testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/onAddColumnStateWriteReorg", func() { + tk.MustExec("begin;") + }) + var wg sync.WaitGroup + wg.Add(1) + go func() { + tk2.MustExec("alter table t add column wait_notify int") + wg.Done() + }() + wg.Wait() + tk.MustExec("delete from t where id=1") + tk.MustGetErrCode("commit", errno.ErrInfoSchemaChanged) + + testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/onDropColumnStateWriteOnly", func() { + tk.MustExec("begin;") + }) + wg.Add(1) + go func() { + tk2.MustExec("alter table t drop column wait_notify") + wg.Done() + }() + wg.Wait() + tk.MustExec("delete from t where id=1") + tk.MustGetErrCode("commit", errno.ErrInfoSchemaChanged) +} diff --git a/pkg/table/tables/tables.go b/pkg/table/tables/tables.go index dc4b2f580aac4..d287d0e778554 100644 --- a/pkg/table/tables/tables.go +++ b/pkg/table/tables/tables.go @@ -1368,7 +1368,7 @@ func (t *TableCommon) RemoveRecord(ctx table.MutateContext, h kv.Handle, r []typ memBuffer.Release(sh) if shouldWriteBinlog(ctx.GetSessionVars(), t.meta) { - cols := t.Cols() + cols := t.DeletableCols() colIDs := make([]int64, 0, len(cols)+1) for _, col := range cols { colIDs = append(colIDs, col.ID)