diff --git a/ddl/concurrentddltest/BUILD.bazel b/ddl/concurrentddltest/BUILD.bazel index 81b86bf3f3856..b70619f27da1a 100644 --- a/ddl/concurrentddltest/BUILD.bazel +++ b/ddl/concurrentddltest/BUILD.bazel @@ -14,6 +14,7 @@ go_test( "//ddl", "//kv", "//meta", + "//sessionctx/variable", "//testkit", "//testkit/testsetup", "//util", diff --git a/ddl/concurrentddltest/switch_test.go b/ddl/concurrentddltest/switch_test.go index d487859260eb2..6cd26811008e6 100644 --- a/ddl/concurrentddltest/switch_test.go +++ b/ddl/concurrentddltest/switch_test.go @@ -23,6 +23,7 @@ import ( "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta" + "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/testkit" "github.com/pingcap/tidb/util" "github.com/stretchr/testify/require" @@ -134,3 +135,15 @@ func TestConcurrentDDLSwitch(t *testing.T) { } } } + +func TestConcurrentDDLSwitchWithMDL(t *testing.T) { + if !variable.EnableConcurrentDDL.Load() { + t.Skip("skip test if concurrent DDL is disabled") + } + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustGetErrMsg("set global tidb_enable_concurrent_ddl=off", "can not disable concurrent ddl when metadata lock is enabled") + tk.MustExec("set global tidb_enable_metadata_lock=0") + tk.MustExec("set global tidb_enable_concurrent_ddl=off") + tk.MustExec("create table test.t(a int)") +} diff --git a/ddl/ddl.go b/ddl/ddl.go index bb92f752b53d5..52a5b0480c42a 100644 --- a/ddl/ddl.go +++ b/ddl/ddl.go @@ -1198,6 +1198,10 @@ func (d *ddl) SwitchConcurrentDDL(toConcurrentDDL bool) error { }) } + if variable.EnableMDL.Load() && !toConcurrentDDL { + return errors.New("can not disable concurrent ddl when metadata lock is enabled") + } + ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) defer cancel() d.waiting.Store(true) diff --git a/expression/integration_serial_test.go b/expression/integration_serial_test.go index a497d9ef54600..77574b4e309a2 100644 --- a/expression/integration_serial_test.go +++ b/expression/integration_serial_test.go @@ -3766,6 +3766,7 @@ func TestSetVariables(t *testing.T) { tk.MustExec("set @@global.tidb_enable_concurrent_ddl=1") tk.MustQuery("select @@global.tidb_enable_concurrent_ddl").Check(testkit.Rows("1")) require.True(t, variable.EnableConcurrentDDL.Load()) + tk.MustExec("set @@global.tidb_enable_metadata_lock=0") tk.MustExec("set @@global.tidb_enable_concurrent_ddl=0") tk.MustQuery("select @@global.tidb_enable_concurrent_ddl").Check(testkit.Rows("0")) require.False(t, variable.EnableConcurrentDDL.Load())