Skip to content

Commit

Permalink
fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
bb7133 committed Dec 24, 2018
1 parent e0e531d commit 3b40c98
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 57 deletions.
8 changes: 6 additions & 2 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,11 @@ func (s *testDBSuite) TestCancelCreateTable(c *C) {
checkErr = errors.Trace(err)
return
}
errs, err := admin.CancelJobs(hookCtx.Txn(true), jobIDs)
txn, err := hookCtx.Txn(true)
if err != nil {
checkErr = errors.Trace(err)
}
errs, err := admin.CancelJobs(txn, jobIDs)
if err != nil {
checkErr = errors.Trace(err)
return
Expand All @@ -566,7 +570,7 @@ func (s *testDBSuite) TestCancelCreateTable(c *C) {
checkErr = errors.Trace(errs[0])
return
}
checkErr = hookCtx.Txn(true).Commit(context.Background())
checkErr = txn.Commit(context.Background())
}
}
originHook := s.dom.DDL().GetHook()
Expand Down
1 change: 0 additions & 1 deletion ddl/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func onCreateTable(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, err erro
// TODO: Add restrictions to this operation.
go splitTableRegion(d.store, tbInfo.ID)
}
ver, err = updateVersionAndTableInfo(t, job, tbInfo, originalState != tbInfo.State)
case model.StateWriteReorganization:
// reorganization -> public (insert data before we make the table public)
err = doCreateTableInsert(d, t, job, tbInfo, snapshotTS)
Expand Down
36 changes: 0 additions & 36 deletions ddl/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,42 +124,6 @@ func testCreateTable(c *C, ctx sessionctx.Context, d *ddl, dbInfo *model.DBInfo,
return job
}

func testCreateTableWithSelect(c *C, ctx sessionctx.Context, d *ddl, dbInfo *model.DBInfo, tblInfo *model.TableInfo) *model.Job {
job := &model.Job{
SchemaID: dbInfo.ID,
TableID: tblInfo.ID,
Type: model.ActionCreateTable,
BinlogInfo: &model.HistoryInfo{},
Args: []interface{}{tblInfo, true /*withSelect*/},
}
err := d.doDDLJob(ctx, job)
c.Assert(err, IsNil)

v := getSchemaVer(c, ctx)
tblInfo.State = model.StatePublic
checkHistoryJobArgs(c, ctx, job.ID, &historyJobArgs{ver: v, tbl: tblInfo})
tblInfo.State = model.StateNone
return job
}

func testRevealTable(c *C, ctx sessionctx.Context, d *ddl, dbInfo *model.DBInfo, tblInfo *model.TableInfo) *model.Job {
job := &model.Job{
SchemaID: dbInfo.ID,
TableID: tblInfo.ID,
Type: model.ActionRevealTable,
BinlogInfo: &model.HistoryInfo{},
Args: []interface{}{tblInfo},
}
err := d.doDDLJob(ctx, job)
c.Assert(err, IsNil)

v := getSchemaVer(c, ctx)
tblInfo.State = model.StatePublic
checkHistoryJobArgs(c, ctx, job.ID, &historyJobArgs{ver: v, tbl: tblInfo})
tblInfo.State = model.StateNone
return job
}

func testCreateView(c *C, ctx sessionctx.Context, d *ddl, dbInfo *model.DBInfo, tblInfo *model.TableInfo) *model.Job {
job := &model.Job{
SchemaID: dbInfo.ID,
Expand Down
9 changes: 7 additions & 2 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,12 @@ func (b *executorBuilder) buildCreateTableInsert(v *plannercore.DDL, tableID int
}
selectExec := b.build(v.InsertPlan.SelectPlan)

m := meta.NewMeta(b.ctx.Txn(true))
txn, err := b.ctx.Txn(true)
if err != nil {
b.err = errors.Trace(err)
return nil
}
m := meta.NewMeta(txn)
dbInfo, ok := b.is.SchemaByName(stmt.Table.Schema)
if !ok {
b.err = infoschema.ErrDatabaseNotExists.GenWithStackByArgs(stmt.Table.Schema.L)
Expand All @@ -709,7 +714,7 @@ func (b *executorBuilder) buildCreateTableInsert(v *plannercore.DDL, tableID int
}

// We have to create an allocator here, which is not the one created by InfoSchema, but it should be fine.
alloc := autoid.NewAllocator(b.ctx.GetStore(), tbInfo.GetDBID(dbInfo.ID))
alloc := autoid.NewAllocator(b.ctx.GetStore(), tbInfo.GetDBID(dbInfo.ID), tbInfo.IsAutoIncColUnsigned())
tbl, err := tables.TableFromMeta(alloc, tbInfo)
if err != nil {
b.err = errors.Trace(err)
Expand Down
17 changes: 5 additions & 12 deletions executor/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ func (e *DDLExec) toErr(err error) error {

// Open implements the Executor Open interface.
func (e *DDLExec) Open(context.Context) error {
e.originalStartTS = e.ctx.Txn(true).StartTS()
txn, err := e.ctx.Txn(true)
if err != nil {
return err
}
e.originalStartTS = txn.StartTS()
return nil
}

Expand All @@ -94,17 +98,6 @@ func (e *DDLExec) Next(ctx context.Context, chk *chunk.Chunk) (err error) {
case *ast.CreateDatabaseStmt:
err = e.executeCreateDatabase(x)
case *ast.CreateTableStmt:
var tableID int64
tableID, err = e.executeCreateTable(x)
if err != nil {
return errors.Trace(e.toErr(err))
}
if tableID != 0 {
err = e.executeSelectInsert(ctx, chk, x, tableID)
if err != nil {
return errors.Trace(e.toErr(err))
}
}
err = e.executeCreateTable(x)
case *ast.CreateViewStmt:
err = e.executeCreateView(x)
Expand Down
1 change: 0 additions & 1 deletion executor/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/ast"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/meta/autoid"
Expand Down
6 changes: 3 additions & 3 deletions planner/core/preprocess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ func (s *testValidatorSuite) TestValidator(c *C) {
{"select * from (select 1 ) a , (select 2) b, (select * from (select 3) a join (select 4) b) c;", false, nil},

{"CREATE VIEW V (a,b,c) AS SELECT 1,1,3;", false, nil},
{"CREATE TABLE t SELECT * FROM u FOR UPDATE;", false, errors.New("[planner:1746]Can't update table 'u' while 't' is being created.")},
{"CREATE TABLE t SELECT * FROM u FOR UPDATE UNION SELECT * FROM v;", false, errors.New("[planner:1746]Can't update table 'u' while 't' is being created.")},
{"CREATE TABLE t SELECT * FROM u FOR UPDATE;", false, core.ErrCantUpdateTableInCreateTableSelect.GenWithStackByArgs("u", "t")},
{"CREATE TABLE t SELECT * FROM u FOR UPDATE UNION SELECT * FROM v;", false, core.ErrCantUpdateTableInCreateTableSelect.GenWithStackByArgs("u", "t")},
{"CREATE TABLE t SELECT u.a FROM u JOIN v ON u.a = v.a FOR UPDATE;", false, core.ErrCantUpdateTableInCreateTableSelect},
{"CREATE TABLE t SELECT a FROM (SELECT 1 AS a, 2 AS b) AS temp FOR UPDATE;", false, errors.New("[planner:1746]Can't update table 'temp' while 't' is being created.")},
{"CREATE TABLE t SELECT a FROM (SELECT 1 AS a, 2 AS b) AS temp FOR UPDATE;", false, core.ErrCantUpdateTableInCreateTableSelect.GenWithStackByArgs("temp", "t")},
{"CREATE TABLE t SELECT a FROM (SELECT 1 AS a, 2 AS b FOR UPDATE) AS temp;", false, nil},
}

Expand Down

0 comments on commit 3b40c98

Please sign in to comment.