diff --git a/br/pkg/lightning/backend/local/BUILD.bazel b/br/pkg/lightning/backend/local/BUILD.bazel index 6e2b5e9a1c43c..c034e6bdb2b3c 100644 --- a/br/pkg/lightning/backend/local/BUILD.bazel +++ b/br/pkg/lightning/backend/local/BUILD.bazel @@ -94,7 +94,7 @@ go_test( ], embed = [":local"], flaky = True, - shard_count = 20, + shard_count = 40, deps = [ "//br/pkg/errors", "//br/pkg/lightning/backend", diff --git a/br/pkg/utils/BUILD.bazel b/br/pkg/utils/BUILD.bazel index 0ae948d18a779..c3bcc629183d5 100644 --- a/br/pkg/utils/BUILD.bazel +++ b/br/pkg/utils/BUILD.bazel @@ -79,6 +79,7 @@ go_test( ], embed = [":utils"], flaky = True, + shard_count = 20, deps = [ "//br/pkg/errors", "//br/pkg/metautil", diff --git a/ddl/concurrentddltest/BUILD.bazel b/ddl/concurrentddltest/BUILD.bazel index b70619f27da1a..d5acc141896c5 100644 --- a/ddl/concurrentddltest/BUILD.bazel +++ b/ddl/concurrentddltest/BUILD.bazel @@ -9,6 +9,7 @@ go_test( ], flaky = True, race = "on", + shard_count = 2, deps = [ "//config", "//ddl", diff --git a/ddl/metadatalocktest/mdl_test.go b/ddl/metadatalocktest/mdl_test.go index 6f4a0012cdfff..64bdf77d55707 100644 --- a/ddl/metadatalocktest/mdl_test.go +++ b/ddl/metadatalocktest/mdl_test.go @@ -1105,3 +1105,16 @@ func TestMDLRenameTable(t *testing.T) { tk.MustGetErrCode("select * from test2.t1;", mysql.ErrNoSuchTable) tk.MustExec("commit") } + +func TestMDLPrepareFail(t *testing.T) { + store := testkit.CreateMockStore(t) + + tk := testkit.NewTestKit(t, store) + tk2 := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("create table t(a int);") + _, _, _, err := tk.Session().PrepareStmt("select b from t") + require.Error(t, err) + + tk2.MustExec("alter table test.t add column c int") +} diff --git a/executor/fktest/BUILD.bazel b/executor/fktest/BUILD.bazel index dbdae1843edaf..86f7a48d28bb6 100644 --- a/executor/fktest/BUILD.bazel +++ b/executor/fktest/BUILD.bazel @@ -8,6 +8,7 @@ go_test( "main_test.go", ], flaky = True, + shard_count = 20, deps = [ "//config", "//executor", diff --git a/session/session.go b/session/session.go index 824384367f33b..a6f5bf4cad0f1 100644 --- a/session/session.go +++ b/session/session.go @@ -2450,7 +2450,6 @@ func (s *session) PrepareStmt(sql string) (stmtID uint32, paramCount int, fields } ctx := context.Background() - inTxn := s.GetSessionVars().InTxn() // NewPrepareExec may need startTS to build the executor, for example prepare statement has subquery in int. // So we have to call PrepareTxnCtx here. if err = s.PrepareTxnCtx(ctx); err != nil { @@ -2467,13 +2466,12 @@ func (s *session) PrepareStmt(sql string) (stmtID uint32, paramCount int, fields } prepareExec := executor.NewPrepareExec(s, sql) err = prepareExec.Next(ctx, nil) + // Rollback even if err is nil. + s.rollbackOnError(ctx) + if err != nil { return } - if !inTxn { - // We could start a transaction to build the prepare executor before, we should rollback it here. - s.RollbackTxn(ctx) - } return prepareExec.ID, prepareExec.ParamCount, prepareExec.Fields, nil }