Remove pg_advisory_unlock_all()
after job is run; only verify blank finished_at
(and not lock presence) before performing job
#1113
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.
The background of this change arises from trying to overcome the performance limitations of the lock verification as described in #896.
Before this change, the sequence when dequeuing a job to perform:
finished_at
is not setAfter this change:
finished_at
is not setBackground / Analysis
Most briefly, GoodJob's advisory locking strategy went through a lot of churn in mid-2021.
Using
pg_advisory_unlock_all
, instead of unlocking the specifically returned record, was introduced in #285 to address unexpectedly advisory locked records caused by "an indeterminate reason" (😞). In the fullness of time, I'm fairly certain that it was caused by aFOR UPDATE SKIP LOCKED
that was introduced in #273 (mistakenly? that PR says it was extracted to #274, and it wasn't), and theSKIP LOCKED
was removed in #288.For the record, the problem wasn't inherently the
FOR UPDATE SKIP LOCKED
but the placement of it in the query. It was placed in the same subselect as the advisory-lock function, implying that sometimes the advisory-lock function would lock a record that would be then be skip-locked from the results but still remain advisory locked: #285 (comment)Or, the issue could be that at the time I was using a
Rails.application.executor.wrap
instead of aRails.application.reloader.wrap
which was also identified in #389 as as source ofWARNING: you don't own a lock of type ExclusiveLock
errors. (a little more convo in #99 too, which is when theexecutor.wrap
was last reviewed)Or both!