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 parallel create table if not exists #6286

Merged
merged 10 commits into from
Apr 16, 2018
Merged

ddl: fix parallel create table if not exists #6286

merged 10 commits into from
Apr 16, 2018

Conversation

winkyao
Copy link
Contributor

@winkyao winkyao commented Apr 14, 2018

In onCreateTable, we will check if table is exists, but we use the if not exists option only in CreateTable. It will cause unexpected [schema:1050]Table 'Xxx' already exists

@winkyao winkyao added type/bugfix This PR fixes a bug. DDL labels Apr 14, 2018
@@ -433,7 +433,6 @@ func (s *testStateChangeSuite) TestShowIndex(c *C) {
}

func (s *testStateChangeSuite) TestParallelDDL(c *C) {
defer testleak.AfterTest(c)()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this?

Copy link
Contributor Author

@winkyao winkyao Apr 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's called in testStateChangeSuite.TeareDownSuite, call testleak.AfterTest(c) here make test unstable.

@@ -501,3 +499,85 @@ func (s *testStateChangeSuite) TestParallelDDL(c *C) {
callback = &ddl.TestDDLCallback{}
d.SetHook(callback)
}

func (s *testStateChangeSuite) TestCreateIfNotExists(c *C) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some comments for the test case.

d.SetHook(callback)
}

func (s *testStateChangeSuite) TestCreateIfNotExists1(c *C) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -501,3 +499,87 @@ func (s *testStateChangeSuite) TestParallelDDL(c *C) {
callback = &ddl.TestDDLCallback{}
d.SetHook(callback)
}

// TestCreateIfNotExists parallel exec create table if not exists xxx. No error returns is expected.
func (s *testStateChangeSuite) TestCreateIfNotExists(c *C) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/TestCreateIfNotExists/TestCreateTableIfNotExists

}

// TestCreateIfNotExists parallel exec create database if not exists xxx. No error returns is expected.
func (s *testStateChangeSuite) TestCreateIfNotExists1(c *C) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/TestCreateIfNotExists1/TestCreateDBIfNotExists

wg.Add(2)
go func() {
defer wg.Done()
_, err2 = se.Execute(context.Background(), "create table if not exists test_not_exists(a int);")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is similar to the next test, only the SQL is different. And we will add some test like this. Could this be extracted into a function?

@winkyao
Copy link
Contributor Author

winkyao commented Apr 16, 2018

@zimulala PTAL

callback := &ddl.TestDDLCallback{}
once := sync.Once{}
callback.OnJobUpdatedExported = func(job *model.Job) {
// sleep a while, let other job enque.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we confirm that the other job is in the queue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this PR, the added test failed stably.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this test code is indeed unstable.

@shenli shenli added the priority/release-blocker This issue blocks a release. Please solve it ASAP. label Apr 16, 2018
ddl/ddl_api.go Outdated
@@ -856,6 +856,11 @@ func (d *ddl) CreateTable(ctx sessionctx.Context, s *ast.CreateTableStmt) (err e
err = d.handleAutoIncID(tbInfo, schema.ID)
}
}

// table exists, but if_not_exits flags is true, so we ignore this error.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if_not_exists

@winkyao
Copy link
Contributor Author

winkyao commented Apr 16, 2018

@zimulala @lamxTyler PTAL

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@alivxxx alivxxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alivxxx
Copy link
Contributor

alivxxx commented Apr 16, 2018

/run-all-tests

@zimulala zimulala added the status/LGT2 Indicates that a PR has LGTM 2. label Apr 16, 2018
@zimulala zimulala merged commit ab7d85b into pingcap:master Apr 16, 2018
@winkyao winkyao deleted the correct_ifnotexists_check branch April 16, 2018 14:39
@you06 you06 added the sig/sql-infra SIG: SQL Infra label Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/release-blocker This issue blocks a release. Please solve it ASAP. sig/sql-infra SIG: SQL Infra status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants