Eileen has uploaded a new change for review. ( 
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

Change-Id: Ic83168ff45a89092e7fcf688c6feb7d09deee608
---
M packages/DB/DataObject.php
1 file changed, 13 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm/civicrm 
refs/changes/05/393705/1

diff --git a/packages/DB/DataObject.php b/packages/DB/DataObject.php
index 0d74ece..37a1961 100644
--- a/packages/DB/DataObject.php
+++ b/packages/DB/DataObject.php
@@ -2436,14 +2436,21 @@
         $t= explode(' ',microtime());
         $_DB_DATAOBJECT['QUERYENDTIME'] = $time = $t[0]+$t[1];
 
-
+        $maxTries = is_defined('CIVICRM_DEADLOCK_RETRIES') ? 
CIVICRM_DEADLOCK_RETRIES : 3;
         for ($tries = 0;$tries < 3;$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) {
+                  // If we have caught a deadlock - let it go around the loop 
until our tries limit is hit.
+                  // else rethrow the exception.
+                  if (!stristr($e->getCause()->getUserInfo(), 
'nativecode=1205') || ($tries + 1) === $maxTries) {
+                    throw $e;
+                  }
+                  CRM_Core_Error::debug_log_message('Retrying after deadlock 
hit on attempt ' . $tries + 1 . ' at query : ' . $string);
+                  continue;
+                }
 
             } else {
                 switch (strtolower(substr(trim($string),0,6))) {
@@ -2460,7 +2467,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: newchange
Gerrit-Change-Id: Ic83168ff45a89092e7fcf688c6feb7d09deee608
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm/civicrm
Gerrit-Branch: master
Gerrit-Owner: Eileen <emcnaugh...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to