Skip to content

Commit f434660

Browse files
committed
reproduce data and columnID count not match
1 parent 9c5981c commit f434660

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

pkg/ddl/column.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ import (
5555
"go.uber.org/zap"
5656
)
5757

58+
var WaitChan chan struct{}
59+
5860
// InitAndAddColumnToTable initializes the ColumnInfo in-place and adds it to the table.
5961
func InitAndAddColumnToTable(tblInfo *model.TableInfo, colInfo *model.ColumnInfo) *model.ColumnInfo {
6062
cols := tblInfo.Columns
@@ -171,6 +173,10 @@ func onAddColumn(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, err error)
171173
case model.StateWriteReorganization:
172174
// reorganization -> public
173175
// Adjust table column offset.
176+
if columnInfo.Name.L == "wait_notify" {
177+
WaitChan <- struct{}{}
178+
<-WaitChan
179+
}
174180
offset, err := LocateOffsetToMove(columnInfo.Offset, pos, tblInfo)
175181
if err != nil {
176182
return ver, errors.Trace(err)

pkg/executor/executor_txn_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222
"time"
2323

24+
"github.com/pingcap/tidb/pkg/ddl"
2425
"github.com/pingcap/tidb/pkg/executor"
2526
"github.com/pingcap/tidb/pkg/sessionctx/binloginfo"
2627
"github.com/pingcap/tidb/pkg/testkit"
@@ -694,3 +695,32 @@ func TestSavepointWithBinlog(t *testing.T) {
694695
tk.MustExec("commit")
695696
tk.MustQuery("select * from t").Check(testkit.Rows("1 1"))
696697
}
698+
699+
func TestColumnNotMatchError(t *testing.T) {
700+
ddl.WaitChan = make(chan struct{})
701+
store := testkit.CreateMockStore(t)
702+
tk := testkit.NewTestKit(t, store)
703+
tk.Session().GetSessionVars().BinlogClient = binloginfo.MockPumpsClient(&testkit.MockPumpClient{})
704+
tk.MustExec("set @@global.tidb_enable_metadata_lock=0")
705+
tk.MustExec("use test")
706+
tk2 := testkit.NewTestKit(t, store)
707+
tk2.MustExec("use test")
708+
tk.MustExec("create table t(id int primary key, a int)")
709+
tk.MustExec("insert into t values(1, 2)")
710+
go func() {
711+
tk2.MustExec("alter table t add column wait_notify int")
712+
close(ddl.WaitChan)
713+
}()
714+
// wait the ddl stage to the reorg
715+
<-ddl.WaitChan
716+
// begin to make sure the table t in txn contains a no public column
717+
tk.MustExec("begin")
718+
// continue ddl and wait it finished to avoid some necessary error log
719+
ddl.WaitChan <- struct{}{}
720+
<-ddl.WaitChan
721+
// this statement will fail because:
722+
// - schema in the plan includes the non-public column -> data contains non-public column
723+
// - table.Cols() does not contain the non-public column
724+
tk.MustExec("delete from t where id=1")
725+
tk.MustExec("commit")
726+
}

0 commit comments

Comments
 (0)