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

ddl: forbid disabling concurrent DDL if MDL is enabled #39301

Merged
merged 7 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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")
Benjamin2037 marked this conversation as resolved.
Show resolved Hide resolved
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")
Benjamin2037 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a place to collect all error msg?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For standard error with the error code, yes. For these misc errors, no.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to have an error code for each TiDB specific feature.

}

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")
Benjamin2037 marked this conversation as resolved.
Show resolved Hide resolved
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