[MediaWiki-commits] [Gerrit] wikimedia...civicrm[master]: CRM-21489 resurrect deadlock re-tries

2017-11-28 Thread jenkins-bot (Code Review)
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


[MediaWiki-commits] [Gerrit] wikimedia...civicrm[master]: CRM-21489 resurrect deadlock re-tries

2017-11-27 Thread Eileen (Code Review)
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 

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