Repository navigation
Fix keyed add_jobs race and preserve attempts on locked batch jobs - #646
Open
fortizflexidao wants to merge 1 commit into
Open
fortizflexidao wants to merge 1 commit into
fortizflexidao wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #580.
This PR adds migration
000021.sqlto fix two edge cases ingraphile_worker.add_jobswhen scheduling jobs with ajob_key:Silent drop when a row becomes locked between
UPDATEandINSERT(Race in add_job/add_jobs with keyed jobs can drop scheduling requests (and returns no row under contention) #580):Under
READ COMMITTED, the initialUPDATE ... WHERE key = spec.job_key AND is_available IS NOT TRUEskips unlocked rows without locking them. If a worker claims that row (or another transaction inserts and locks the same key) beforeINSERT ... ON CONFLICT (key) DO UPDATE WHERE jobs.locked_at IS NULLruns,WHERE jobs.locked_at IS NULLevaluates to false and Postgres returns no row.spec.job_keywithFOR UPDATE(ordered bykey) before the key-clearingUPDATE, so a concurrentget_job(FOR UPDATE SKIP LOCKED) skips them.Lost retries on in-flight batch jobs (
json_typeof(payload) = 'array'):When a locked job has its
keycleared because a new job with the samejob_keyarrives,add_jobssetsattempts = jobs.max_attemptsso the superseded job will not retry if it fails. For batch jobs (JSON array payload), the newly inserted row only contains the new elements, not the elements currently being processed by the locked batch job. Preservingjobs.attemptswhenjson_typeof(jobs.payload) = 'array' and jobs.locked_at is not nullallows the in-flight batch to still retry its failed elements if it errors out.Performance impact
unknown
Security impact
unknown
Checklist
yarn lint:fixpasses.yarn testpasses.RELEASE_NOTES.mdfile (if one exists).