Skip to content

Commit

Permalink
ddl: fix concurrent access to do.infoHandle has a data race error (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscoxll authored Nov 27, 2018
1 parent e2e8d67 commit e5dc251
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
14 changes: 8 additions & 6 deletions ddl/fail_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ func (s *testFailDBSuite) TestHalfwayCancelOperations(c *C) {
c.Assert(row.Len(), Equals, 1)
c.Assert(row.GetInt64(0), DeepEquals, int64(1))
c.Assert(rs[0].Close(), IsNil)
// Reload schema.
s.dom.ResetHandle(s.store)
// Execute ddl statement reload schema.
_, err = s.se.Execute(context.Background(), "alter table t comment 'test1'")
c.Assert(err, IsNil)
err = s.dom.DDL().(ddl.DDLForTest).GetHook().OnChanged(nil)
c.Assert(err, IsNil)
s.se, err = session.CreateSession4Test(s.store)
Expand All @@ -105,8 +106,8 @@ func (s *testFailDBSuite) TestHalfwayCancelOperations(c *C) {
c.Assert(err, IsNil)

// test for renaming table
gofail.Enable("github.com/pingcap/tidb/ddl/errRenameTable", `return(true)`)
defer gofail.Disable("github.com/pingcap/tidb/ddl/errRenameTable")
gofail.Enable("github.com/pingcap/tidb/ddl/renameTableErr", `return(true)`)
defer gofail.Disable("github.com/pingcap/tidb/ddl/renameTableErr")
_, err = s.se.Execute(context.Background(), "create table tx(a int)")
c.Assert(err, IsNil)
_, err = s.se.Execute(context.Background(), "insert into tx values(1)")
Expand All @@ -124,8 +125,9 @@ func (s *testFailDBSuite) TestHalfwayCancelOperations(c *C) {
c.Assert(row.Len(), Equals, 1)
c.Assert(row.GetInt64(0), DeepEquals, int64(1))
c.Assert(rs[0].Close(), IsNil)
// Reload schema.
s.dom.ResetHandle(s.store)
// Execute ddl statement reload schema.
_, err = s.se.Execute(context.Background(), "alter table tx comment 'tx'")
c.Assert(err, IsNil)
err = s.dom.DDL().(ddl.DDLForTest).GetHook().OnChanged(nil)
c.Assert(err, IsNil)
s.se, err = session.CreateSession4Test(s.store)
Expand Down
5 changes: 0 additions & 5 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,6 @@ func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duratio
}
}

// ResetHandle resets the domain's infoschema handle. It is used for testing.
func (do *Domain) ResetHandle(store kv.Storage) {
do.infoHandle = infoschema.NewHandle(store)
}

// Init initializes a domain.
func (do *Domain) Init(ddlLease time.Duration, sysFactory func(*Domain) (pools.Resource, error)) error {
if ebd, ok := do.store.(EtcdBackend); ok {
Expand Down

0 comments on commit e5dc251

Please sign in to comment.