Under heavy load, Drupal occasionally encounters MySQL Deadlock errors. The MySQL documentation (http://dev.mysql.com/doc/refman/5.0/en/innodb-deadlocks.html) states:

you must write your applications so that they are always prepared to re-issue a transaction if it gets rolled back because of a deadlock.

Currently, instead of re-issuing the transaction when a deadlock is encountered as MySQL suggests, Drupal / PDO fails with a fatal error. Instead, the transaction should be retried.

I would propose that when we encounter any MySQL error we do the following
1. Check for the existence of the string "try restarting transaction" in the error. This is MySQL indicating that the transaction can be retried.
2. Wait 50 milliseconds (or more or less, this should likely be tunable)
3. Retry and increment a "retry" counter
5. Give up after 5 retries (more or less, tunable)

Comments

jhodgdon’s picture

jhodgdon’s picture

Issue summary: View changes

fixing hmtl