From daa89c96c902295999770465a6facaec324f6486 Mon Sep 17 00:00:00 2001 From: tangenta Date: Fri, 6 Jan 2023 18:14:37 +0800 Subject: [PATCH 1/2] ddl: support showing subjob reorg type in admin show ddl --- ddl/multi_schema_change.go | 5 +++++ executor/executor.go | 12 +++++++++++- executor/infoschema_reader_test.go | 2 +- parser/model/ddl.go | 2 ++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ddl/multi_schema_change.go b/ddl/multi_schema_change.go index a21bc27965c77..19c355ebfa8da 100644 --- a/ddl/multi_schema_change.go +++ b/ddl/multi_schema_change.go @@ -190,6 +190,10 @@ func appendToSubJobs(m *model.MultiSchemaInfo, job *model.Job) error { if err != nil { return err } + var reorgTp model.ReorgType + if job.ReorgMeta != nil { + reorgTp = job.ReorgMeta.ReorgTp + } m.SubJobs = append(m.SubJobs, &model.SubJob{ Type: job.Type, Args: job.Args, @@ -198,6 +202,7 @@ func appendToSubJobs(m *model.MultiSchemaInfo, job *model.Job) error { SnapshotVer: job.SnapshotVer, Revertible: true, CtxVars: job.CtxVars, + ReorgTp: reorgTp, }) return nil } diff --git a/executor/executor.go b/executor/executor.go index 1679ed9e57e12..d24bd29f8005f 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -595,7 +595,7 @@ func (e *DDLJobRetriever) appendJobToChunk(req *chunk.Chunk, job *model.Job, che req.AppendInt64(0, job.ID) req.AppendString(1, schemaName) req.AppendString(2, tableName) - req.AppendString(3, subJob.Type.String()+" /* subjob */") + req.AppendString(3, subJob.Type.String()+" /* subjob */"+showAddIdxReorgTpInSubJob(subJob)) req.AppendString(4, subJob.SchemaState.String()) req.AppendInt64(5, job.SchemaID) req.AppendInt64(6, job.TableID) @@ -620,6 +620,16 @@ func showAddIdxReorgTp(job *model.Job) string { return "" } +func showAddIdxReorgTpInSubJob(subJob *model.SubJob) string { + if subJob.Type == model.ActionAddIndex || subJob.Type == model.ActionAddPrimaryKey { + tp := subJob.ReorgTp.String() + if len(tp) > 0 { + return " /* " + tp + " */" + } + } + return "" +} + func ts2Time(timestamp uint64, loc *time.Location) types.Time { duration := time.Duration(math.Pow10(9-types.DefaultFsp)) * time.Nanosecond t := model.TSConvert2Time(timestamp) diff --git a/executor/infoschema_reader_test.go b/executor/infoschema_reader_test.go index ed6eed4fb4607..79c2b418e18d2 100644 --- a/executor/infoschema_reader_test.go +++ b/executor/infoschema_reader_test.go @@ -254,7 +254,7 @@ func TestDDLJobs(t *testing.T) { tk.MustExec("create table tt (a int);") tk.MustExec("alter table tt add index t(a), add column b int") tk.MustQuery("select db_name, table_name, job_type from information_schema.DDL_JOBS limit 3").Check( - testkit.Rows("test_ddl_jobs tt alter table multi-schema change", "test_ddl_jobs tt add index /* subjob */", "test_ddl_jobs tt add column /* subjob */")) + testkit.Rows("test_ddl_jobs tt alter table multi-schema change", "test_ddl_jobs tt add index /* subjob */ /* txn-merge */", "test_ddl_jobs tt add column /* subjob */")) } func TestKeyColumnUsage(t *testing.T) { diff --git a/parser/model/ddl.go b/parser/model/ddl.go index 46c1e65477d99..8267a591d3435 100644 --- a/parser/model/ddl.go +++ b/parser/model/ddl.go @@ -350,6 +350,7 @@ type SubJob struct { Warning *terror.Error `json:"warning"` CtxVars []interface{} `json:"-"` SchemaVer int64 `json:"schema_version"` + ReorgTp ReorgType `json:"reorg_tp"` } // IsNormal returns true if the sub-job is normally running. @@ -412,6 +413,7 @@ func (sub *SubJob) FromProxyJob(proxyJob *Job, ver int64) { sub.Warning = proxyJob.Warning sub.RowCount = proxyJob.RowCount sub.SchemaVer = ver + sub.ReorgTp = proxyJob.ReorgMeta.ReorgTp } // JobMeta is meta info of Job. From dd23107bedabe5e6c30a3de93a8f6aa9c3fdd31d Mon Sep 17 00:00:00 2001 From: tangenta Date: Mon, 9 Jan 2023 10:21:42 +0800 Subject: [PATCH 2/2] fix TestMultiSchemaChangeAdminShowDDLJobs --- ddl/multi_schema_change_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddl/multi_schema_change_test.go b/ddl/multi_schema_change_test.go index a8d6f01e63ac6..d9facec4642cf 100644 --- a/ddl/multi_schema_change_test.go +++ b/ddl/multi_schema_change_test.go @@ -1052,7 +1052,7 @@ func TestMultiSchemaChangeAdminShowDDLJobs(t *testing.T) { assert.Equal(t, len(rows), 4) assert.Equal(t, rows[1][1], "test") assert.Equal(t, rows[1][2], "t") - assert.Equal(t, rows[1][3], "add index /* subjob */") + assert.Equal(t, rows[1][3], "add index /* subjob */ /* txn-merge */") assert.Equal(t, rows[1][4], "delete only") assert.Equal(t, rows[1][len(rows[1])-1], "running")