Drupal and transient MySQL errors

A while ago Arjen Lentz blogged about transient MySQL errors that can occur when using a transactional storage engine, like say InnoDB.

Error: No error occurred.Since I'm a fan of the reliability and automated recovery that InnoDB provides, I use it for all the Drupals that I host.  However, on a very busy site, this may lead to deadlocks. These in turn lead to users seeing errors, which is something I'd like to avoid. Especially if the error could be prevented.

What I've done to make use of these error codes is change the _db_query() function in includes/database.mysql.inc and wrap the call to mysql_query() in a loop.

The function now checks the returned error code and if the code indicates a transient error, it will try to rerun the query after sleeping for 50 milliseconds.  It will try each query up to three times before giving up, though you can change this by modifying DRUPAL_MYSQL_QUERY_RETRY in modules/system/system.module.

AttachmentSize
File drupal-mysql-error-retry.patch2.65 KB

Add new comment