jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/393705 )
Change subject: CRM-21489 resurrect deadlock re-tries
..
CRM-21489 resurrect deadlock re-tries
It turns out the code to retry 3 times in event of a deadlock is broken.
More detail on the JIRA ticket
Bug:T181450
Change-Id: Ic83168ff45a89092e7fcf688c6feb7d09deee608
---
M packages/DB/DataObject.php
1 file changed, 20 insertions(+), 7 deletions(-)
Approvals:
jenkins-bot: Verified
Ejegg: Looks good to me, approved
diff --git a/packages/DB/DataObject.php b/packages/DB/DataObject.php
index 0d74ece..dd82a87 100644
--- a/packages/DB/DataObject.php
+++ b/packages/DB/DataObject.php
@@ -2436,14 +2436,27 @@
$t= explode(' ',microtime());
$_DB_DATAOBJECT['QUERYENDTIME'] = $time = $t[0]+$t[1];
-
-for ($tries = 0;$tries < 3;$tries++) {
-
+$maxTries = defined('CIVICRM_DEADLOCK_RETRIES') ?
CIVICRM_DEADLOCK_RETRIES : 3;
+for ($tries = 0;$tries < $maxTries;$tries++) {
if ($_DB_driver == 'DB') {
-if ($tries) {
- CRM_Core_Error::debug_log_message('Attempt: ' . $tries + 1 .
' at query : ' . $string);
+ try {
+ $result = $DB->query($string);
}
-$result = $DB->query($string);
+catch (PEAR_Exception $e) {
+ // CRM-21489 If we have caught a DB lock - let it go around
the loop until our tries limit is hit.
+ // else rethrow the exception. The 2 locks we are looking at
are mysql code 1205 (lock) and
+ // 1213 (deadlock).
+ $dbErrorMessage = $e->getCause()->getUserInfo();
+ if (!stristr($dbErrorMessage, 'nativecode=1205') &&
!stristr($dbErrorMessage, 'nativecode=1213')) {
+throw $e;
+ }
+ $message = (stristr($dbErrorMessage, 'nativecode=1213') ?
'Database deadlock encountered' : 'Database lock encountered');
+ if (($tries + 1) === $maxTries) {
+throw new CRM_Core_Exception($message, 0, array('sql' =>
$string, 'trace' => $e->getTrace()));
+ }
+ CRM_Core_Error::debug_log_message("Retrying after $message
hit on attempt " . ($tries + 1) . ' at query : ' . $string);
+ continue;
+ }
} else {
switch (strtolower(substr(trim($string),0,6))) {
@@ -2460,7 +2473,7 @@
}
}
-// see if we got a failure.. - try again a few times..
+// See CRM-21489 for why I believe this is never hit.
if (!is_a($result,'PEAR_Error')) {
break;
}
--
To view, visit https://gerrit.wikimedia.org/r/393705
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic83168ff45a89092e7fcf688c6feb7d09deee608
Gerrit-PatchSet: 6
Gerrit-Project: wikimedia/fundraising/crm/civicrm
Gerrit-Branch: master
Gerrit-Owner: Eileen
Gerrit-Reviewer: Eileen
Gerrit-Reviewer: Ejegg
Gerrit-Reviewer: Mepps
Gerrit-Reviewer: jenkins-bot <>
___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits