Hello,
When regenerating the entity_usage statistics I oftentimes get this error:
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction: INSERT INTO {entity_usage} (target_id, target_type, source_id, source_type, source_langcode, source_vid, method, field_name, count) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8); Array ( [:db_insert_placeholder_0] => 988611 [:db_insert_placeholder_1] => media [:db_insert_placeholder_2] => 277906 [:db_insert_placeholder_3] => node [:db_insert_placeholder_4] => da [:db_insert_placeholder_5] => 2194026 [:db_insert_placeholder_6] => entity_reference [:db_insert_placeholder_7] => field_images [:db_insert_placeholder_8] => 1 ) i Drupal\entity_usage\EntityUsage->registerUsage() (linje 137 af docroot/modules/contrib/entity_usage/src/EntityUsage.php).
Database is mysql, site has 6000+ nodes with an average of 10 revisions. Last time I checked there were +-650.000 records in the entity_usage table, so we're talking about a lot of data here.
Does anyone know what might cause this and how to fix it? Should I just up some (memory) limit? Even though that will probably just hide the error instead of fixing it.
Comments
Comment #1
Anonymous (not verified) commentedsamspinoy created an issue. See original summary.
Comment #2
Anonymous (not verified) commentedComment #3
marcoscanoHm, DB lock errors are tricky to troubleshoot... I haven't experienced this, so I don't have anything specific in mind right now.
Do you need / want to store all the usage? If you believe the size of the table is the issue on your DB setup, you can try to adjust the settings on
/admin/config/entity-usage/settingsto allow tracking only of the entity types you want, and then trigger the usage batch again. Hope it helps!Comment #4
Anonymous (not verified) commentedYeah I only track entities that need to be tracked. But I have 6000+ nodes and since tracking revisions cannot be turned off, it's still huge.
I take it there is no way to not track revisions?
Comment #5
marcoscanoNo. In the 1.x branch we didn't track revisions, but that's a bad solution when your site has revisioning enabled, once it won't correspond then to the reality. For instance:
- Node A rev. 1 points to Node B
- Node A rev. 2 removes reference to Node B
- You delete Node B, once there are no tracked usages for it
- You try to roll-back Node A to rev. 1, and then you have a broken reference.
Comment #6
Anonymous (not verified) commentedBut what does that scenario have to do with this module? You mean the tracking would be wrong, making users think there are no more usages for node B?
While I see your point, most of the editors on this project don't bother checking revisions and doing rollbacks. Also if it can shrink my db table by 90%, it's worth the risk.
So how could I go about updating a usage record each time an entity gets saved, rather than adding a new one for each revision? Is this logic in a plugin that can be overwritten?
Comment #7
marcoscanoYou can use the 1.x branch, where no revisions are tracked, and only one usage per translation is recorded (if multiple translations reference the target entity).
Comment #8
Anonymous (not verified) commentedI have actually managed to get this to work with the implementation of the following two hooks:
This only keeps one record per entity and keeps records nicely up to date with update/delete. You probably think I am butchering your module :) but this works for my use-case.
Comment #9
Anonymous (not verified) commentedComment #10
niklanThis is somehow related to caching. drush cr solve the problem. I don't save logs but I got this problem at first in code, but when I try to remove users via UI, this also happens but cache was there also.