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: admin show ddl jobs output confusing with multiple jobs #24075

Closed
wants to merge 8 commits into from
2 changes: 1 addition & 1 deletion ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ func (s *testIntegrationSuite5) TestBackwardCompatibility(c *C) {
job.ID, err = t.GenGlobalID()
c.Assert(err, IsNil)
job.Version = 1
job.StartTS = txn.StartTS()
job.CreateTS = txn.StartTS()

// Simulate old TiDB init the add index job, old TiDB will not init the model.Job.ReorgMeta field,
// if we set job.SnapshotVer here, can simulate the behavior.
Expand Down
2 changes: 1 addition & 1 deletion ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5990,7 +5990,7 @@ func (s *testSerialDBSuite) TestDDLJobErrorCount(c *C) {
job.ID, err = t.GenGlobalID()
c.Assert(err, IsNil)
job.Version = 1
job.StartTS = txn.StartTS()
job.CreateTS = txn.StartTS()

err = t.EnQueueDDLJob(job)
c.Assert(err, IsNil)
Expand Down
3 changes: 2 additions & 1 deletion ddl/ddl_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (d *ddl) addBatchDDLJobs(tasks []*limitJobTask) {
for i, task := range tasks {
job := task.job
job.Version = currentVersion
job.StartTS = txn.StartTS()
job.CreateTS = txn.StartTS()
job.ID = ids[i]
if err = buildJobDependence(t, job); err != nil {
return errors.Trace(err)
Expand Down Expand Up @@ -684,6 +684,7 @@ func (w *worker) runDDLJob(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64,
defer func() {
metrics.DDLWorkerHistogram.WithLabelValues(metrics.WorkerRunDDLJob, job.Type.String(), metrics.RetLabel(err)).Observe(time.Since(timeStart).Seconds())
}()
job.StartTS = t.StartTS
if job.IsFinished() {
return
}
Expand Down
2 changes: 1 addition & 1 deletion ddl/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (d *ddl) Stats(vars *variable.SessionVars) (map[string]interface{}, error)
job := ddlInfo.Jobs[0]
m[ddlJobID] = job.ID
m[ddlJobAction] = job.Type.String()
m[ddlJobStartTS] = job.StartTS / 1e9 // unit: second
m[ddlJobStartTS] = job.CreateTS / 1e9 // unit: second
m[ddlJobState] = job.State.String()
m[ddlJobRows] = job.RowCount
if job.Error == nil {
Expand Down
2 changes: 1 addition & 1 deletion distsql/request_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (builder *RequestBuilder) SetKeyRanges(keyRanges []kv.KeyRange) *RequestBui
return builder
}

// SetStartTS sets "StartTS" for "kv.Request".
// SetStartTS sets "CreateTS" for "kv.Request".
func (builder *RequestBuilder) SetStartTS(startTS uint64) *RequestBuilder {
builder.Request.StartTs = startTS
return builder
Expand Down
14 changes: 7 additions & 7 deletions executor/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func (e *DDLExec) executeRecoverTable(s *ast.RecoverTableStmt) error {
SchemaID: job.SchemaID,
TableInfo: tblInfo,
DropJobID: job.ID,
SnapshotTS: job.StartTS,
SnapshotTS: job.CreateTS,
CurAutoIncID: autoIncID,
CurAutoRandID: autoRandID,
}
Expand All @@ -424,7 +424,7 @@ func (e *DDLExec) executeRecoverTable(s *ast.RecoverTableStmt) error {
func (e *DDLExec) getTableAutoIDsFromSnapshot(job *model.Job) (autoIncID, autoRandID int64, err error) {
// Get table original autoIDs before table drop.
dom := domain.GetDomain(e.ctx)
m, err := dom.GetSnapshotMeta(job.StartTS)
m, err := dom.GetSnapshotMeta(job.CreateTS)
if err != nil {
return 0, 0, err
}
Expand Down Expand Up @@ -452,13 +452,13 @@ func (e *DDLExec) getRecoverTableByJobID(s *ast.RecoverTableStmt, t *meta.Meta,
}

// Check GC safe point for getting snapshot infoSchema.
err = gcutil.ValidateSnapshot(e.ctx, job.StartTS)
err = gcutil.ValidateSnapshot(e.ctx, job.CreateTS)
if err != nil {
return nil, nil, err
}

// Get the snapshot infoSchema before drop table.
snapInfo, err := dom.GetSnapshotInfoSchema(job.StartTS)
snapInfo, err := dom.GetSnapshotInfoSchema(job.CreateTS)
if err != nil {
return nil, nil, err
}
Expand All @@ -478,15 +478,15 @@ func (e *DDLExec) getRecoverTableByJobID(s *ast.RecoverTableStmt, t *meta.Meta,
func GetDropOrTruncateTableInfoFromJobs(jobs []*model.Job, gcSafePoint uint64, dom *domain.Domain, fn func(*model.Job, *model.TableInfo) (bool, error)) (bool, error) {
for _, job := range jobs {
// Check GC safe point for getting snapshot infoSchema.
err := gcutil.ValidateSnapshotWithGCSafePoint(job.StartTS, gcSafePoint)
err := gcutil.ValidateSnapshotWithGCSafePoint(job.CreateTS, gcSafePoint)
if err != nil {
return false, err
}
if job.Type != model.ActionDropTable && job.Type != model.ActionTruncateTable {
continue
}

snapMeta, err := dom.GetSnapshotMeta(job.StartTS)
snapMeta, err := dom.GetSnapshotMeta(job.CreateTS)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -587,7 +587,7 @@ func (e *DDLExec) executeFlashbackTable(s *ast.FlashBackTableStmt) error {
SchemaID: job.SchemaID,
TableInfo: tblInfo,
DropJobID: job.ID,
SnapshotTS: job.StartTS,
SnapshotTS: job.CreateTS,
CurAutoIncID: autoIncID,
CurAutoRandID: autoRandID,
}
Expand Down
10 changes: 6 additions & 4 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ func (e *DDLJobRetriever) appendJobToChunk(req *chunk.Chunk, job *model.Job, che
tableName = getTableName(e.is, job.TableID)
}

createTime := ts2Time(job.CreateTS)
startTime := ts2Time(job.StartTS)
finishTime := ts2Time(finishTS)

Expand All @@ -492,13 +493,14 @@ func (e *DDLJobRetriever) appendJobToChunk(req *chunk.Chunk, job *model.Job, che
req.AppendInt64(5, job.SchemaID)
req.AppendInt64(6, job.TableID)
req.AppendInt64(7, job.RowCount)
req.AppendTime(8, startTime)
req.AppendTime(8, createTime)
req.AppendTime(9, startTime)
if finishTS > 0 {
req.AppendTime(9, finishTime)
req.AppendTime(10, finishTime)
} else {
req.AppendNull(9)
req.AppendNull(10)
}
req.AppendString(10, job.State.String())
req.AppendString(11, job.State.String())
}

func ts2Time(timestamp uint64) types.Time {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ require (
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0
sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67
)
replace github.com/pingcap/parser => ../parser

go 1.13
1 change: 1 addition & 0 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,7 @@ var tableDDLJobsCols = []columnInfo{
{name: "SCHEMA_ID", tp: mysql.TypeLonglong, size: 21},
{name: "TABLE_ID", tp: mysql.TypeLonglong, size: 21},
{name: "ROW_COUNT", tp: mysql.TypeLonglong, size: 21},
{name: "CREATE_TIME", tp: mysql.TypeDatetime, size: 19},
{name: "START_TIME", tp: mysql.TypeDatetime, size: 19},
{name: "END_TIME", tp: mysql.TypeDatetime, size: 19},
{name: "STATE", tp: mysql.TypeVarchar, size: 64},
Expand Down
3 changes: 2 additions & 1 deletion planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1944,7 +1944,7 @@ func buildCleanupIndexFields() (*expression.Schema, types.NameSlice) {
}

func buildShowDDLJobsFields() (*expression.Schema, types.NameSlice) {
schema := newColumnsWithNames(11)
schema := newColumnsWithNames(12)
schema.Append(buildColumnWithName("", "JOB_ID", mysql.TypeLonglong, 4))
schema.Append(buildColumnWithName("", "DB_NAME", mysql.TypeVarchar, 64))
schema.Append(buildColumnWithName("", "TABLE_NAME", mysql.TypeVarchar, 64))
Expand All @@ -1953,6 +1953,7 @@ func buildShowDDLJobsFields() (*expression.Schema, types.NameSlice) {
schema.Append(buildColumnWithName("", "SCHEMA_ID", mysql.TypeLonglong, 4))
schema.Append(buildColumnWithName("", "TABLE_ID", mysql.TypeLonglong, 4))
schema.Append(buildColumnWithName("", "ROW_COUNT", mysql.TypeLonglong, 4))
schema.Append(buildColumnWithName("", "CREATE_TIME", mysql.TypeDatetime, 19))
schema.Append(buildColumnWithName("", "START_TIME", mysql.TypeDatetime, 19))
schema.Append(buildColumnWithName("", "END_TIME", mysql.TypeDatetime, 19))
schema.Append(buildColumnWithName("", "STATE", mysql.TypeVarchar, 64))
Expand Down
2 changes: 1 addition & 1 deletion session/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
// TxnState wraps kv.Transaction to provide a new kv.Transaction.
// 1. It holds all statement related modification in the buffer before flush to the txn,
// so if execute statement meets error, the txn won't be made dirty.
// 2. It's a lazy transaction, that means it's a txnFuture before StartTS() is really need.
// 2. It's a lazy transaction, that means it's a txnFuture before CreateTS() is really need.
type TxnState struct {
// States of a TxnState should be one of the followings:
// Invalid: kv.Transaction == nil && txnFuture == nil
Expand Down