Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
|
Postgres advisory locking factory. More...
Public Member Functions | |
__construct ($type) | |
Almighty constructor. | |
auto_release () | |
Auto release any open locks on shutdown. | |
extend_lock (lock $lock, $maxlifetime=86400) | |
Extend a lock that was previously obtained with @lock. | |
get_lock ($resource, $timeout, $maxlifetime=86400) | |
Create and get a lock. | |
is_available () | |
Is available. | |
release_lock (lock $lock) | |
Release a lock that was previously obtained with @lock. | |
supports_auto_release () | |
Will this lock type will be automatically released when a process ends. | |
supports_recursion () | |
Multiple locks for the same resource can NOT be held by a single process. | |
supports_timeout () | |
Return information about the blocking behaviour of the lock type on this platform. | |
Protected Member Functions | |
get_index_from_key ($key) | |
This function generates the unique index for a specific lock key using a sha1 prefix converted to decimal. | |
get_unique_db_instance_id () | |
Calculate a unique instance id based on the database name and prefix. | |
Protected Attributes | |
moodle_database | $db |
$db Hold a reference to the global $DB | |
int | $dblockid = -1 |
$dblockid - used as a namespace for these types of locks (separate from session locks) | |
array | $openlocks = array() |
$openlocks - List of held locks - used by auto-release | |
string | $type |
$type Used to prefix lock keys | |
Static Protected Attributes | |
static array | $lockidcache = array() |
$lockidcache - static cache for string -> int conversions required for pg advisory locks. | |
Postgres advisory locking factory.
Postgres locking implementation using advisory locks. Some important points. Postgres has 2 different forms of lock functions, some accepting a single int, and some accepting 2 ints. This implementation uses the 2 int version so that it uses a separate namespace from the session locking. The second note, is because postgres uses integer keys for locks, we first need to map strings to a unique integer. This is done using a prefix of a sha1 hash converted to an integer.
core\lock\postgres_lock_factory::__construct | ( | $type | ) |
Almighty constructor.
string | $type | - Used to prefix lock keys. |
Implements core\lock\lock_factory.
core\lock\postgres_lock_factory::auto_release | ( | ) |
Auto release any open locks on shutdown.
This is required, because we may be using persistent DB connections.
core\lock\postgres_lock_factory::extend_lock | ( | lock | $lock, |
$maxlifetime = 86400 ) |
Extend a lock that was previously obtained with @lock.
lock | $lock | - a lock obtained from this factory. |
int | $maxlifetime | - the new lifetime for the lock (in seconds). |
boolean | - true if the lock was extended. |
Implements core\lock\lock_factory.
|
protected |
This function generates the unique index for a specific lock key using a sha1 prefix converted to decimal.
string | $key |
int |
moodle_exception |
core\lock\postgres_lock_factory::get_lock | ( | $resource, | |
$timeout, | |||
$maxlifetime = 86400 ) |
Create and get a lock.
string | $resource | - The identifier for the lock. Should use frankenstyle prefix. |
int | $timeout | - The number of seconds to wait for a lock before giving up. |
int | $maxlifetime | - Unused by this lock type. |
boolean | - true if a lock was obtained. |
Implements core\lock\lock_factory.
|
protected |
Calculate a unique instance id based on the database name and prefix.
int. |
core\lock\postgres_lock_factory::is_available | ( | ) |
Is available.
boolean | - True if this lock type is available in this environment. |
Implements core\lock\lock_factory.
core\lock\postgres_lock_factory::release_lock | ( | lock | $lock | ) |
Release a lock that was previously obtained with @lock.
lock | $lock | - a lock obtained from this factory. |
boolean | - true if the lock is no longer held (including if it was never held). |
Implements core\lock\lock_factory.
core\lock\postgres_lock_factory::supports_auto_release | ( | ) |
Will this lock type will be automatically released when a process ends.
boolean | - Via shutdown handler. |
Implements core\lock\lock_factory.
core\lock\postgres_lock_factory::supports_recursion | ( | ) |
Multiple locks for the same resource can NOT be held by a single process.
boolean | - false. |
Implements core\lock\lock_factory.
core\lock\postgres_lock_factory::supports_timeout | ( | ) |
Return information about the blocking behaviour of the lock type on this platform.
boolean | - Defer to the DB driver. |
Implements core\lock\lock_factory.