Skip to content

Commit

Permalink
ddl: fix a data race (#10900)
Browse files Browse the repository at this point in the history
  • Loading branch information
SunRunAway authored and tiancaiamao committed Jun 21, 2019
1 parent 697ba85 commit 5cd77cd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ func hasRootPrivilege() bool {
}

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

Expand Down
10 changes: 9 additions & 1 deletion ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ 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 @@ -90,7 +98,7 @@ func setUpSuite(s *testDBSuite, c *C) {
s.autoIDStep = autoid.GetStep()
ddl.WaitTimeWhenErrorOccured = 0
// Test for table lock.
config.GetGlobalConfig().EnableTableLock = true
atomic.StoreUint32(&tableLockEnabled, 1)

s.cluster = mocktikv.NewCluster()
mocktikv.BootstrapWithSingleStore(s.cluster)
Expand Down
8 changes: 4 additions & 4 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 @@ -419,13 +419,13 @@ func (s *testSerialSuite) TestTableLocksEnable(c *C) {
defer tk.MustExec("drop table if exists t1")
tk.MustExec("create table t1 (a int)")
// recover table lock config.
originValue := config.GetGlobalConfig().EnableTableLock
originValue := atomic.LoadUint32(&tableLockEnabled)
defer func() {
config.GetGlobalConfig().EnableTableLock = originValue
atomic.StoreUint32(&tableLockEnabled, originValue)
}()

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

0 comments on commit 5cd77cd

Please sign in to comment.