From 7e899aeb21a27e8b37ac7b38751ce00886bdbda8 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 24 Feb 2023 11:29:53 +1300 Subject: [PATCH] Remove legacy handling of locks for discontinued mysql/mariaDB versions --- CRM/Core/Lock.php | 28 ---------------------------- CRM/Dedupe/Merger.php | 3 --- CRM/Utils/SQL.php | 24 ------------------------ 3 files changed, 55 deletions(-) diff --git a/CRM/Core/Lock.php b/CRM/Core/Lock.php index 3a3c220e19..67adc99c02 100644 --- a/CRM/Core/Lock.php +++ b/CRM/Core/Lock.php @@ -171,9 +171,6 @@ class CRM_Core_Lock implements \Civi\Core\Lock\LockInterface { */ public function acquire($timeout = NULL) { if (!$this->_hasLock) { - if (!CRM_Utils_SQL::supportsMultipleLocks() && self::$jobLog && CRM_Core_DAO::singleValueQuery("SELECT IS_USED_LOCK( '" . self::$jobLog . "')")) { - return $this->hackyHandleBrokenCode(self::$jobLog); - } $query = "SELECT GET_LOCK( %1, %2 )"; $params = [ @@ -235,29 +232,4 @@ class CRM_Core_Lock implements \Civi\Core\Lock\LockInterface { return $this->_hasLock; } - /** - * CRM-12856 locks were originally set up for jobs, but the concept was extended to caching & groups without - * understanding that would undermine the job locks (because grabbing a lock implicitly releases existing ones) - * this is all a big hack to mitigate the impact of that - but should not be seen as a fix. Not sure correct fix - * but maybe locks should be used more selectively? Or else we need to handle is some cool way that Tim is yet to write :-) - * if we are running in the context of the cron log then we would rather die (or at least let our process die) - * than release that lock - so if the attempt is being made by setCache or something relatively trivial - * we'll just return TRUE, but if it's another job then we will crash as that seems 'safer' - * - * @param string $jobLog - * @throws CRM_Core_Exception - * @return bool - */ - public function hackyHandleBrokenCode($jobLog) { - if (stristr($this->_name, 'job')) { - \Civi::log()->debug('lock acquisition for ' . $this->_name . '(' . $this->_id . ')' . ' attempted when ' . $jobLog . ' is not released'); - throw new CRM_Core_Exception('lock acquisition for ' . $this->_name . '(' . $this->_id . ')' . ' attempted when ' . $jobLog . ' is not released'); - } - if (defined('CIVICRM_LOCK_DEBUG')) { - \Civi::log()->debug('(CRM-12856) faking lock for ' . $this->_name . '(' . $this->_id . ')'); - } - $this->_hasLock = TRUE; - return TRUE; - } - } diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index 9bc24aa442..7171b54b22 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -2962,9 +2962,6 @@ ORDER BY civicrm_custom_group.weight, */ protected static function getLocksOnContacts($contacts):array { $locks = []; - if (!CRM_Utils_SQL::supportsMultipleLocks()) { - return $locks; - } foreach ($contacts as $contactID) { $lock = Civi::lockManager()->acquire("data.core.contact.{$contactID}"); if ($lock->isAcquired()) { diff --git a/CRM/Utils/SQL.php b/CRM/Utils/SQL.php index 1ca298e96a..981d7cb6e5 100644 --- a/CRM/Utils/SQL.php +++ b/CRM/Utils/SQL.php @@ -135,30 +135,6 @@ class CRM_Utils_SQL { return TRUE; } - /** - * Does the DB version support mutliple locks per - * - * https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_get-lock - * - * This is a conservative measure to introduce the change which we expect to deprecate later. - * - * @todo we only check mariadb & mysql right now but maybe can add percona. - */ - public static function supportsMultipleLocks() { - static $isSupportLocks = NULL; - if (!isset($isSupportLocks)) { - $version = self::getDatabaseVersion(); - if (stripos($version, 'mariadb') !== FALSE) { - $isSupportLocks = version_compare($version, '10.0.2', '>='); - } - else { - $isSupportLocks = version_compare($version, '5.7.5', '>='); - } - } - - return $isSupportLocks; - } - /** * Get the version string for the database. * -- 2.25.1