Handle mysql transaction deadlocks more gracefully by making multiple attempts when they occur
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
$hAppdbLink = null;
|
||||
$hBugzillaLink = null;
|
||||
|
||||
define(MYSQL_DEADLOCK_ERRNO, 1213);
|
||||
|
||||
function query_appdb($sQuery,$sComment="")
|
||||
{
|
||||
global $hAppdbLink;
|
||||
@@ -13,9 +15,32 @@ function query_appdb($sQuery,$sComment="")
|
||||
mysql_select_db(APPS_DB, $hAppdbLink);
|
||||
}
|
||||
|
||||
$iRetries = 2;
|
||||
|
||||
/* we need to retry queries that hit transaction deadlocks */
|
||||
/* as a deadlock isn't really a failure */
|
||||
while($iRetries)
|
||||
{
|
||||
$hResult = mysql_query($sQuery, $hAppdbLink);
|
||||
if(!$hResult) query_error($sQuery, $sComment);
|
||||
if(!$hResult)
|
||||
{
|
||||
/* if this error isn't a deadlock OR if it is a deadlock and we've */
|
||||
/* run out of retries, report the error */
|
||||
$iErrno = mysql_errno();
|
||||
if(($iErrno != MYSQL_DEADLOCK_ERRNO) || (($iErrno == MYSQL_DEADLOCK_ERRNO) && ($iRetries <= 0)))
|
||||
{
|
||||
query_error($sQuery, $sComment);
|
||||
return $hResult;
|
||||
}
|
||||
|
||||
$iRetries--;
|
||||
} else
|
||||
{
|
||||
return $hResult;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user