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

jobs: refresh job details before removing protected timestamps #92586

Merged
merged 1 commit into from
Nov 28, 2022
Merged
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
27 changes: 16 additions & 11 deletions pkg/jobs/jobsprotectedts/jobs_protected_ts_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func (p *Manager) Protect(
return nil, err
}
return func(ctx context.Context) error {
// Remove the protected timestamp.
return p.Unprotect(ctx, job)
}, nil
}
Expand All @@ -201,19 +202,23 @@ func (p *Manager) Protect(
// record. Note: This should only be used for job cleanup if is not currently,
// executing.
func (p *Manager) Unprotect(ctx context.Context, job *jobs.Job) error {
return p.db.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
// Fetch the protected timestamp UUID from the job, if one exists.
protectedtsID := getProtectedTSOnJob(job.Details())
// Fetch the protected timestamp UUID from the job, if one exists.
if getProtectedTSOnJob(job.Details()) == nil {
return nil
}
// If we do find one then we need to clean up the protected timestamp,
// and remove it from the job.
return job.Update(ctx, nil, func(txn *kv.Txn, md jobs.JobMetadata, ju *jobs.JobUpdater) error {
// The job will get refreshed, so check one more time the protected
// timestamp still exists. The callback returned from Protect works
// on a previously cached copy.
protectedtsID := getProtectedTSOnJob(md.Payload.UnwrapDetails())
if protectedtsID == nil {
return nil
}
// If we do find one then we need to clean up the protected timestamp,
// and remove it from the job.
return job.Update(ctx, txn, func(txn *kv.Txn, md jobs.JobMetadata, ju *jobs.JobUpdater) error {
updatedDetails := setProtectedTSOnJob(job.Details(), nil)
md.Payload.Details = jobspb.WrapPayloadDetails(updatedDetails)
ju.UpdatePayload(md.Payload)
return p.protectedTSProvider.Release(ctx, txn, *protectedtsID)
})
updatedDetails := setProtectedTSOnJob(job.Details(), nil)
md.Payload.Details = jobspb.WrapPayloadDetails(updatedDetails)
ju.UpdatePayload(md.Payload)
return p.protectedTSProvider.Release(ctx, txn, *protectedtsID)
})
}