Repository navigation
Lock healed records in primary key order - #93
Merged
Merged
Conversation
When a scope has no belongs_to association, or its parent is nil, the healer locks the scope's records with plain lock.ids. On MySQL, that deadlocks more often against saves to the same list than ordering the lock by primary key, which #75 does for positioning's own lock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
brendon
force-pushed
the
fix/healer-lock-order
branch
from
November 28, 2026 01:33
0069249 to
6ef8590
Compare
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.
When a scope has no
belongs_toassociation, or its parent isnil, the healer locks the scope's records with plainlock.idsbefore renumbering them. #75 found that on MySQL, plainlock.idsdeadlocks more often than the same lock ordered by primary key, and changed positioning's own lock toreorder(primary_key).lock.ids. This PR makes the same change to both of the healer'slock.idscalls.Measurements
MySQL 9.7.4, locally. Each run is five rounds of three concurrent moves to position 1 plus one
heal_position_column!, on 10 records in one list. Deadlocks are moves/heals, for each of three runs:mainProduct)[scope, position]unique indexPositions were correct after every round. This PR doesn't change the moves' own lock; their deadlocks in the column scope are the ones #75 also measured on
main. The probe isn't part of this PR.Who this changes things for
Only apps that heal a list with no parent row to lock: a model with no scope, a scope on plain columns, or a list whose
belongs_toparent isnil. The same rows are locked, now in primary key order. Healing a list that has a parent still locks the parent withlock!.Tests
test_heal_locks_records_in_primary_key_orderchecks that the healer's lock is ordered by primary key for a model with no scope (Product), a column scope (Blog) and anilparent (Category). It's skipped on SQLite, which has no row locks, and fails againstmain's healer on MySQL and PostgreSQL.Changelog: When healing a scope that has no
belongs_toassociation (or whose parent isnil), lock its records in primary key order. On MySQL, healing next to saves to the same list deadlocked more often without it.🤖 Generated with Claude Code