mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
Merge branch 'MDL-67594-master-2' of git://github.com/mihailges/moodle
This commit is contained in:
commit
3bf4744303
6
cache/upgrade.txt
vendored
6
cache/upgrade.txt
vendored
@ -1,6 +1,12 @@
|
||||
This files describes API changes in /cache/stores/* - cache store plugins.
|
||||
Information provided here is intended especially for developers.
|
||||
|
||||
=== 4.0 ===
|
||||
* The function supports_recursion() from the lock_factory interface has been deprecated including the related implementations.
|
||||
* The function extend_lock() from the lock_factory interface has been deprecated without replacement including the related
|
||||
implementations.
|
||||
* The function extend() from the lock class has been deprecated without replacement.
|
||||
|
||||
=== 3.9 ===
|
||||
* The record_cache_hit/miss/set methods now take a cache_store instead of a cache_definition object
|
||||
|
||||
|
@ -91,9 +91,13 @@ class db_record_lock_factory implements lock_factory {
|
||||
|
||||
/**
|
||||
* Multiple locks for the same resource can be held by a single process.
|
||||
*
|
||||
* @deprecated since Moodle 4.0.
|
||||
* @return boolean - False - not process specific.
|
||||
*/
|
||||
public function supports_recursion() {
|
||||
debugging('The function supports_recursion() is deprecated, please do not use it anymore.',
|
||||
DEBUG_DEVELOPER);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -187,11 +191,16 @@ class db_record_lock_factory implements lock_factory {
|
||||
|
||||
/**
|
||||
* Extend a lock that was previously obtained with @lock.
|
||||
*
|
||||
* @deprecated since Moodle 4.0.
|
||||
* @param lock $lock - a lock obtained from this factory.
|
||||
* @param int $maxlifetime - the new lifetime for the lock (in seconds).
|
||||
* @return boolean - true if the lock was extended.
|
||||
*/
|
||||
public function extend_lock(lock $lock, $maxlifetime = 86400) {
|
||||
debugging('The function extend_lock() is deprecated, please do not use it anymore.',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
$now = time();
|
||||
$expires = $now + $maxlifetime;
|
||||
$params = array('expires' => $expires,
|
||||
|
@ -108,9 +108,13 @@ class file_lock_factory implements lock_factory {
|
||||
|
||||
/**
|
||||
* Multiple locks for the same resource cannot be held from a single process.
|
||||
*
|
||||
* @deprecated since Moodle 4.0.
|
||||
* @return boolean - False
|
||||
*/
|
||||
public function supports_recursion() {
|
||||
debugging('The function supports_recursion() is deprecated, please do not use it anymore.',
|
||||
DEBUG_DEVELOPER);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -188,11 +192,15 @@ class file_lock_factory implements lock_factory {
|
||||
|
||||
/**
|
||||
* Extend a lock that was previously obtained with @lock.
|
||||
*
|
||||
* @deprecated since Moodle 4.0.
|
||||
* @param lock $lock - not used
|
||||
* @param int $maxlifetime - not used
|
||||
* @return boolean - true if the lock was extended.
|
||||
*/
|
||||
public function extend_lock(lock $lock, $maxlifetime = 86400) {
|
||||
debugging('The function extend_lock() is deprecated, please do not use it anymore.',
|
||||
DEBUG_DEVELOPER);
|
||||
// Not supported by this factory.
|
||||
return false;
|
||||
}
|
||||
|
@ -76,9 +76,12 @@ class installation_lock_factory implements lock_factory {
|
||||
/**
|
||||
* Multiple locks for the same resource cannot be held from a single process.
|
||||
*
|
||||
* @deprecated since Moodle 4.0.
|
||||
* @return boolean - False
|
||||
*/
|
||||
public function supports_recursion() {
|
||||
debugging('The function supports_recursion() is deprecated, please do not use it anymore.',
|
||||
DEBUG_DEVELOPER);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -115,11 +118,14 @@ class installation_lock_factory implements lock_factory {
|
||||
/**
|
||||
* Extend a lock that was previously obtained with @lock.
|
||||
*
|
||||
* @deprecated since Moodle 4.0.
|
||||
* @param lock $lock - not used
|
||||
* @param int $maxlifetime - not used
|
||||
* @return boolean - true if the lock was extended.
|
||||
*/
|
||||
public function extend_lock(lock $lock, $maxlifetime = 86400) {
|
||||
debugging('The function extend_lock() is deprecated, please do not use it anymore.',
|
||||
DEBUG_DEVELOPER);
|
||||
// Not supported by this factory.
|
||||
return false;
|
||||
}
|
||||
|
@ -80,10 +80,15 @@ class lock {
|
||||
|
||||
/**
|
||||
* Extend the lifetime of this lock. Not supported by all factories.
|
||||
*
|
||||
* @deprecated since Moodle 4.0.
|
||||
* @param int $maxlifetime - the new lifetime for the lock (in seconds).
|
||||
* @return bool
|
||||
*/
|
||||
public function extend($maxlifetime = 86400) {
|
||||
debugging('The function extend() is deprecated, please do not use it anymore.',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
if ($this->factory) {
|
||||
return $this->factory->extend_lock($this, $maxlifetime);
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ interface lock_factory {
|
||||
/**
|
||||
* Supports recursion.
|
||||
*
|
||||
* @deprecated since Moodle 4.0.
|
||||
* @return boolean - True if attempting to get 2 locks on the same resource will "stack"
|
||||
*/
|
||||
public function supports_recursion();
|
||||
@ -98,6 +99,7 @@ interface lock_factory {
|
||||
/**
|
||||
* Extend the timeout on a held lock.
|
||||
*
|
||||
* @deprecated since Moodle 4.0.
|
||||
* @param lock $lock - lock obtained from this factory
|
||||
* @param int $maxlifetime - new max time to hold the lock
|
||||
* @return boolean - True if the lock was extended.
|
||||
|
@ -106,9 +106,12 @@ class mysql_lock_factory implements lock_factory {
|
||||
* Hard coded to false and workaround inconsistent support in different
|
||||
* versions of MySQL / MariaDB.
|
||||
*
|
||||
* @deprecated since Moodle 4.0.
|
||||
* @return boolean - false
|
||||
*/
|
||||
public function supports_recursion() {
|
||||
debugging('The function supports_recursion() is deprecated, please do not use it anymore.',
|
||||
DEBUG_DEVELOPER);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -165,11 +168,15 @@ class mysql_lock_factory implements lock_factory {
|
||||
|
||||
/**
|
||||
* Extend a lock that was previously obtained with @lock.
|
||||
*
|
||||
* @deprecated since Moodle 4.0.
|
||||
* @param lock $lock - a lock obtained from this factory.
|
||||
* @param int $maxlifetime - the new lifetime for the lock (in seconds).
|
||||
* @return boolean - true if the lock was extended.
|
||||
*/
|
||||
public function extend_lock(lock $lock, $maxlifetime = 86400) {
|
||||
debugging('The function extend_lock() is deprecated, please do not use it anymore.',
|
||||
DEBUG_DEVELOPER);
|
||||
// Not supported by this factory.
|
||||
return false;
|
||||
}
|
||||
|
@ -118,11 +118,15 @@ class postgres_lock_factory implements lock_factory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiple locks for the same resource can be held by a single process.
|
||||
* @return boolean - Defer to the DB driver.
|
||||
* Multiple locks for the same resource can NOT be held by a single process.
|
||||
*
|
||||
* @deprecated since Moodle 4.0.
|
||||
* @return boolean - false.
|
||||
*/
|
||||
public function supports_recursion() {
|
||||
return true;
|
||||
debugging('The function supports_recursion() is deprecated, please do not use it anymore.',
|
||||
DEBUG_DEVELOPER);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -145,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.
|
||||
@ -155,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;
|
||||
|
||||
@ -194,11 +205,15 @@ class postgres_lock_factory implements lock_factory {
|
||||
|
||||
/**
|
||||
* Extend a lock that was previously obtained with @lock.
|
||||
*
|
||||
* @deprecated since Moodle 4.0.
|
||||
* @param lock $lock - a lock obtained from this factory.
|
||||
* @param int $maxlifetime - the new lifetime for the lock (in seconds).
|
||||
* @return boolean - true if the lock was extended.
|
||||
*/
|
||||
public function extend_lock(lock $lock, $maxlifetime = 86400) {
|
||||
debugging('The function extend_lock() is deprecated, please do not use it anymore.',
|
||||
DEBUG_DEVELOPER);
|
||||
// Not supported by this factory.
|
||||
return false;
|
||||
}
|
||||
|
@ -70,35 +70,35 @@ class lock_testcase extends advanced_testcase {
|
||||
$this->assertNotEmpty($lock1, 'Get a lock');
|
||||
|
||||
if ($lockfactory->supports_timeout()) {
|
||||
if ($lockfactory->supports_recursion()) {
|
||||
$lock2 = $lockfactory->get_lock('abc', 2);
|
||||
// Attempt to obtain a lock within a 2 sec timeout.
|
||||
$durationlock2 = -microtime(true);
|
||||
$lock2 = $lockfactory->get_lock('abc', 2);
|
||||
$durationlock2 += microtime(true);
|
||||
|
||||
if (!$lock2) { // If the lock was not obtained.
|
||||
$this->assertFalse($lock2, 'Cannot get a stacked lock');
|
||||
// This should timeout after 2 seconds.
|
||||
$this->assertTrue($durationlock2 < 2.5, 'Lock should timeout after no more than 2 seconds');
|
||||
} else {
|
||||
$this->assertNotEmpty($lock2, 'Get a stacked lock');
|
||||
$this->assertTrue($lock2->release(), 'Release a stacked lock');
|
||||
}
|
||||
|
||||
// Attempt to obtain a lock within a 0 sec timeout.
|
||||
$durationlock2 = -microtime(true);
|
||||
$lock2 = $lockfactory->get_lock('abc', 0);
|
||||
$durationlock2 += microtime(true);
|
||||
|
||||
if (!$lock2) { // If the lock was not obtained.
|
||||
// This should timeout almost instantly.
|
||||
$this->assertTrue($durationlock2 < 0.100, 'Lock should timeout almost instantly < 100ms');
|
||||
} else {
|
||||
// This stacked lock should be gained almost instantly.
|
||||
$duration = -microtime(true);
|
||||
$lock3 = $lockfactory->get_lock('abc', 0);
|
||||
$duration += microtime(true);
|
||||
$lock3->release();
|
||||
$this->assertTrue($duration < 0.100, 'Lock should be gained almost instantly');
|
||||
$this->assertTrue($durationlock2 < 0.100, 'Lock should be gained almost instantly');
|
||||
$lock2->release();
|
||||
|
||||
// We should also assert that locks fail instantly if locked
|
||||
// from another process but this is hard to unit test.
|
||||
|
||||
} else {
|
||||
// This should timeout after 2 seconds.
|
||||
$duration = -microtime(true);
|
||||
$lock2 = $lockfactory->get_lock('abc', 2);
|
||||
$duration += microtime(true);
|
||||
$this->assertFalse($lock2, 'Cannot get a stacked lock');
|
||||
$this->assertTrue($duration < 2.5, 'Lock should timeout after no more than 2 seconds');
|
||||
|
||||
// This should timeout almost instantly.
|
||||
$duration = -microtime(true);
|
||||
$lock2 = $lockfactory->get_lock('abc', 0);
|
||||
$duration += microtime(true);
|
||||
$this->assertFalse($lock2, 'Cannot get a stacked lock');
|
||||
$this->assertTrue($duration < 0.100, 'Lock should timeout almost instantly < 100ms');
|
||||
}
|
||||
}
|
||||
// Release the lock.
|
||||
|
Loading…
x
Reference in New Issue
Block a user