Skip to content

Commit

Permalink
ddl: a better way to fix data race against #10900 (#11121)
Browse files Browse the repository at this point in the history
  • Loading branch information
SunRunAway authored and coocood committed Jul 8, 2019
1 parent c1bd3b1 commit fe0ed73
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ func hasRootPrivilege() bool {
}

// TableLockEnabled uses to check whether enabled the table lock feature.
var TableLockEnabled = func() bool {
func TableLockEnabled() bool {
return GetGlobalConfig().EnableTableLock
}

Expand Down
13 changes: 4 additions & 9 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ type testDBSuite struct {
autoIDStep int64
}

var tableLockEnabled uint32 = 0

func init() {
config.TableLockEnabled = func() bool {
return atomic.LoadUint32(&tableLockEnabled) > 0
}
}

func setUpSuite(s *testDBSuite, c *C) {
var err error

Expand All @@ -99,7 +91,10 @@ func setUpSuite(s *testDBSuite, c *C) {
s.autoIDStep = autoid.GetStep()
ddl.WaitTimeWhenErrorOccured = 0
// Test for table lock.
atomic.StoreUint32(&tableLockEnabled, 1)
cfg := config.GetGlobalConfig()
newCfg := *cfg
newCfg.EnableTableLock = true
config.StoreGlobalConfig(&newCfg)

s.cluster = mocktikv.NewCluster()
mocktikv.BootstrapWithSingleStore(s.cluster)
Expand Down
14 changes: 8 additions & 6 deletions ddl/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import (
"fmt"
"strings"
"sync"
"sync/atomic"
"time"

. "github.com/pingcap/check"
"github.com/pingcap/errors"
"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 @@ -418,14 +418,16 @@ func (s *testSerialSuite) TestTableLocksEnable(c *C) {
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 := atomic.LoadUint32(&tableLockEnabled)

// Test for enable table lock config.
cfg := config.GetGlobalConfig()
newCfg := *cfg
newCfg.EnableTableLock = false
config.StoreGlobalConfig(&newCfg)
defer func() {
atomic.StoreUint32(&tableLockEnabled, originValue)
config.StoreGlobalConfig(cfg)
}()

// Test for enable table lock config.
atomic.StoreUint32(&tableLockEnabled, 0)
tk.MustExec("lock tables t1 write")
checkTableLock(c, tk.Se, "test", "t1", model.TableLockNone)
}

0 comments on commit fe0ed73

Please sign in to comment.