Seeing deadlocks on views_content_cache table.
START TRANSACTION;
INSERT into views_content_cache VALUES (UNIX_TIMESTAMP(), NULL, NULL, 'conversation', 'node_changed', NULL, NULL, NULL, NULL);
This locks all rows with 'conversation' as c3 or 'node_changed' as c4. For non-unique indexes, innodb does exclusive locks for all rows with that value.
In another session
All these
DELETE FROM views_content_cache WHERE c3 = 'conversation' AND c4 = 'node_changed'
DELETE FROM views_content_cache WHERE c4 = 'node_changed'
DELETE FROM views_content_cache WHERE c3 = 'blog' AND c4 = 'node_changed'
DELETE FROM views_content_cache WHERE c3 = 'blog' AND c4 = 'node_changed' and c5 = 1;
Will produce "ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction"; not deadlock yet (but haven't quite wrapped my head around how to get a deadlock), but can see why the delete/inserts can slow down a site under heavy load.
To try and clarify further, Using "DELETE FROM views_content_cache WHERE c3 = 'blog' AND c4 = 'node_changed'" as an example, the delete's need exclusive locks on the rows where c3 = 'blog' or c4 'node_changed', but cannot get the c4 'node_changed' lock as the INSERT has those rather broad locks.
So a site with a lot content being posted, the insert/delete lock waits start piling up and getting slower and slower.
Comment | File | Size | Author |
---|---|---|---|
#33 | views_content_cache-deadlocks-1890470-33.patch | 2.9 KB | HitchShock |
| |||
#30 | views-content-cache-deadlocks-1890470-30-D7.patch | 1.64 KB | sokru |
#23 | views_content_cache-deadlocks-1890470-23.patch | 926 bytes | dnotes |
| |||
#17 | views_content_cache-1890470-deadlocks.patch | 1.12 KB | khoomy |
#10 | views_content_cache-1890470-deadlocks.patch | 2.4 KB | Steven Jones |
Comments
Comment #1
generalredneckI can confirm this... having the same on 7.x-3.0-alpha2
Comment #2
hefox CreditAttribution: hefox commentedhttp://gyazo.com/6e3b2f39362a1b4378a9d5b86d8f208a
I can confirm this on d.o
Comment #3
generalredneckha ha, Nice! I may ahve to look into this and see if there is a way to fix it...
Comment #4
Steven Jones CreditAttribution: Steven Jones commentedYeah...we can probably do better here, and we can probably also leverage the D7 DB API while we're at it.
Comment #5
Steven Jones CreditAttribution: Steven Jones commentedComment #6
Steven Jones CreditAttribution: Steven Jones commentedReplace the delete/insert with a merge query, which adds a transaction, but should mean that we can do an UPDATE query most of the time.
Comment #7
Steven Jones CreditAttribution: Steven Jones commentedBad patch file.
Comment #8
generalredneckThis "may" be a fix, and this comment may be a separate issue, but why doesn't this module use the Cache API?
Comment #9
Steven Jones CreditAttribution: Steven Jones commentedThis is using the cache API for the bits that are using a cache (we use it via views).
This error is in a bit of code that in D8 would be using the 'state' system, because it isn't a cache thing, it's a thing that we want to keep around permanently.
I think the patch in #7 is good, but just need to check that it actually keeps the functionality of the module the same.
Comment #10
Steven Jones CreditAttribution: Steven Jones commentedActually, add some more assertions to the tests, so that we make sure the merge query is doing what it should.
Comment #11
Steven Jones CreditAttribution: Steven Jones commentedThanks everyone, I've pushed the latest patch into 7.x-3.x
Comment #12
nnewton CreditAttribution: nnewton commentedI'd like to re-open this. We have deployed this module on drupal.org and are having fairly large issues with deadlocks around this table. Particularly around project_issue updates, as every one requires a X RECORD LOCK on a single row in this table to update the timestamp. The db_merge here doesn't really solve the problem.
I'm trying to get you some debugging information. Currently its looking a lot like the separate indexes for c1/c2/c3 are causing issues, but that is obviously not at all conclusive.
Comment #13
JeffSheltren CreditAttribution: JeffSheltren commentedre-opening
Comment #14
nnewton CreditAttribution: nnewton commentedAdditional information:
The column/index split is indeed contributing to the issue. Has converting this from a c1,c2,cN split to a single combined cache-id ever been considered? It seems like this could be a two column table, (varchar,timestamp). However, I obviously have just started reading the module and likely don't know the specifics.
Comment #15
Kristen Polfix typo
Comment #16
MixologicAdding a related issue in the infrastructure queue.
Comment #17
khoomy CreditAttribution: khoomy commentedI have same issue as:
PDOException: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction: UPDATE {views_content_cache} SET timestamp=:db_update_placeholder_0
I fixed this by adding merge query within try catch block
Comment #18
jason.fisher CreditAttribution: jason.fisher commentedI believe this patch is working for me. I did have to modify the directories by hand in the patch to get it to apply.
Comment #19
mgiffordComment #21
MediaFormat CreditAttribution: MediaFormat commentedGetting this error with Version: 7.x-3.0-alpha3+1-dev
PDOException : SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction: UPDATE {views_content_cache} SET timestamp=:db_update_placeholder_0 WHERE ( (c2 = :db_condition_placeholder_0) AND (c3 = :db_condition_placeholder_1) ); Array ( [:db_update_placeholder_0] => 1458846330 [:db_condition_placeholder_0] => video [:db_condition_placeholder_1] => node_changed ) in views_content_cache_update_set() (line 128 in /sites/all/modules/views_content_cache/views_content_cache.module).
Comment #22
DamienMcKennaComment #23
dnotes CreditAttribution: dnotes commentedUpdating the patch from #17 so that it will apply cleanly. I wonder at this approach; won't a try/catch just trade database lockouts for failed updates, resulting in views being cached too long?
Comment #24
dnotes CreditAttribution: dnotes commentedComment #25
bigjim CreditAttribution: bigjim commentedI'ld be curious to hear thoughts on @nnewton's question in #14 above? Seems like that would allow the use of the default cache back-end, no?
Comment #26
MustangGB CreditAttribution: MustangGB commentedI've noticed that if you update many nodes in the same request a merge is executed for each of them, which presumably locks the table for longer than necessary, resulting in higher deadlock probability.
How about only updating a maximum of once per map per request.
A quick proof of concept:
Comment #27
dchatry#26 seems to be working, I don't get deadlocks anymore, I will report back once I've tested it further.
Comment #28
Chris Matthews CreditAttribution: Chris Matthews commenteddchatry - were you able to further test the proof of concept in #26?
Comment #29
dchatryYes, the deadlocks are gone and I don't see any obvious additional issue.
Comment #30
sokru CreditAttribution: sokru as a volunteer commentedPatch from #26, kudos to @MustangGB.
Comment #31
HitchShockDid a simple rework of the last patch
Comment #33
HitchShockAlso, updated tests
Comment #34
HitchShock