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 add partition problem #8902

Merged
merged 5 commits into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions ddl/db_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,24 @@ func (s *testStateChangeSuite) TestParallelAlterModifyColumn(c *C) {
s.testControlParallelExecSQL(c, sql, sql, f)
}

func (s *testStateChangeSuite) TestParallelAlterAddPartition(c *C) {
sql1 := `alter table t_part_parallel add partition (
partition p2 values less than (30)
);`
f := func(c *C, err1, err2 error) {
var oneErr error
if (err1 != nil && err2 == nil) || (err1 == nil && err2 != nil) {
if err1 != nil {
oneErr = err1
} else {
oneErr = err2
}
}
c.Assert(oneErr.Error(), Equals, "[ddl:1493]VALUES LESS THAN value must be strictly increasing for each partition")
}
s.testControlParallelExecSQL(c, sql1, sql1, f)
}

func (s *testStateChangeSuite) TestParallelChangeColumnName(c *C) {
sql1 := "ALTER TABLE t CHANGE a aa int;"
sql2 := "ALTER TABLE t CHANGE b aa int;"
Expand Down Expand Up @@ -659,6 +677,16 @@ func (s *testStateChangeSuite) testControlParallelExecSQL(c *C, sql1, sql2 strin
c.Assert(err, IsNil)
defer s.se.Execute(context.Background(), "drop table t")

_, err = s.se.Execute(context.Background(), "set @@tidb_enable_table_partition = 1")
c.Assert(err, IsNil)
_, err = s.se.Execute(context.Background(), "drop database if exists t_part_parallel")
c.Assert(err, IsNil)
_, err = s.se.Execute(context.Background(), `create table t_part_parallel (a int key)
partition by range(a) (
partition p0 values less than (10),
partition p1 values less than (20)
);`)

callback := &ddl.TestDDLCallback{}
times := 0
callback.OnJobUpdatedExported = func(job *model.Job) {
Expand Down
7 changes: 7 additions & 0 deletions ddl/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,13 @@ func onAddTablePartition(t *meta.Meta, job *model.Job) (ver int64, _ error) {
job.State = model.JobStateCancelled
return ver, errors.Trace(err)
}

err = checkAddPartitionValue(tblInfo, partInfo)
if err != nil {
job.State = model.JobStateCancelled
return ver, errors.Trace(err)
}

err = checkPartitionNameUnique(tblInfo, partInfo)
if err != nil {
job.State = model.JobStateCancelled
Expand Down