-
Notifications
You must be signed in to change notification settings - Fork 22
Fix PG::ExclusionViolation in concurrent updates #394
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
base: master
Are you sure you want to change the base?
Conversation
d5aef09 to
d1e362a
Compare
|
Any chance to run this spec in isolation? |
|
@tagliala This is expected behavior. You should run |
|
Got it, but it is not expected there to fail because specs under They all pass in isolation Specs requiring rails are placed under |
|
@tagliala Thanks for clarification 👍 |
fe9ab7b to
3251767
Compare
f026cb5 to
522e564
Compare
525460d to
5f48110
Compare
8c95067 to
0aceac6
Compare
0aceac6 to
d5bf643
Compare
This PR addresses concurrency issues where simultaneous updates to the same record could trigger a PG::ExclusionViolation due to overlapping validity ranges.
Key Changes & Technical Details:
Fix
PG::ExclusionViolation:Added explicit row locking (
PERFORM 1 ... FOR UPDATE) in the UPDATE trigger. This serializes concurrent updates to the same row, preventing them from attempting to insert overlapping history ranges simultaneously.After adding the lock we have the second issue with
RangeError, we can fix it with slightly updated squashing logic.Update Squashing Logic:
I updated the query that detects multiple updates for the same transaction and changed conditions from
lower(validity) = _nowtolower(validity) >= _nowThis means that when the
validityis already updated in a parallel transaction that runs at the same millisecond, we will squash the changes and not create a new historical record.