I think using a lock inside of _field_info_collate_types can help to prevent deadlocks.

Comments

mikeytown2’s picture

Status: Active » Needs review
StatusFileSize
new650 bytes
mikeytown2’s picture

Title: Deadlocks occur on cache_field field_info_types:en INSERT » Deadlocks occur in cache_field table.
Status: Needs review » Needs work

Looks like cache_field operations can cause deadlocks in other places as well.

field.info.class.inc
field_info:field_map
field_info:fields
field_info:instances
field_info:bundle:$entity_type:$bundle
field_info:bundle_extra:$entity_type:$bundle

field.info.inc
field_info_types:$langcode

field.attach.inc
field:$entity_type:$id

The deadlock in field.attach.inc should not be fixed; if there is a collision one of the inserts/updates should be rolled back. All others should be fixed.

mikeytown2’s picture

Status: Needs work » Needs review
StatusFileSize
new2.98 KB
fabianx’s picture

Status: Needs review » Reviewed & tested by the community

This is still helpful to have for the core cache backends.

**RTBC**

mikeytown2’s picture

I would like to add that this patch is not applicable to D8 as the field_info keys are being set in their own cache table now and thus the cache_field table doesn't have this issue.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 3: drupal-2193149-3-cache_field-lock.patch, failed testing.

Status: Needs work » Needs review
mikeytown2’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 3: drupal-2193149-3-cache_field-lock.patch, failed testing.

Status: Needs work » Needs review
mikeytown2’s picture

Issue tags: +Performance, +innoDB, +database cache
dcam’s picture

Status: Needs review » Reviewed & tested by the community
anybody’s picture

Whao, great progress! I'm looking forward to seeing this in core soon :)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 3: drupal-2193149-3-cache_field-lock.patch, failed testing.

Status: Needs work » Needs review
dcam’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 3: drupal-2193149-3-cache_field-lock.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: drupal-2193149-3-cache_field-lock.patch, failed testing.

Status: Needs work » Needs review
dcam’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 3: drupal-2193149-3-cache_field-lock.patch, failed testing.

David_Rothstein’s picture

Status: Needs work » Reviewed & tested by the community

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x - thanks!

I had to think about this one for a while before committing it... I think the patch makes sense, though. I'd feel better if anyone can confirm that they are running this on a production site with no problems so far :)

  • David_Rothstein committed af4cde1 on 7.x
    Issue #2193149 by mikeytown2: Fixed Deadlocks occur in cache_field table...
joelpittet’s picture

@David_Rothstein I am running this on a production server. So far no problems and no deadlocks, have had it applied since Oct 29th. So not that long.

David_Rothstein’s picture

Awesome, thanks @joelpittet.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jsheller’s picture

I have a question to this. On our website Core 7.34 is currently installed (since middle of december) but when I click "Clear Cache" on the administration interface or when I add a new field to a content type (what seems to clear the cache itself) I still get this deadlock. Do I miss something? What can I do? After the deadlock the mysql server connection is lost and the website is not reachable. Thank you very much!

brad.bulger’s picture

I am still getting this deadlock error with this change in place on 7.34 as well.

mikeytown2’s picture

This issue did fix part of the problem; it does reduce the deadlock occurrences. Odds are you're experiencing this issue as well #2222635: Waiting for table metadata lock on cache_field table.

I am working on a module that fixes the rest of the cache issues when using the database as the cache backend; still not ready but getting closer https://www.drupal.org/project/apdqc. Think I'll put out a beta 1 by the end of the week if things at work are smooth going. I will say that as of right now using the module and fixing all the issues that the status report page complains about will make it so the cache tables no longer lock. We had an issue on production where APDQC slowed down the site (all cache queries took right around 75ms) but we never got a database lock or a metadata lock as a result even thought the load spiked to 50 on the MySQL box #2416895: Fix issues when ran on a live production server. Once all the module's issues, except for session handling, is fixed expect a beta 1 to be released.

gopisathya’s picture

We are using 7.41 and still get this error during production deployment

PDOException: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction: DELETE FROM {cache_field}

We do use "drush fra -y" during deployment