appdb/include query.php
WineHQ
wineowner at wine.codeweavers.com
Wed Jul 19 14:20:16 CDT 2006
ChangeSet ID: 26668
CVSROOT: /opt/cvs-commit
Module name: appdb
Changes by: wineowner at winehq.org 2006/07/19 14:20:16
Modified files:
include : query.php
Log message:
Chris Morgan <cmorgan at alum.wpi.edu>
Handle mysql transaction deadlocks more gracefully by making multiple attempts when they occur
Patch: http://cvs.winehq.org/patch.py?id=26668
Old revision New revision Changes Path
1.6 1.7 +29 -4 appdb/include/query.php
Index: appdb/include/query.php
diff -u -p appdb/include/query.php:1.6 appdb/include/query.php:1.7
--- appdb/include/query.php:1.6 19 Jul 2006 19:20:16 -0000
+++ appdb/include/query.php 19 Jul 2006 19:20:16 -0000
@@ -2,6 +2,8 @@
$hAppdbLink = null;
$hBugzillaLink = null;
+define(MYSQL_DEADLOCK_ERRNO, 1213);
+
function query_appdb($sQuery,$sComment="")
{
global $hAppdbLink;
@@ -12,10 +14,33 @@ function query_appdb($sQuery,$sComment="
$hAppdbLink = mysql_connect(APPS_DBHOST, APPS_DBUSER, APPS_DBPASS,true);
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;
}
/*
More information about the wine-cvs
mailing list