Skip to content

Commit

Permalink
sql: make cleanup jobs spawned by alter primary key not cancelable
Browse files Browse the repository at this point in the history
Fixes #45500.

This PR makes the job spawned by ALTER PRIMARY KEY that cleans
up indexes be uncancelable.

This PR additionally fixes a related bug where ALTER PRIMARY KEY
would spawn a job when it didn't actually enqueue any mutations
on the table descriptor, causing future schema changes on the
table to hang.

Release note (sql change): This PR makes the cleanup job spawned
by ALTER PRIMARY KEY in some cases uncancelable.
  • Loading branch information
rohany committed Mar 3, 2020
1 parent 860c137 commit 3d7aeb3
Show file tree
Hide file tree
Showing 6 changed files with 326 additions and 237 deletions.
8 changes: 8 additions & 0 deletions pkg/jobs/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ type Record struct {
Details jobspb.Details
Progress jobspb.ProgressDetails
RunningStatus RunningStatus
// NonCancelable is used to denote when a job cannot be canceled. This field
// will not be respected in mixed version clusters where some nodes have
// a version < 20.1, so it can only be used in cases where all nodes having
// versions >= 20.1 is guaranteed.
NonCancelable bool
}

// StartableJob is a job created with a transaction to be started later.
Expand Down Expand Up @@ -375,6 +380,9 @@ func (j *Job) cancelRequested(
ctx context.Context, fn func(context.Context, *client.Txn) error,
) error {
return j.Update(ctx, func(txn *client.Txn, md JobMetadata, ju *JobUpdater) error {
if md.Payload.Noncancelable {
return errors.Newf("job %d: not cancelable", j.ID())
}
if md.Status == StatusCancelRequested || md.Status == StatusCanceled {
return nil
}
Expand Down
Loading

0 comments on commit 3d7aeb3

Please sign in to comment.