Skip to content

Commit

Permalink
ddl: fix genGlobalID function repetition RunInNewTxn (#7130)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscoxll authored and tiancaiamao committed Jul 23, 2018
1 parent f59f696 commit ade23a0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
20 changes: 10 additions & 10 deletions ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,6 @@ func (dc *ddlCtx) isOwner() bool {
return isOwner
}

func (dc *ddlCtx) genGlobalID() (int64, error) {
var globalID int64
err := kv.RunInNewTxn(dc.store, true, func(txn kv.Transaction) error {
var err error
globalID, err = meta.NewMeta(txn).GenGlobalID()
return errors.Trace(err)
})
return globalID, errors.Trace(err)
}

// RegisterEventCh registers passed channel for ddl Event.
func (d *ddl) RegisterEventCh(ch chan<- *util.Event) {
d.ddlEventCh = ch
Expand Down Expand Up @@ -421,6 +411,16 @@ func (d *ddl) GetInformationSchema(ctx sessionctx.Context) infoschema.InfoSchema
return d.mu.interceptor.OnGetInfoSchema(ctx, is)
}

func (d *ddl) genGlobalID() (int64, error) {
var globalID int64
err := kv.RunInNewTxn(d.store, true, func(txn kv.Transaction) error {
var err error
globalID, err = meta.NewMeta(txn).GenGlobalID()
return errors.Trace(err)
})
return globalID, errors.Trace(err)
}

// generalWorker returns the first worker. The ddl structure has only one worker before we implement the parallel worker.
// It's used for testing.
func (d *ddl) generalWorker() *worker {
Expand Down
2 changes: 1 addition & 1 deletion ddl/ddl_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func (w *worker) runDDLJob(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64,
case model.ActionDropForeignKey:
ver, err = onDropForeignKey(t, job)
case model.ActionTruncateTable:
ver, err = onTruncateTable(d, t, job)
ver, err = onTruncateTable(t, job)
case model.ActionRebaseAutoID:
ver, err = onRebaseAutoID(d.store, t, job)
case model.ActionRenameTable:
Expand Down
4 changes: 2 additions & 2 deletions ddl/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func getTableInfo(t *meta.Meta, job *model.Job, schemaID int64) (*model.TableInf
// onTruncateTable delete old table meta, and creates a new table identical to old table except for table ID.
// As all the old data is encoded with old table ID, it can not be accessed any more.
// A background job will be created to delete old data.
func onTruncateTable(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error) {
func onTruncateTable(t *meta.Meta, job *model.Job) (ver int64, _ error) {
schemaID := job.SchemaID
tableID := job.TableID
var newTableID int64
Expand All @@ -220,7 +220,7 @@ func onTruncateTable(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ erro
oldPartitionIDs = getPartitionIDs(tblInfo)
for _, def := range tblInfo.Partition.Definitions {
var pid int64
pid, err = d.genGlobalID()
pid, err = t.GenGlobalID()
if err != nil {
job.State = model.JobStateCancelled
return ver, errors.Trace(err)
Expand Down

0 comments on commit ade23a0

Please sign in to comment.