Skip to content

Commit

Permalink
ddl: forbid disabling concurrent DDL if MDL is enabled (#39301)
Browse files Browse the repository at this point in the history
close #39131
  • Loading branch information
wjhuang2016 authored Nov 22, 2022
1 parent d5e9ef0 commit 75efe68
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions ddl/concurrentddltest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ go_test(
"//ddl",
"//kv",
"//meta",
"//sessionctx/variable",
"//testkit",
"//testkit/testsetup",
"//util",
Expand Down
13 changes: 13 additions & 0 deletions ddl/concurrentddltest/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)")
}
4 changes: 4 additions & 0 deletions ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions expression/integration_serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 75efe68

Please sign in to comment.