5

When I run my custom import script, and during it's execution starts reindex, it causes the error :

SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction, query was:

INSERT INTO catalog_product_entity_datetime ... and other catalog_product_entity_* tables

How can I avoid these errors?

I thinking about a few ways:

  1. Lock indexer
  2. Lock tables (bad idea)
  3. Temporary disable cron (even more bad idea)
  4. Extend and override core indexer and manually write the code that will check some lock files.

I can't find any information about indexer locking in Magento 2.

And another question: It can be a problem with the deadlock not at all in reindex and import?

Thanks.

2

Here is the code which might help you (I took it from \Magento\Indexer\Model\Indexer::reindexAll):

$state = $stateFactory->create();
$state->loadByIndexer({indexer_id});
$state->setStatus(StateInterface::STATUS_WORKING);
$state->save();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.