|
MediaWiki master
|
Resource locking handling. More...
Inherited by Wikimedia\LockManager\FSLockManager, Wikimedia\LockManager\NullLockManager, and Wikimedia\LockManager\QuorumLockManager.

Public Member Functions | |
| __construct (array $config) | |
| Construct a new instance from configuration. | |
| lock (array $paths, $type=self::LOCK_EX, $timeout=0) | |
| Lock the resources at the given abstract paths. | |
| lockByType (array $pathsByType, $timeout=0) | |
| Lock the resources at the given abstract paths. | |
| unlock (array $paths, $type=self::LOCK_EX) | |
| Unlock the resources at the given abstract paths. | |
| unlockByType (array $pathsByType) | |
| Unlock the resources at the given abstract paths. | |
Public Attributes | |
| const | LOCK_EX = 3 |
| const | LOCK_SH = 1 |
| Lock types; stronger locks have higher values. | |
| const | LOCK_UW = 2 |
Protected Member Functions | |
| doLock (array $paths, $type) | |
| Lock resources with the given keys and lock type. | |
| doLockByType (array $pathsByType) | |
| doUnlock (array $paths, $type) | |
| Unlock resources with the given keys and lock type. | |
| doUnlockByType (array $pathsByType) | |
| normalizePathsByType (array $pathsByType) | |
| Normalize the $paths array by converting LOCK_UW locks into the appropriate type and removing any duplicated paths for each lock type. | |
| sha1Base36Absolute ( $path) | |
| Get the base 36 SHA-1 of a string, padded to 31 digits. | |
Protected Attributes | |
| string | $domain |
| domain (usually wiki ID) | |
| array | $locksHeld = [] |
| Map of (resource path => lock type => count) | |
| int | $lockTTL |
| maximum time locks can be held | |
| array | $lockTypeMap |
| Mapping of lock types to the type actually used. | |
| LoggerInterface | $logger |
| string | $session |
| Random 32-char hex number. | |
| const | MAX_LOCK_TTL = 2 * 3600 |
| Max expected lock expiry in any context. | |
| const | MIN_LOCK_TTL = 5 |
| Minimum lock TTL. | |
Resource locking handling.
Locks on resource keys can either be shared or exclusive.
Implementations must keep track of what is locked by this process in-memory and support nested locking calls (using reference counting). At least LOCK_UW and LOCK_EX must be implemented. LOCK_SH can be a no-op. Locks should either be non-blocking or have low wait timeouts.
Subclasses should avoid throwing exceptions at all costs.
Definition at line 36 of file LockManager.php.
| Wikimedia\LockManager\LockManager::__construct | ( | array | $config | ) |
Construct a new instance from configuration.
| array | $config | Parameters include:
|
Reimplemented in Wikimedia\LockManager\FSLockManager, Wikimedia\LockManager\MemcLockManager, and Wikimedia\LockManager\RedisLockManager.
Definition at line 82 of file LockManager.php.
|
abstractprotected |
Lock resources with the given keys and lock type.
| array | $paths | List of paths |
| int | $type | LockManager::LOCK_* constant |
Reimplemented in Wikimedia\LockManager\FSLockManager, Wikimedia\LockManager\NullLockManager, and Wikimedia\LockManager\QuorumLockManager.
Referenced by Wikimedia\LockManager\LockManager\doLockByType().
|
protected |
| array | $pathsByType | Map of LockManager::LOCK_* constants to lists of paths |
Reimplemented in Wikimedia\LockManager\QuorumLockManager.
Definition at line 209 of file LockManager.php.
References Wikimedia\LockManager\LockManager\doLock(), and Wikimedia\LockManager\LockManager\doUnlock().
Referenced by Wikimedia\LockManager\LockManager\lockByType().
|
abstractprotected |
Unlock resources with the given keys and lock type.
| array | $paths | List of paths |
| int | $type | LockManager::LOCK_* constant |
Reimplemented in Wikimedia\LockManager\FSLockManager, Wikimedia\LockManager\NullLockManager, and Wikimedia\LockManager\QuorumLockManager.
Referenced by Wikimedia\LockManager\LockManager\doLockByType(), and Wikimedia\LockManager\LockManager\doUnlockByType().
|
protected |
| array | $pathsByType | Map of LockManager::LOCK_* constants to lists of paths |
Reimplemented in Wikimedia\LockManager\QuorumLockManager.
Definition at line 244 of file LockManager.php.
References Wikimedia\LockManager\LockManager\doUnlock().
Referenced by Wikimedia\LockManager\LockManager\unlockByType().
|
final |
Lock the resources at the given abstract paths.
| array | $paths | List of resource names |
| int | $type | LockManager::LOCK_* constant |
| int | $timeout | Timeout in seconds (0 means non-blocking) (since 1.21) |
Definition at line 113 of file LockManager.php.
References Wikimedia\LockManager\LockManager\lockByType().
Referenced by Wikimedia\LockManager\RedisLockManager\getLocksOnServer().
|
final |
Lock the resources at the given abstract paths.
| array | $pathsByType | Map of LockManager::LOCK_* constants to lists of paths |
| int | $timeout | Timeout in seconds (0 means non-blocking) (since 1.21) |
Definition at line 125 of file LockManager.php.
References Wikimedia\LockManager\LockManager\doLockByType(), and Wikimedia\LockManager\LockManager\normalizePathsByType().
Referenced by Wikimedia\LockManager\ScopedLock\factory(), and Wikimedia\LockManager\LockManager\lock().
|
finalprotected |
Normalize the $paths array by converting LOCK_UW locks into the appropriate type and removing any duplicated paths for each lock type.
| array | $pathsByType | Map of LockManager::LOCK_* constants to lists of paths |
Definition at line 188 of file LockManager.php.
References $path.
Referenced by Wikimedia\LockManager\LockManager\lockByType(), and Wikimedia\LockManager\LockManager\unlockByType().
|
finalprotected |
Get the base 36 SHA-1 of a string, padded to 31 digits.
Before hashing, the path will be prefixed with the domain ID. This should be used internally for lock key or file names.
| string | $path |
Definition at line 176 of file LockManager.php.
Referenced by Wikimedia\LockManager\MemcLockManager\recordKeyForPath(), and Wikimedia\LockManager\RedisLockManager\recordKeyForPath().
|
final |
Unlock the resources at the given abstract paths.
| array | $paths | List of paths |
| int | $type | LockManager::LOCK_* constant |
Definition at line 150 of file LockManager.php.
References Wikimedia\LockManager\LockManager\unlockByType().
|
final |
Unlock the resources at the given abstract paths.
| array | $pathsByType | Map of LockManager::LOCK_* constants to lists of paths |
Definition at line 161 of file LockManager.php.
References Wikimedia\LockManager\LockManager\doUnlockByType(), and Wikimedia\LockManager\LockManager\normalizePathsByType().
Referenced by Wikimedia\LockManager\MemcLockManager\__destruct(), Wikimedia\LockManager\RedisLockManager\__destruct(), and Wikimedia\LockManager\LockManager\unlock().
|
protected |
domain (usually wiki ID)
Definition at line 51 of file LockManager.php.
|
protected |
Map of (resource path => lock type => count)
Definition at line 48 of file LockManager.php.
Referenced by Wikimedia\LockManager\MemcLockManager\freeLocksOnServer(), and Wikimedia\LockManager\MemcLockManager\getLocksOnServer().
|
protected |
maximum time locks can be held
Definition at line 53 of file LockManager.php.
Referenced by Wikimedia\LockManager\MemcLockManager\getLocksOnServer().
|
protected |
Mapping of lock types to the type actually used.
Definition at line 41 of file LockManager.php.
|
protected |
Definition at line 38 of file LockManager.php.
|
protected |
Random 32-char hex number.
Definition at line 56 of file LockManager.php.
Referenced by Wikimedia\LockManager\MemcLockManager\getLocksOnServer().
| const Wikimedia\LockManager\LockManager::LOCK_EX = 3 |
Definition at line 61 of file LockManager.php.
Referenced by Wikimedia\LockManager\FSLockManager\doSingleLock().
| const Wikimedia\LockManager\LockManager::LOCK_SH = 1 |
Lock types; stronger locks have higher values.
Definition at line 59 of file LockManager.php.
Referenced by Wikimedia\LockManager\FSLockManager\doSingleLock(), Wikimedia\LockManager\RedisLockManager\freeLocksOnServer(), and Wikimedia\LockManager\RedisLockManager\getLocksOnServer().
| const Wikimedia\LockManager\LockManager::LOCK_UW = 2 |
Definition at line 60 of file LockManager.php.
|
protected |
Max expected lock expiry in any context.
Definition at line 64 of file LockManager.php.
|
protected |
Minimum lock TTL.
The configured lockTTL is ignored if it is less than this value.
Definition at line 67 of file LockManager.php.