Handle mysql transaction deadlocks more gracefully by making multiple attempts when they occur

This commit is contained in:
Chris Morgan
2006-07-19 19:20:16 +00:00
committed by WineHQ
parent 55065a254c
commit 311081fda5

View File

@@ -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);
}
$hResult = mysql_query($sQuery, $hAppdbLink);
if(!$hResult) query_error($sQuery, $sComment);
return $hResult;
$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)
{
/* 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;
}
/*