1213 Deadlock found when trying to get lock
Preconditions
- Magento 2.1.3
- Php 7.0.13-1 and Apache2
Steps to reproduce
- Importing Product (Saving to Magento) from 3rd party API from CLI Script
- Run above process in parallel since too many products exist
- Index - Update by Schedule. (Meaning no index works when importing product)
Expected result
- Product Should be successfully saved to the system
Actual result
- Following problem happen oftenly,
- PDOException: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock
- If I try to edit product related value on Admin page while importing product, that error happen too.
The indexer runs on a schedule by cron! you need to disable that or they need a lock to prevent concurrent access!
If you don't mind modifying the database code you can modify aoe's magenta 1 plugin to function the same. I have and it does not solve the longer issues, but can be a lifesaver due to the little short issues!
You should really batch all of your product imports when the store is in maintenance mode and then reindex before taking it out of maintenance mode at midnight!
At least until magento can develop a decent locking system to work around the cron indexer! https://github.com/AOEpeople/Aoe_DbRetry/blob/master/app/code/community/Aoe/DbRetry/Resource/Db/Pdo/Mysql/Adapter.php
Thanks for reply.
-
I forgot to mention that we for now even disabled cron job too. So, no index work when importing product.
-
Let me tell you my scenario here -- There are lots of products on 3rd party system to import. -- Average 30k products exist on that system. On that system, 3k of products deleted and 3k of new products created every week. -- To manage a price and stock of existing product and newly added product, we need to run this process at least 1-2 per week. -- Importing Products to Magento system is slow. Especially creating new product is much slower than updating. -- Because of reason above (many products and slow), we have to run this process most time of week. So we cannot even turn our website in maintenance mode. That's why we need to run this script in parallel to get it done faster.
Thank you
Sounds like you need to use a dedicated import script. I can import 1M products in about 6 hours time using dedicated script that does direct access to database, but as you have figured out- you cannot manually muck with the categories/products during the same time! IMO the best route would be to offload the product attributes/categories to a nosql based solution so you can side-load the products. I've only seen this done with magento 1 using smile-sa (GitHub) mongodb driver!
But if you use smile-sa's elastic suite - the indexing goes much faster! check it out it is free!
While reindexing the catalog stays online since it reindexes to a new catalog and does a switcheroo when done!
Hello,
Could you please specify "nosql based solution" ?
Thank you
store all product attributes in mongodb which is far better than EAV-style datastore for tons of products. Better yet - imo - would be to store the attributes in elasticsearch itself!
Thanks for reply. I have another question regarding indexing.
-
Currently Indexer has been set as "UPDATE BY SCHEDULE"
-
Cron job currently disabled
-
Create Product using php script on CLI and through Product Model (Product->save())
=> expected result, newly added product should not be in catalog_product_flat table => actual result, newly added product is in catalog_product_flat_table (look system reindex after product save)
I'm not sure, are you sure that cron.php is not being called by crond?!
I assumed reindexing was to move from database (flat, or eav) to solr/elasticsearch models on schedule. I would have thought the flat table was directly written to.
I've been using elasticsearch since v1 - so i'm not sure how the flat tables get indexed if not real time?! mysql doesn't need any work to add text based indexing!
I'm having this same issue on magento 2.1.6 and I'm using elasticsearch but my issue seems to be when magento is running a reindex
Confirm this bug.
v.2.1.8
and with v.2.21
Confirm Magento 2.1.10 In our case, when reindex is running, no order can be placed (lock on sales_order table)
Magento Version: 2.1.9| Mode: Production Indexing Mode: Update on save
Total Products: 18k Total Customers: 54k Total Orders: 18k
my client site is marketplace site so, on this site, there are lots of products, customers, and orders adding or updating.
But when I tried to reindexing all than after some time exception.log file generated including the following error in this file and server was stuck and then need to restart the server and then after the site is working as normal.
"PDOException: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction"
so please suggest me how can I fix it and what is the best way to reindexing manually or using cron?
Hi @yj4189 , if you set indexers to "Update on Save" mode, then you should not do full reindex. I suggest you change indexing mode to "update on schedule" + setup crons.
If you still have deadlock, please provide information from mysql command SHOW ENGINE INNODB STATUS
Same error happening for me on 2.2.2
Same error happening for me on 2.2.3
We are facing deadlock issue during catalog_product_attribute reindexing.
It gives SQLSTATE[HY000]: General error: 2006 MySQL server has gone away error as MySQL database CPU is 100% utilized.
Magento version: 2.1.7 No of SKUs: 6 Lacs No of Attributes: 110 No of stores: 4
Please suggest what can be done?
@dimple-ambab , it can be another issue, not related to a deadlock. Please check after error happening status of section LATEST DETECTED DEADLOCK with command "SHOW ENGINE INNODB STATUS" Also check all mysql error logs for reason of error
I've experienced similar issues...
This is still an issue on 2.2.4, but only when trying to save products while the indexing is running.
Same here - We receive that error if a product is saving when the index is running.