Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

txn: disable amend by default on master #21829

Merged
merged 4 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5970,6 +5970,7 @@ func (s *testDBSuite1) TestAlterTableWithValidation(c *C) {
func (s *testSerialDBSuite) TestCommitTxnWithIndexChange(c *C) {
// Prepare work.
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("set tidb_enable_amend_pessimistic_txn = 1;")
tk.MustExec("drop database if exists test_db")
tk.MustExec("create database test_db")
tk.MustExec("use test_db")
Expand Down Expand Up @@ -6041,7 +6042,6 @@ func (s *testSerialDBSuite) TestCommitTxnWithIndexChange(c *C) {
false,
model.StateNone},
// Test unique index
/* TODO unique index is not supported now.
{[]string{"insert into t1 values(3, 30, 300)",
"insert into t1 values(4, 40, 400)",
"insert into t2 values(11, 11, 11)",
Expand Down Expand Up @@ -6085,7 +6085,6 @@ func (s *testSerialDBSuite) TestCommitTxnWithIndexChange(c *C) {
{"1 10 100", "2 20 200"}},
true,
model.StateWriteOnly},
*/
}
tk.MustQuery("select * from t1;").Check(testkit.Rows("1 10 100", "2 20 200"))

Expand Down
14 changes: 11 additions & 3 deletions session/pessimistic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,7 @@ func (s *testPessimisticSuite) TestPessimisticTxnWithDDLAddDropColumn(c *C) {

// tk2 starts a pessimistic transaction and make some changes on table t1.
// tk executes some ddl statements add/drop column on table t1.
tk.MustExec("set tidb_enable_amend_pessimistic_txn = 1;")
tk.MustExec("begin pessimistic")
tk.MustExec("update t1 set c2 = c1 * 10")
tk2.MustExec("alter table t1 add column c3 int after c1")
Expand All @@ -1612,6 +1613,7 @@ func (s *testPessimisticSuite) TestPessimisticTxnWithDDLAddDropColumn(c *C) {
tk.MustExec("commit")
tk.MustQuery("select * from t1").Check(testkit.Rows("1", "2", "5"))
}

func (s *testPessimisticSuite) TestPessimisticTxnWithDDLChangeColumn(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk2 := testkit.NewTestKitWithInit(c, s.store)
Expand All @@ -1624,6 +1626,7 @@ func (s *testPessimisticSuite) TestPessimisticTxnWithDDLChangeColumn(c *C) {
tk.MustExec("insert t1 values (1, 77, 'a'), (2, 88, 'b')")

// Extend column field length is acceptable.
tk.MustExec("set tidb_enable_amend_pessimistic_txn = 1;")
tk.MustExec("begin pessimistic")
tk.MustExec("update t1 set c2 = c1 * 10")
tk2.MustExec("alter table t1 modify column c2 bigint")
Expand Down Expand Up @@ -1892,13 +1895,15 @@ func (s *testPessimisticSuite) TestAmendTxnVariable(c *C) {
tk3.MustExec("set tidb_enable_amend_pessimistic_txn = 0;")
tk3.MustExec("begin pessimistic")
tk3.MustExec("insert into t1 values(3, 3, 3)")
tk.MustExec("set tidb_enable_amend_pessimistic_txn = 1;")
tk.MustExec("begin pessimistic")
tk.MustExec("insert into t1 values(4, 4, 4)")
tk2.MustExec("alter table t1 add column new_col int")
err := tk3.ExecToErr("commit")
c.Assert(err, NotNil)
tk.MustExec("commit")
tk2.MustQuery("select * from t1").Check(testkit.Rows("1 1 1 <nil>", "2 2 2 <nil>", "4 4 4 <nil>"))
tk.MustExec("set tidb_enable_amend_pessimistic_txn = 0;")

// Set off the global variable.
tk2.MustExec("set global tidb_enable_amend_pessimistic_txn = 0;")
Expand All @@ -1916,9 +1921,6 @@ func (s *testPessimisticSuite) TestAmendTxnVariable(c *C) {
tk2.MustExec("alter table t1 add column new_col2 int")
tk4.MustExec("commit")
tk2.MustQuery("select * from t1").Check(testkit.Rows("1 1 1 <nil>", "2 2 2 <nil>", "4 4 4 <nil>", "5 5 5 <nil>"))

// Restore.
tk2.MustExec("set global tidb_enable_amend_pessimistic_txn = 1;")
}

func (s *testPessimisticSuite) TestSelectForUpdateWaitSeconds(c *C) {
Expand Down Expand Up @@ -2032,6 +2034,9 @@ func (s *testPessimisticSuite) TestAsyncCommitWithSchemaChange(c *C) {
tk.MustExec("insert into tk values(1, 1, 1)")
tk2 := s.newAsyncCommitTestKitWithInit(c)
tk3 := s.newAsyncCommitTestKitWithInit(c)
tk.MustExec("set tidb_enable_amend_pessimistic_txn = 1;")
tk2.MustExec("set tidb_enable_amend_pessimistic_txn = 1;")
tk3.MustExec("set tidb_enable_amend_pessimistic_txn = 1;")

// The txn tk writes something but with failpoint the primary key is not committed.
tk.MustExec("begin pessimistic")
Expand Down Expand Up @@ -2097,6 +2102,9 @@ func (s *testPessimisticSuite) Test1PCWithSchemaChange(c *C) {
tk.MustExec("drop table if exists tk")
tk.MustExec("create table tk (c1 int primary key, c2 int)")
tk.MustExec("insert into tk values (1, 1)")
tk.MustExec("set tidb_enable_amend_pessimistic_txn = 1;")
tk2.MustExec("set tidb_enable_amend_pessimistic_txn = 1;")
tk3.MustExec("set tidb_enable_amend_pessimistic_txn = 1;")

tk.MustExec("begin pessimistic")
tk.MustExec("insert into tk values(2, 2)")
Expand Down
2 changes: 2 additions & 0 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,8 @@ func (s *testSchemaSuite) TestRetrySchemaChangeForEmptyChange(c *C) {
tk.MustExec("insert into t1 values (1)")
tk.MustExec("commit")

// TODO remove this enable after fixing table delta map.
tk.MustExec("set tidb_enable_amend_pessimistic_txn = 1")
tk.MustExec("begin pessimistic")
tk1.MustExec("alter table t add k int")
tk.MustExec("select * from t for update")
Expand Down
2 changes: 1 addition & 1 deletion sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ const (
DefTiDBShardAllocateStep = math.MaxInt64
DefTiDBEnableTelemetry = true
DefTiDBEnableParallelApply = false
DefTiDBEnableAmendPessimisticTxn = true
DefTiDBEnableAmendPessimisticTxn = false
DefTiDBPartitionPruneMode = "static-only"
DefTiDBEnableRateLimitAction = true
DefTiDBEnableAsyncCommit = false
Expand Down