-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix a condition which would lead to MySQL deadlock #127
Merged
Conversation
This file contains 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
👍 |
2 similar comments
👍 |
👍 |
I don't think the where clause is necessary, I think the fix here is just using Old:
This PR:
Proposed:
|
Thanks for that catch John. I think you're correct. I will make that modification. |
Running a delete by an index condition, for example: ``` DELETE FROM spree_adjustments WHERE adjustable_id = 1 AND adjustable_type = 'Spree::Shipment' ``` will require MySQL to acquire a gap lock on the index which indexes adjustable_id and adjustable_type. Running this in a heavily loaded environment can lead to deadlocks in MySQL as multiple threads need an exclusive gap lock on the index in question. By deleting records by the primary key instead, MySQL is able to deal with this without requiring an exclusive lock on the primary key index, avoiding the deadlock situation.
gmacdougall
force-pushed
the
fix-mysql-deadlock
branch
from
June 30, 2015 17:28
ff07a4f
to
07f9983
Compare
jhawthorn
added a commit
that referenced
this pull request
Jun 30, 2015
Fix a condition which would lead to MySQL deadlock
glongman
added a commit
to Fullscript/spree
that referenced
this pull request
Apr 24, 2018
Tax computation occurs repeatedly per order, per line item, per step during checkout. Spree::TaxRate computes new Adjustments after deleting the old ones. A PR in Solidus pointed out that using `delete_all` can result in generated SQL that contains polymorphic columns and caused INNODB to take gap locks. Under load this can result in deadlock. Using `deleted_all` means only primary key based deleted will occur. No gap locks so deadlocks can be less likely. spree_adjustments is a high traffic table. Spree::Adjustment has no `after_destroy` or relations that would invoke logic on destroy so this should be safe. Ref: solidusio/solidus#127
spaghetticode
referenced
this pull request
in nebulab/solidus
Mar 26, 2021
Try to harden the PayPal integration spec
mamhoff
added a commit
to mamhoff/solidus
that referenced
this pull request
Jun 26, 2024
…-callback-override Remove `require_promotion_code` override
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.
Running a delete by an index condition, for example:
will require MySQL to acquire a gap lock on the index which indexes
adjustable_id and adjustable_type.
Running this in a heavily loaded environment can lead to deadlocks in
MySQL as multiple threads need an exclusive gap lock on the index in
question.
By deleting records by the primary key instead, MySQL is able to deal
with this without requiring an exclusive lock on the primary key index,
avoiding the deadlock situation.