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: fix race in table lock config #10848

Merged
merged 4 commits into from
Jun 20, 2019
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
27 changes: 4 additions & 23 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func setUpSuite(s *testDBSuite, c *C) {
s.schemaName = "test_db"
s.autoIDStep = autoid.GetStep()
ddl.WaitTimeWhenErrorOccured = 0
// Test for table lock.
config.GetGlobalConfig().EnableTableLock = true

s.cluster = mocktikv.NewCluster()
mocktikv.BootstrapWithSingleStore(s.cluster)
Expand Down Expand Up @@ -2776,18 +2778,6 @@ func (s *testDBSuite2) TestLockTables(c *C) {
tk.MustExec("create table t1 (a int)")
tk.MustExec("create table t2 (a int)")

// recover table lock config.
originValue := config.GetGlobalConfig().EnableTableLock
defer func() {
config.GetGlobalConfig().EnableTableLock = originValue
}()

// Test for enable table lock config.
config.GetGlobalConfig().EnableTableLock = false
tk.MustExec("lock tables t1 write")
checkTableLock(c, tk.Se, "test", "t1", model.TableLockNone)
config.GetGlobalConfig().EnableTableLock = true

// Test lock 1 table.
tk.MustExec("lock tables t1 write")
checkTableLock(c, tk.Se, "test", "t1", model.TableLockWrite)
Expand Down Expand Up @@ -2963,7 +2953,7 @@ func (s *testDBSuite2) TestLockTables(c *C) {
}

// TestConcurrentLockTables test concurrent lock/unlock tables.
func (s *testDBSuite2) TestConcurrentLockTables(c *C) {
func (s *testDBSuite4) TestConcurrentLockTables(c *C) {
if israce.RaceEnabled {
c.Skip("skip race test")
}
Expand All @@ -2976,15 +2966,6 @@ func (s *testDBSuite2) TestConcurrentLockTables(c *C) {
tk.MustExec("create table t1 (a int)")
tk2.MustExec("use test")

// recover table lock config.
originValue := config.GetGlobalConfig().EnableTableLock
defer func() {
config.GetGlobalConfig().EnableTableLock = originValue
}()

// Test for enable table lock config.
config.GetGlobalConfig().EnableTableLock = true

// Test concurrent lock tables read.
sql1 := "lock tables t1 read"
sql2 := "lock tables t1 read"
Expand Down Expand Up @@ -3017,7 +2998,7 @@ func (s *testDBSuite2) TestConcurrentLockTables(c *C) {
tk2.MustExec("unlock tables")
}

func (s *testDBSuite2) testParallelExecSQL(c *C, sql1, sql2 string, se1, se2 session.Session, f checkRet) {
func (s *testDBSuite4) testParallelExecSQL(c *C, sql1, sql2 string, se1, se2 session.Session, f checkRet) {
callback := &ddl.TestDDLCallback{}
times := 0
callback.OnJobRunBeforeExported = func(job *model.Job) {
Expand Down
19 changes: 19 additions & 0 deletions ddl/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/pingcap/failpoint"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/infoschema"
Expand Down Expand Up @@ -410,3 +411,21 @@ func (s *testSerialSuite) TestCanceledJobTakeTime(c *C) {
sub := time.Since(startTime)
c.Assert(sub, Less, ddl.WaitTimeWhenErrorOccured)
}

func (s *testSerialSuite) TestTableLocksEnable(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1")
defer tk.MustExec("drop table if exists t1")
tk.MustExec("create table t1 (a int)")
// recover table lock config.
originValue := config.GetGlobalConfig().EnableTableLock
defer func() {
config.GetGlobalConfig().EnableTableLock = originValue
}()

// Test for enable table lock config.
config.GetGlobalConfig().EnableTableLock = false
tk.MustExec("lock tables t1 write")
checkTableLock(c, tk.Se, "test", "t1", model.TableLockNone)
}