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: support displaying sub-job reorg type in admin show ddl #40387

Merged
merged 8 commits into from
Jan 10, 2023
5 changes: 5 additions & 0 deletions ddl/multi_schema_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion ddl/multi_schema_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
12 changes: 11 additions & 1 deletion executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion executor/infoschema_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions parser/model/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,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.
Expand Down Expand Up @@ -418,6 +419,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.
Expand Down