From 96d2fc00f2770d13cacedd4c4100995bc33408d5 Mon Sep 17 00:00:00 2001 From: lihaowei Date: Fri, 16 Apr 2021 13:32:29 +0800 Subject: [PATCH] 4 review --- ddl/db_integration_test.go | 2 +- ddl/db_test.go | 2 +- ddl/ddl_worker.go | 3 ++- ddl/stat.go | 2 +- distsql/request_builder.go | 2 +- executor/ddl.go | 14 +++++++------- executor/executor.go | 10 ++++++---- go.mod | 1 + infoschema/tables.go | 1 + planner/core/planbuilder.go | 3 ++- session/txn.go | 2 +- 11 files changed, 24 insertions(+), 18 deletions(-) diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index d73ef6c0e6850..f06372d447432 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -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. diff --git a/ddl/db_test.go b/ddl/db_test.go index d58340878c780..0e47a2098db7a 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -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) diff --git a/ddl/ddl_worker.go b/ddl/ddl_worker.go index 33ebaea2c5f6f..624fd89bf3177 100644 --- a/ddl/ddl_worker.go +++ b/ddl/ddl_worker.go @@ -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) @@ -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 } diff --git a/ddl/stat.go b/ddl/stat.go index 6f21b99f89a8e..f668fb40bb915 100644 --- a/ddl/stat.go +++ b/ddl/stat.go @@ -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 { diff --git a/distsql/request_builder.go b/distsql/request_builder.go index ac53de8a0c4a3..6f7d41f132477 100644 --- a/distsql/request_builder.go +++ b/distsql/request_builder.go @@ -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 diff --git a/executor/ddl.go b/executor/ddl.go index 2940bab6b80f5..a95d7274d6cbb 100644 --- a/executor/ddl.go +++ b/executor/ddl.go @@ -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, } @@ -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 } @@ -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 } @@ -478,7 +478,7 @@ 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 } @@ -486,7 +486,7 @@ func GetDropOrTruncateTableInfoFromJobs(jobs []*model.Job, gcSafePoint uint64, d continue } - snapMeta, err := dom.GetSnapshotMeta(job.StartTS) + snapMeta, err := dom.GetSnapshotMeta(job.CreateTS) if err != nil { return false, err } @@ -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, } diff --git a/executor/executor.go b/executor/executor.go index 3371ca93442e3..702101a9cd709 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -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) @@ -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 { diff --git a/go.mod b/go.mod index 6e8463bceb9ef..1a136ae374406 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/infoschema/tables.go b/infoschema/tables.go index 4021c2844ad9c..f9e71beef4459 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -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}, diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index f955459ffe495..e5bdc850da5f3 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -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)) @@ -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)) diff --git a/session/txn.go b/session/txn.go index eed4698f60a65..15fd8f2e57a96 100644 --- a/session/txn.go +++ b/session/txn.go @@ -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