0

On Drupal 8 we're getting a few deadlock conditions - most connected with the cache. There are quite a few answers to this issue but not so much for D8 (which has very different caching mechanism). Is there any way to resolve/mitigate?

Drupal\Core\Entity\EntityStorageException: SQLSTATE[40P01]: Deadlock detected: 7 ERROR: deadlock detected DETAIL: 
Process 9131 waits for ShareRowExclusiveLock on relation 8341492 of database 8341380; blocked by process 9130. 
Process 9130 waits for ShareRowExclusiveLock on relation 8341562 of database 8341380; blocked by process 9131. 
HINT: See server log for query details.: LOCK TABLE {cache_bootstrap} IN SHARE ROW EXCLUSIVE MODE; 
Array ( ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() 
    (line 847 of /var/xxx/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
  • 1
    No, this is not caching related, this deadlock occurs while saving a content entity. Such a deadlock is very unlikely unless you have an unusual amount of content entity saves. Do you have a lot of POST requests saving data? Or do you have a use case where you update content entities in GET requests? – 4k4 Nov 28 at 10:25
  • 1
    Checking dependencies of cache_bootstrap I could find only one core service connecting this to content entities, PermissionsHashGenerator. So I would start looking for unusual saves of users. – 4k4 Nov 28 at 10:50
  • Thanks @4k4 - how can you tell its content? I'm not quite sure what is causing it so would like to add some debug code to provide a bit more information. Any thoughts on best place for that? – jons Nov 29 at 12:25
  • You can tell by the error message. The deadlock happens in SqlContentEntityStorage->save(), which starts a database transaction and then causes a deadlock in cache_bootstrap. – 4k4 Nov 29 at 13:42
  • Thanks - anyone got a good way of reproducing (on dev)! – jons Nov 29 at 16:32
0

You can enable alternative cache implementation (with cache bootstrap) memcache or redis. Read more about deadlocks: https://support.acquia.com/hc/en-us/articles/360005253954-Fixing-database-deadlocks

  • thanks - I've looked at redis. I guess that just reduces the possibility of locks - rather than resolving the underlying DB/code logic issues? – jons Nov 29 at 12:30
0

i had this bug a while ago , and i found this fixing dead locks in drupal

ALTER TABLE semaphore ENGINE = MEMORY;
ALTER TABLE semaphore DROP PRIMARY KEY;
ALTER TABLE semaphore ADD PRIMARY KEY (name, value) USING BTREE;
ALTER TABLE semaphore ADD UNIQUE name (name) USING BTREE;
ALTER TABLE semaphore DROP INDEX value;
ALTER TABLE semaphore ADD INDEX value (value) USING BTREE;
ALTER TABLE semaphore DROP INDEX expire;
ALTER TABLE semaphore ADD INDEX expire (expire) USING BTREE;

I hope this helps , it worked for me .

  • 1
    is semaphore fix related just to D7? – jons Nov 29 at 12:26
  • i tried it on d8 too it seems to work – Malek Massoudi Dec 2 at 14:20
0

You can try add to file settings.php

$databases['default']['default']['init_commands'] = array(
  'isolation' => "SET SESSION tx_isolation='READ-COMMITTED'"
);

https://support.acquia.com/hc/en-us/articles/360005253954-Fixing-database-deadlocks

  • 1
    This seems tailored to Acquia hosting and for MySQL (thought there are similar for Postgres etc) – jons Nov 29 at 16:31

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.