Skip to content

Commit

Permalink
address crazycs520's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bb7133 committed Dec 6, 2018
1 parent 27ff953 commit ade79af
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ddl/ddl_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func (w *worker) runDDLJob(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64,
case model.ActionDropSchema:
ver, err = onDropSchema(t, job)
case model.ActionCreateTable:
ver, err = onCreateTable(d, w, t, job)
ver, err = onCreateTable(d, t, job)
case model.ActionDropTable:
ver, err = onDropTable(t, job)
case model.ActionDropTablePartition:
Expand Down
18 changes: 11 additions & 7 deletions ddl/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ package ddl
import (
"context"
"fmt"
"strconv"
"strings"

"github.com/pingcap/errors"
"github.com/pingcap/parser/model"
"github.com/pingcap/tidb/ddl/util"
Expand All @@ -27,11 +30,9 @@ import (
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/util/sqlexec"
log "github.com/sirupsen/logrus"
"strconv"
"strings"
)

func onCreateTable(d *ddlCtx, w *worker, t *meta.Meta, job *model.Job) (ver int64, err error) {
func onCreateTable(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, err error) {
schemaID := job.SchemaID
tbInfo := &model.TableInfo{}
var withSelect bool // if this is a 'create table ... select' job
Expand All @@ -55,14 +56,20 @@ func onCreateTable(d *ddlCtx, w *worker, t *meta.Meta, job *model.Job) (ver int6

if withSelect {
tbInfo.State = model.StateWriteReorganization
job.SchemaState = model.StateWriteReorganization
} else {
tbInfo.State = model.StatePublic
job.SchemaState = model.StatePublic
}

err = t.CreateTable(schemaID, tbInfo)
if err != nil {
return ver, errors.Trace(err)
}
if EnableSplitTableRegion {
// TODO: Add restrictions to this operation.
go splitTableRegion(d.store, tbInfo.ID)
}
case model.StateWriteReorganization:
// reorganization -> public (insert data before we make the table public)
err = doCreateTableInsert(d, t, job, tbInfo, snapshotTS)
Expand All @@ -72,14 +79,11 @@ func onCreateTable(d *ddlCtx, w *worker, t *meta.Meta, job *model.Job) (ver int6
}

tbInfo.State = model.StatePublic
job.SchemaState = model.StatePublic
default:
return ver, ErrInvalidTableState.GenWithStack("invalid table state %v", tbInfo.State)
}
tbInfo.UpdateTS = t.StartTS
if EnableSplitTableRegion {
// TODO: Add restrictions to this operation.
go splitTableRegion(d.store, tbInfo.ID)
}
ver, err = updateVersionAndTableInfo(t, job, tbInfo, originalState != tbInfo.State)
if err != nil {
job.State = model.JobStateCancelled
Expand Down
1 change: 1 addition & 0 deletions ddl/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"context"
"encoding/hex"
"fmt"

"github.com/pingcap/errors"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/kv"
Expand Down
6 changes: 3 additions & 3 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ import (
"bytes"
"context"
"fmt"
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/meta/autoid"
"github.com/pingcap/tidb/table/tables"
"math"
"sort"
"strings"
Expand All @@ -39,12 +36,15 @@ import (
"github.com/pingcap/tidb/expression/aggregation"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/meta/autoid"
"github.com/pingcap/tidb/metrics"
plannercore "github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/statistics"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/admin"
"github.com/pingcap/tidb/util/chunk"
Expand Down
3 changes: 2 additions & 1 deletion executor/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package executor_test
import (
"context"
"fmt"
"github.com/pingcap/tidb/util/testutil"
"math"
"strings"
"time"
Expand All @@ -33,6 +32,8 @@ import (
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/testkit"
"github.com/pingcap/tidb/util/testutil"
"golang.org/x/net/context"
)

func (s *testSuite) TestTruncateTable(c *C) {
Expand Down

0 comments on commit ade79af

Please sign in to comment.