Skip to content

Commit

Permalink
*: add create time to admin show ddl jobs (#32435)
Browse files Browse the repository at this point in the history
ref #23494
  • Loading branch information
wjhuang2016 committed Feb 17, 2022
1 parent 5e52263 commit e592cef
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
3 changes: 3 additions & 0 deletions ddl/ddl_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,9 @@ func (w *worker) runDDLJob(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64,

logutil.Logger(w.logCtx).Info("[ddl] run DDL job", zap.String("job", job.String()))
timeStart := time.Now()
if job.RealStartTS == 0 {
job.RealStartTS = t.StartTS
}
defer func() {
metrics.DDLWorkerHistogram.WithLabelValues(metrics.WorkerRunDDLJob, job.Type.String(), metrics.RetLabel(err)).Observe(time.Since(timeStart).Seconds())
}()
Expand Down
16 changes: 11 additions & 5 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ func (e *DDLJobRetriever) appendJobToChunk(req *chunk.Chunk, job *model.Job, che
tableName = getTableName(e.is, job.TableID)
}

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

// Check the privilege.
Expand All @@ -525,13 +526,18 @@ 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)
if finishTS > 0 {
req.AppendTime(9, finishTime)
req.AppendTime(8, createTime)
if job.RealStartTS > 0 {
req.AppendTime(9, startTime)
} else {
req.AppendNull(9)
}
req.AppendString(10, job.State.String())
if finishTS > 0 {
req.AppendTime(10, finishTime)
} else {
req.AppendNull(10)
}
req.AppendString(11, job.State.String())
}

func ts2Time(timestamp uint64) types.Time {
Expand Down
8 changes: 4 additions & 4 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func (s *testSuite3) TestAdmin(c *C) {
err = r.Next(ctx, req)
c.Assert(err, IsNil)
row = req.GetRow(0)
c.Assert(row.Len(), Equals, 11)
c.Assert(row.Len(), Equals, 12)
txn, err = s.store.Begin()
c.Assert(err, IsNil)
historyJobs, err := admin.GetHistoryDDLJobs(txn, admin.DefNumHistoryJobs)
Expand All @@ -442,7 +442,7 @@ func (s *testSuite3) TestAdmin(c *C) {
err = r.Next(ctx, req)
c.Assert(err, IsNil)
row = req.GetRow(0)
c.Assert(row.Len(), Equals, 11)
c.Assert(row.Len(), Equals, 12)
c.Assert(row.GetInt64(0), Equals, historyJobs[0].ID)
c.Assert(err, IsNil)

Expand Down Expand Up @@ -569,13 +569,13 @@ func (s *testSuiteP2) TestAdminShowDDLJobs(c *C) {
re = tk.MustQuery("admin show ddl jobs 1 where job_type='create table'")
row = re.Rows()[0]
c.Assert(row[1], Equals, "test_admin_show_ddl_jobs")
c.Assert(row[9], Equals, "<nil>")
c.Assert(row[10], Equals, "<nil>")

// Test the START_TIME and END_TIME field.
re = tk.MustQuery("admin show ddl jobs where job_type = 'create table' and start_time > str_to_date('20190101','%Y%m%d%H%i%s')")
row = re.Rows()[0]
c.Assert(row[2], Equals, "t")
c.Assert(row[9], Equals, "<nil>")
c.Assert(row[10], Equals, "<nil>")
}

func (s *testSuiteP2) TestAdminShowDDLJobsInfo(c *C) {
Expand Down
4 changes: 2 additions & 2 deletions executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ func (e *DDLJobsReaderExec) Next(ctx context.Context, req *chunk.Chunk) error {
num := mathutil.Min(req.Capacity(), len(e.runningJobs)-e.cursor)
for i := e.cursor; i < e.cursor+num; i++ {
e.appendJobToChunk(req, e.runningJobs[i], checker)
req.AppendString(11, e.runningJobs[i].Query)
req.AppendString(12, e.runningJobs[i].Query)
}
e.cursor += num
count += num
Expand All @@ -1206,7 +1206,7 @@ func (e *DDLJobsReaderExec) Next(ctx context.Context, req *chunk.Chunk) error {
}
for _, job := range e.cacheJobs {
e.appendJobToChunk(req, job, checker)
req.AppendString(11, job.Query)
req.AppendString(12, job.Query)
}
e.cursor += len(e.cacheJobs)
}
Expand Down
1 change: 1 addition & 0 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,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 @@ -2689,7 +2689,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 @@ -2698,6 +2698,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

0 comments on commit e592cef

Please sign in to comment.