Skip to content

Commit

Permalink
ddl: add context cancel check before commit (pingcap#53134)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta authored and terry1purcell committed May 17, 2024
1 parent 1bf9d50 commit e29dc54
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/ddl/ddl_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ func (w *JobContext) setDDLLabelForDiagnosis(jobType model.ActionType) {
}

func (w *worker) HandleJobDone(d *ddlCtx, job *model.Job, t *meta.Meta) error {
if err := w.checkOwnerBeforeCommit(); err != nil {
if err := w.checkBeforeCommit(); err != nil {
return err
}
err := w.finishDDLJob(t, job)
Expand Down Expand Up @@ -956,7 +956,7 @@ func (w *worker) HandleDDLJobTable(d *ddlCtx, job *model.Job) (int64, error) {
return 0, err
}

if err = w.checkOwnerBeforeCommit(); err != nil {
if err = w.checkBeforeCommit(); err != nil {
d.unlockSchemaVersion(job.ID)
return 0, err
}
Expand Down Expand Up @@ -1008,13 +1008,18 @@ func (w *worker) HandleDDLJobTable(d *ddlCtx, job *model.Job) (int64, error) {
return schemaVer, nil
}

func (w *worker) checkOwnerBeforeCommit() error {
func (w *worker) checkBeforeCommit() error {
if !w.ddlCtx.isOwner() && w.tp != localWorker {
// Since this TiDB instance is not a DDL owner anymore,
// it should not commit any transaction.
w.sess.Rollback()
return dbterror.ErrNotOwner
}

if err := w.ctx.Err(); err != nil {
// The worker context is canceled, it should not commit any transaction.
return err
}
return nil
}

Expand Down

0 comments on commit e29dc54

Please sign in to comment.