Skip to content

Commit 6efce0f

Browse files
authored
executor: sync deletable columns to binlog when remove record (#53617)
close #53133
1 parent afd2343 commit 6efce0f

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

pkg/ddl/column.go

+2
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ func onAddColumn(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, err error)
172172
case model.StateWriteReorganization:
173173
// reorganization -> public
174174
// Adjust table column offset.
175+
failpoint.InjectCall("onAddColumnStateWriteReorg")
175176
offset, err := LocateOffsetToMove(columnInfo.Offset, pos, tblInfo)
176177
if err != nil {
177178
return ver, errors.Trace(err)
@@ -271,6 +272,7 @@ func onDropColumn(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error)
271272
}
272273
case model.StateWriteOnly:
273274
// write only -> delete only
275+
failpoint.InjectCall("onDropColumnStateWriteOnly")
274276
colInfo.State = model.StateDeleteOnly
275277
tblInfo.MoveColumnInfo(colInfo.Offset, len(tblInfo.Columns)-1)
276278
if len(idxInfos) > 0 {

pkg/executor/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ go_test(
426426
"//pkg/testkit",
427427
"//pkg/testkit/external",
428428
"//pkg/testkit/testdata",
429+
"//pkg/testkit/testfailpoint",
429430
"//pkg/testkit/testmain",
430431
"//pkg/testkit/testsetup",
431432
"//pkg/types",

pkg/executor/executor_txn_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ import (
1818
"fmt"
1919
"strconv"
2020
"strings"
21+
"sync"
2122
"testing"
2223
"time"
2324

25+
"github.com/pingcap/tidb/pkg/errno"
2426
"github.com/pingcap/tidb/pkg/executor"
2527
"github.com/pingcap/tidb/pkg/sessionctx/binloginfo"
2628
"github.com/pingcap/tidb/pkg/testkit"
29+
"github.com/pingcap/tidb/pkg/testkit/testfailpoint"
2730
"github.com/stretchr/testify/require"
2831
)
2932

@@ -694,3 +697,40 @@ func TestSavepointWithBinlog(t *testing.T) {
694697
tk.MustExec("commit")
695698
tk.MustQuery("select * from t").Check(testkit.Rows("1 1"))
696699
}
700+
701+
func TestColumnNotMatchError(t *testing.T) {
702+
store := testkit.CreateMockStore(t)
703+
tk := testkit.NewTestKit(t, store)
704+
tk.Session().GetSessionVars().BinlogClient = binloginfo.MockPumpsClient(&testkit.MockPumpClient{})
705+
tk.MustExec("set @@global.tidb_enable_metadata_lock=0")
706+
tk.MustExec("use test")
707+
tk2 := testkit.NewTestKit(t, store)
708+
tk2.MustExec("use test")
709+
tk.MustExec("create table t(id int primary key, a int)")
710+
tk.MustExec("insert into t values(1, 2)")
711+
712+
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/onAddColumnStateWriteReorg", func() {
713+
tk.MustExec("begin;")
714+
})
715+
var wg sync.WaitGroup
716+
wg.Add(1)
717+
go func() {
718+
tk2.MustExec("alter table t add column wait_notify int")
719+
wg.Done()
720+
}()
721+
wg.Wait()
722+
tk.MustExec("delete from t where id=1")
723+
tk.MustGetErrCode("commit", errno.ErrInfoSchemaChanged)
724+
725+
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/onDropColumnStateWriteOnly", func() {
726+
tk.MustExec("begin;")
727+
})
728+
wg.Add(1)
729+
go func() {
730+
tk2.MustExec("alter table t drop column wait_notify")
731+
wg.Done()
732+
}()
733+
wg.Wait()
734+
tk.MustExec("delete from t where id=1")
735+
tk.MustGetErrCode("commit", errno.ErrInfoSchemaChanged)
736+
}

pkg/table/tables/tables.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ func (t *TableCommon) RemoveRecord(ctx table.MutateContext, h kv.Handle, r []typ
13681368
memBuffer.Release(sh)
13691369

13701370
if shouldWriteBinlog(ctx.GetSessionVars(), t.meta) {
1371-
cols := t.Cols()
1371+
cols := t.DeletableCols()
13721372
colIDs := make([]int64, 0, len(cols)+1)
13731373
for _, col := range cols {
13741374
colIDs = append(colIDs, col.ID)

0 commit comments

Comments
 (0)