Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#53617
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
tangenta authored and ti-chi-bot committed May 31, 2024
1 parent d9c5bf6 commit 396be5b
Show file tree
Hide file tree
Showing 4 changed files with 541 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ddl/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,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)
Expand Down Expand Up @@ -263,6 +264,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 {
Expand Down
47 changes: 47 additions & 0 deletions executor/executor_txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,22 @@ import (
"fmt"
"strconv"
"strings"
"sync"
"testing"
"time"

<<<<<<< HEAD:executor/executor_txn_test.go
"github.com/pingcap/tidb/executor"
"github.com/pingcap/tidb/sessionctx/binloginfo"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tipb/go-binlog"
=======
"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"
>>>>>>> 6efce0f061d (executor: sync deletable columns to binlog when remove record (#53617)):pkg/executor/executor_txn_test.go
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
)
Expand Down Expand Up @@ -789,6 +798,7 @@ func TestSavepointWithBinlog(t *testing.T) {
tk.MustQuery("select * from t").Check(testkit.Rows("1 1"))
}

<<<<<<< HEAD:executor/executor_txn_test.go
type mockPumpClient struct{}

func (m mockPumpClient) WriteBinlog(ctx context.Context, in *binlog.WriteBinlogReq, opts ...grpc.CallOption) (*binlog.WriteBinlogResp, error) {
Expand All @@ -797,4 +807,41 @@ func (m mockPumpClient) WriteBinlog(ctx context.Context, in *binlog.WriteBinlogR

func (m mockPumpClient) PullBinlogs(ctx context.Context, in *binlog.PullBinlogReq, opts ...grpc.CallOption) (binlog.Pump_PullBinlogsClient, error) {
return nil, nil
=======
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)
>>>>>>> 6efce0f061d (executor: sync deletable columns to binlog when remove record (#53617)):pkg/executor/executor_txn_test.go
}
Loading

0 comments on commit 396be5b

Please sign in to comment.