MDL-67594 core_lock: Modify postgres get_lock() to avoid recursion

This commit is contained in:
Mihail Geshoski
2020-07-06 13:04:41 +08:00
parent 566b73fbfc
commit 83c18a2dec
+12 -5
View File
@@ -118,15 +118,15 @@ class postgres_lock_factory implements lock_factory {
}
/**
* Multiple locks for the same resource can be held by a single process.
* Multiple locks for the same resource can NOT be held by a single process.
*
* @deprecated since Moodle 4.0.
* @return boolean - Defer to the DB driver.
* @return boolean - false.
*/
public function supports_recursion() {
debugging('The function supports_recursion() is deprecated, please do not use it anymore.',
DEBUG_DEVELOPER);
return true;
return false;
}
/**
@@ -149,6 +149,7 @@ class postgres_lock_factory implements lock_factory {
/**
* Create and get a lock
*
* @param string $resource - The identifier for the lock. Should use frankenstyle prefix.
* @param int $timeout - The number of seconds to wait for a lock before giving up.
* @param int $maxlifetime - Unused by this lock type.
@@ -159,8 +160,14 @@ class postgres_lock_factory implements lock_factory {
$token = $this->get_index_from_key($this->type . '_' . $resource);
$params = array('locktype' => $this->dblockid,
'token' => $token);
if (isset($this->openlocks[$token])) {
return false;
}
$params = [
'locktype' => $this->dblockid,
'token' => $token
];
$locked = false;