cockroachdb / cockroachdb/cockroach

jobs: scheduled jobs Create and Update functions are not txn retry safe

Open
#106,700 0 comments 0 reactions 0 assignees View on GitHub
A-jobs C-bug db-cy-23 T-jobs
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

**Describe the problem**

The `scheduledJobStorageTxn` API takes a *job.Job object and updates the database in the context of the given transaction. However, it also attempts to update the given *job.Job and those updates result in errors if the transaction is retried.

For example, the Create method has an assertion that the ScheduleID does not exist on the object. But InitFromDatums will set the ScheduleID during the transaction.

https://github.com/cockroachdb/cockroach/blob/b383f9663f8fa45b5b62f9662fcdb9397fd01557/pkg/jobs/scheduled_job.go#L461-L490

Similarly, Update requires that the job object have dirty state, but the marshalChanges method clears the dirty state before the transaction commits.

https://github.com/cockroachdb/cockroach/blob/b383f9663f8fa45b5b62f9662fcdb9397fd01557/pkg/jobs/scheduled_job.go#L505-L540

We likely need to re-think the shape of this API to fix this.

Found as part of #106417

Jira issue: CRDB-29684

Epic CRDB-32494

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.