cockroachdb / cockroachdb/cockroach
jobs: scheduled jobs Create and Update functions are not txn retry safe
- 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
Assessment
This issue has not been assessed yet.