MediaWiki
1.30.0
|
Class for handling resource locking. More...
Public Member Functions | |
__construct (array $config) | |
Construct a new instance from configuration. More... | |
lock (array $paths, $type=self::LOCK_EX, $timeout=0) | |
Lock the resources at the given abstract paths. More... | |
lockByType (array $pathsByType, $timeout=0) | |
Lock the resources at the given abstract paths. More... | |
unlock (array $paths, $type=self::LOCK_EX) | |
Unlock the resources at the given abstract paths. More... | |
unlockByType (array $pathsByType) | |
Unlock the resources at the given abstract paths. More... | |
Public Attributes | |
const | LOCK_EX = 3 |
const | LOCK_SH = 1 |
Lock types; stronger locks have higher values. More... | |
const | LOCK_UW = 2 |
Protected Member Functions | |
doLock (array $paths, $type) | |
Lock resources with the given keys and lock type. More... | |
doLockByType (array $pathsByType) | |
doUnlock (array $paths, $type) | |
Unlock resources with the given keys and lock type. More... | |
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. More... | |
sha1Base16Absolute ( $path) | |
Get the base 16 SHA-1 of a string, padded to 31 digits. More... | |
sha1Base36Absolute ( $path) | |
Get the base 36 SHA-1 of a string, padded to 31 digits. More... | |
Protected Attributes | |
$domain | |
array | $locksHeld = [] |
Map of (resource path => lock type => count) More... | |
$lockTTL | |
array | $lockTypeMap |
Mapping of lock types to the type actually used. More... | |
LoggerInterface | $logger |
string | $session |
Random 32-char hex number. More... | |
Class for handling resource locking.
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 46 of file LockManager.php.
LockManager::__construct | ( | array | $config | ) |
Construct a new instance from configuration.
array | $config | Parameters include:
|
Reimplemented in DBLockManager, MemcLockManager, RedisLockManager, FSLockManager, and MySqlLockManager.
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 FSLockManager, QuorumLockManager, and NullLockManager.
Referenced by doLockByType().
|
protected |
array | $pathsByType | Map of LockManager::LOCK_* constants to lists of paths |
Reimplemented in QuorumLockManager.
Definition at line 216 of file LockManager.php.
References $type, as, doLock(), doUnlock(), and StatusValue\newGood().
Referenced by lockByType().
|
abstractprotected |
Unlock resources with the given keys and lock type.
array | $paths | List of paths |
int | $type | LockManager::LOCK_* constant |
Reimplemented in FSLockManager, QuorumLockManager, and NullLockManager.
Referenced by doLockByType(), and doUnlockByType().
|
protected |
array | $pathsByType | Map of LockManager::LOCK_* constants to lists of paths |
Reimplemented in QuorumLockManager.
Definition at line 250 of file LockManager.php.
References $type, as, doUnlock(), and StatusValue\newGood().
Referenced by 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 115 of file LockManager.php.
References $type, and lockByType().
Referenced by 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 127 of file LockManager.php.
References doLockByType(), normalizePathsByType(), and use.
Referenced by ScopedLock\factory(), and 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 201 of file LockManager.php.
References $res, $type, and as.
Referenced by lockByType(), and unlockByType().
|
finalprotected |
Get the base 16 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 189 of file LockManager.php.
|
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 177 of file LockManager.php.
Referenced by MySqlLockManager\doGetLocksOnServer(), RedisLockManager\recordKeyForPath(), and MemcLockManager\recordKeyForPath().
|
final |
Unlock the resources at the given abstract paths.
array | $paths | List of paths |
int | $type | LockManager::LOCK_* constant |
Definition at line 151 of file LockManager.php.
References $type, and unlockByType().
|
final |
Unlock the resources at the given abstract paths.
array | $pathsByType | Map of LockManager::LOCK_* constants to lists of paths |
Definition at line 162 of file LockManager.php.
References doUnlockByType(), and normalizePathsByType().
Referenced by RedisLockManager\__destruct(), and unlock().
|
protected |
Definition at line 60 of file LockManager.php.
|
protected |
Map of (resource path => lock type => count)
Definition at line 58 of file LockManager.php.
Referenced by MemcLockManager\freeLocksOnServer(), and MemcLockManager\getLocksOnServer().
|
protected |
Definition at line 61 of file LockManager.php.
Referenced by MemcLockManager\getLocksOnServer().
|
protected |
Mapping of lock types to the type actually used.
Definition at line 51 of file LockManager.php.
|
protected |
Definition at line 48 of file LockManager.php.
|
protected |
Random 32-char hex number.
Definition at line 64 of file LockManager.php.
Referenced by MySqlLockManager\doGetLocksOnServer(), and MemcLockManager\getLocksOnServer().
const LockManager::LOCK_EX = 3 |
Definition at line 69 of file LockManager.php.
Referenced by LocalFile\acquireFileLock(), FileBackendStore\doClean(), FSLockManager\doSingleLock(), FileBackendTest\doTestLockCalls(), FileBackendStore\getPathsToLockForOpsInternal(), FileBackendMultiWrite\getScopedLocksForOps(), Wikimedia\Rdbms\DatabaseSqlite\lock(), LocalFile\releaseFileLock(), SyncFileBackend\syncFileBatch(), and Wikimedia\Rdbms\DatabaseSqlite\unlock().
const LockManager::LOCK_SH = 1 |
Lock types; stronger locks have higher values.
Definition at line 67 of file LockManager.php.
Referenced by PostgreSqlLockManager\doGetLocksOnServer(), FSLockManager\doSingleLock(), FileBackendTest\doTestLockCalls(), RedisLockManager\freeLocksOnServer(), and RedisLockManager\getLocksOnServer().
const LockManager::LOCK_UW = 2 |
Definition at line 68 of file LockManager.php.
Referenced by SwiftFileBackend\addMissingMetadata(), FileBackendStore\concatenate(), FileBackendStore\getPathsToLockForOpsInternal(), FileBackendMultiWrite\getScopedLocksForOps(), and SyncFileBackend\syncFileBatch().