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 #31544

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
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.SchemaState = model.StateQueueing
if err = buildJobDependence(t, job); err != nil {
return errors.Trace(err)
}
Expand Down Expand Up @@ -596,6 +597,10 @@ func (w *worker) handleDDLJobQueue(d *ddlCtx) error {
return errors.Trace(err)
}

if job.SchemaState == model.StateQueueing {
job.SchemaState = model.StateNone
}

// only general ddls allowed to be executed when TiKV is disk full.
if w.tp == addIdxWorker && job.IsRunning() {
txn.SetDiskFullOpt(kvrpcpb.DiskFullOpt_NotAllowedOnFull)
Expand Down
6 changes: 5 additions & 1 deletion parser/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const (
StateReplicaOnly
// StateGlobalTxnOnly means we can only use global txn for operator on this schema element
StateGlobalTxnOnly
// StateQueueing means the job is in the initial state of add partition.
StateQueueing
/*
* Please add the new state at the end to keep the values consistent across versions.
*/
Expand All @@ -70,8 +72,10 @@ func (s SchemaState) String() string {
return "replica only"
case StateGlobalTxnOnly:
return "global txn only"
default:
case StateQueueing:
return "queueing"
default:
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
4 changes: 2 additions & 2 deletions util/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ func IsJobRollbackable(job *model.Job) bool {
return false
}
case model.ActionAddTablePartition:
return job.SchemaState == model.StateNone || job.SchemaState == model.StateReplicaOnly
return job.SchemaState == model.StateNone || job.SchemaState == model.StateReplicaOnly || job.SchemaState == model.StateQueueing
case model.ActionDropColumn, model.ActionDropColumns, model.ActionDropTablePartition,
model.ActionRebaseAutoID, model.ActionShardRowID,
model.ActionTruncateTable, model.ActionAddForeignKey,
model.ActionDropForeignKey, model.ActionRenameTable,
model.ActionModifyTableCharsetAndCollate, model.ActionTruncateTablePartition,
model.ActionModifySchemaCharsetAndCollate, model.ActionRepairTable,
model.ActionModifyTableAutoIdCache, model.ActionModifySchemaDefaultPlacement:
return job.SchemaState == model.StateNone
return job.SchemaState == model.StateNone || job.SchemaState == model.StateQueueing
}
return true
}
Expand Down