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 concurrent access to do.infoHandle has a data race error #8287

Merged
merged 14 commits into from
Nov 27, 2018
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