// runDDLJob runs a DDL job. func (d *ddl) runDDLJob(t *meta.Meta, job *model.Job) { log.Infof("[ddl] run DDL job %s", job) if job.IsFinished() { return } if job.State != model.JobRollback { job.State = model.JobRunning } var err error switch job.Type { case model.ActionCreateSchema: err = d.onCreateSchema(t, job) case model.ActionDropSchema: err = d.onDropSchema(t, job) case model.ActionCreateTable: err = d.onCreateTable(t, job) case model.ActionDropTable: err = d.onDropTable(t, job) case model.ActionAddColumn: err = d.onAddColumn(t, job) case model.ActionDropColumn: err = d.onDropColumn(t, job) case model.ActionModifyColumn: err = d.onModifyColumn(t, job) case model.ActionAddIndex: err = d.onCreateIndex(t, job) case model.ActionDropIndex: err = d.onDropIndex(t, job) case model.ActionAddForeignKey: err = d.onCreateForeignKey(t, job) case model.ActionDropForeignKey: err = d.onDropForeignKey(t, job) case model.ActionTruncateTable: err = d.onTruncateTable(t, job) default: // Invalid job, cancel it. job.State = model.JobCancelled err = errInvalidDDLJob.Gen("invalid ddl job %v", job) } // Save errors in job, so that others can know errors happened. if err != nil { // If job is not cancelled, we should log this error. if job.State != model.JobCancelled { log.Errorf("[ddl] run ddl job err %v", errors.ErrorStack(err)) } else { log.Infof("[ddl] the job is normal to cancel because %v", errors.ErrorStack(err)) } job.Error = toTError(err) job.ErrorCount++ } }
func (d *ddl) runDDLJob(t *meta.Meta, job *model.Job) { if job.IsFinished() { return } job.State = model.JobRunning var err error switch job.Type { case model.ActionCreateSchema: err = d.onCreateSchema(t, job) case model.ActionDropSchema: err = d.onDropSchema(t, job) case model.ActionCreateTable: err = d.onCreateTable(t, job) case model.ActionDropTable: err = d.onDropTable(t, job) case model.ActionAddColumn: err = d.onAddColumn(t, job) case model.ActionDropColumn: err = d.onDropColumn(t, job) case model.ActionAddIndex: err = d.onCreateIndex(t, job) case model.ActionDropIndex: err = d.onDropIndex(t, job) case model.ActionAddForeignKey: err = d.onCreateForeignKey(t, job) case model.ActionDropForeignKey: err = d.onDropForeignKey(t, job) default: // invalid job, cancel it. job.State = model.JobCancelled err = errInvalidDDLJob.Gen("invalid ddl job %v", job) } // saves error in job, so that others can know error happens. if err != nil { // if job is not cancelled, we should log this error. if job.State != model.JobCancelled { log.Errorf("run ddl job err %v", errors.ErrorStack(err)) } job.Error = err.Error() job.ErrorCount++ } }
// runBgJob runs a background job. func (d *ddl) runBgJob(t *meta.Meta, job *model.Job) { job.State = model.JobRunning var err error switch job.Type { case model.ActionDropSchema: err = d.delReorgSchema(t, job) case model.ActionDropTable, model.ActionTruncateTable: err = d.delReorgTable(t, job) default: job.State = model.JobCancelled err = errInvalidBgJob } if err != nil { if job.State != model.JobCancelled { log.Errorf("[ddl] run background job err %v", errors.ErrorStack(err)) } job.Error = toTError(err) job.ErrorCount++ } }
func (d *ddl) runJob(job *model.Job) error { if job.State == model.JobDone || job.State == model.JobCancelled { return nil } job.State = model.JobRunning var err error switch job.Type { case model.ActionCreateSchema: case model.ActionDropSchema: case model.ActionCreateTable: case model.ActionDropTable: case model.ActionAddColumn: case model.ActionDropColumn: case model.ActionAddIndex: case model.ActionDropIndex: case model.ActionAddConstraint: case model.ActionDropConstraint: default: return errors.Errorf("invalid job %v", job) } // if err and inner doesn't cancel job, return err. if err != nil { if job.State != model.JobCancelled { return errors.Trace(err) } job.Error = err.Error() } else { job.State = model.JobDone } return nil }