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: fix inappropriate schema state output by admin show ddl jobs #33850

Merged
merged 3 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ddl/column_type_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func TestRollbackColumnTypeChangeBetweenInteger(t *testing.T) {
// Alter sql will modify column c2 to bigint not null.
SQL := "alter table t modify column c2 int not null"
err := tk.ExecToErr(SQL)
require.EqualError(t, err, "[ddl:1]MockRollingBackInCallBack-queueing")
require.EqualError(t, err, "[ddl:1]MockRollingBackInCallBack-none")
assertRollBackedColUnchanged(t, tk)

// Mock roll back at model.StateDeleteOnly.
Expand Down
5 changes: 5 additions & 0 deletions ddl/ddl_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ func (d *ddl) addBatchDDLJobs(tasks []*limitJobTask) {
job.Version = currentVersion
job.StartTS = txn.StartTS()
job.ID = ids[i]
job.State = model.JobStateQueueing
if err = buildJobDependence(t, job); err != nil {
return errors.Trace(err)
}
Expand Down Expand Up @@ -623,6 +624,10 @@ func (w *worker) handleDDLJobQueue(d *ddlCtx) error {
return errors.Trace(err)
}

if job.IsQueueing() {
job.State = model.JobStateNone
tangenta marked this conversation as resolved.
Show resolved Hide resolved
}

d.mu.RLock()
d.mu.hook.OnJobRunBefore(job)
d.mu.RUnlock()
Expand Down
12 changes: 12 additions & 0 deletions parser/model/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,14 @@ func (job *Job) IsRunning() bool {
return job.State == JobStateRunning
}

func (job *Job) IsQueueing() bool {
return job.State == JobStateQueueing
}

func (job *Job) NotStarted() bool {
return job.State == JobStateNone || job.State == JobStateQueueing
}

// JobState is for job state.
type JobState byte

Expand All @@ -523,6 +531,8 @@ const (
JobStateSynced JobState = 6
// JobStateCancelling is used to mark the DDL job is cancelled by the client, but the DDL work hasn't handle it.
JobStateCancelling JobState = 7
// JobStateQueueing means the job has not yet been started.
JobStateQueueing JobState = 8
)

// String implements fmt.Stringer interface.
Expand All @@ -542,6 +552,8 @@ func (s JobState) String() string {
return "cancelling"
case JobStateSynced:
return "synced"
case JobStateQueueing:
return "queueing"
default:
return "none"
}
Expand Down
2 changes: 1 addition & 1 deletion parser/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (s SchemaState) String() string {
case StateGlobalTxnOnly:
return "global txn only"
default:
return "queueing"
return "none"
}
}

Expand Down
2 changes: 1 addition & 1 deletion parser/model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func TestJobStartTime(t *testing.T) {
BinlogInfo: &HistoryInfo{},
}
require.Equal(t, TSConvert2Time(job.StartTS), time.Unix(0, 0))
require.Equal(t, fmt.Sprintf("ID:123, Type:none, State:none, SchemaState:queueing, SchemaID:0, TableID:0, RowCount:0, ArgLen:0, start time: %s, Err:<nil>, ErrCount:0, SnapshotVersion:0", time.Unix(0, 0)), job.String())
require.Equal(t, fmt.Sprintf("ID:123, Type:none, State:none, SchemaState:none, SchemaID:0, TableID:0, RowCount:0, ArgLen:0, start time: %s, Err:<nil>, ErrCount:0, SnapshotVersion:0", time.Unix(0, 0)), job.String())
}

func TestJobCodec(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion util/admin/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestGetDDLJobs(t *testing.T) {
currJobs2 = currJobs2[:0]
err = IterAllDDLJobs(txn, func(jobs []*model.Job) (b bool, e error) {
for _, job := range jobs {
if job.State == model.JobStateNone {
if job.NotStarted() {
currJobs2 = append(currJobs2, job)
} else {
return true, nil
Expand Down