Problem/Motivation
There are often issues reported(for example this one) of MySQL failing on multiple request trying to save an entity of the same type. This happens due to MySQL transaction deadlocks.
The "semaphore" table, which(I suppose) was meant to deal with this kind of problems, suffers from this issue as well - there is a bug report of it, but I was also able to reproduce it locally too.
An example of steps to reproduce
- Write a batch that generates dummy entities, for example Nodes
- Launch a few of them in separate browser tabs or windows
- At least one of the batches will fail quickly
Proposed resolution
Wrap the ContentEntityStorageBase::doSave() into GET_LOCK and RELEASE_LOCK functions of MySQL with using entity type specific lock ID's, for example "entity_node_save" or "entity_commerce_order_save".
The request
We(my company) are going to implement this solution as a separate module which would use hook_entity_presave/hook_entity_update, and publish it in case of success. We have a proof-of-concept code, which has shown us great stable results.
Can you guys please take a look onto this idea and tell if it is worth development and publishing as a contrib module for the community? Also, are there maybe any "underwater stones" to consider specifically?
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 3216606-9.patch | 5.11 KB | ranjith_kumar_k_u |
| #8 | 3216606-nr-bot.txt | 107 bytes | needs-review-queue-bot |
| #6 | locked_content_entity_operations.patch | 4.6 KB | leonidzinets |
Comments
Comment #2
mxr576Comment #3
cilefen commentedI would rather we fix this in core. Is the semaphore locking fixable?
Comment #6
leonidzinetsAfter some extra research we found out that implementing locks in entity-related hooks is not enough, and under some circumstances the issues still happened. So, this is the approach that we've currently ended upon. It's a core file patch(attached) and so far initial testing has shown good results.
Do you guys know if there are some underwater stones with this approach? Were there some reasons why this(or similar) approach hasn't been implemented to the core yet? Maybe there are some extra consequences of this approach which I currently don't understand?
Comment #7
cilefen commentedComment #8
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #9
ranjith_kumar_k_u commentedRe-rolled #6
Comment #10
ranjith_kumar_k_u commentedwrong patch please ignore
Comment #11
ranjith_kumar_k_u commented