MediaWiki master
Wikimedia\LockManager\FSLockManager Class Reference

Simple lock management based on server-local temporary files. More...

Inherits Wikimedia\LockManager\LockManager.

Collaboration diagram for Wikimedia\LockManager\FSLockManager:

Public Member Functions

 __construct (array $config)
 Construct a new instance from configuration.
 __destruct ()
 Make sure remaining locks get cleared.
Public Member Functions inherited from Wikimedia\LockManager\LockManager
 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.
 lockKey (string $key, int $timeout=0)
 Provide a mutex of the key.
Parameters
string$keyKey to lock (relative to a domain, usually represented by the wiki ID, which callers don't need to specify)
int$timeoutTime to wait in seconds
Returns
bool true if the lock is acquired, false otherwise

 scopedLock (string $key, int $timeout=0)
 Lock a key and unlock it automatically when the object is destructed.
Parameters
string$key
int$timeout
Returns
ScopedCallback|null returns null when we failed to acquire the lock

 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.
 unlockKey (string $key)
 
Parameters
string$keyKey to unlock (relative to a domain, usually represented by the wiki ID, which callers don't need to specify)
Returns
bool true if the lock is released, false otherwise

Protected Member Functions

 doLockByType (array $pathsByType)
 Acquire a set of locks without blocking.If some locks could not be acquired, then the other locks should be released. This must set the "lockmanager-fail-conflict" error if there are any lock conflicts.
Parameters
array$pathsByTypeMap of LockManager::LOCK_* constants to lists of paths
Returns
StatusValue
See also
LockManager\lockByType()

 doSingleLock ( $path, $type)
 Lock a single resource key.
 doSingleUnlock ( $path, $type)
 Unlock a single resource key.
 doUnlockByType (array $pathsByType)
 Release a set of locks.
Parameters
array$pathsByTypeMap of LockManager::LOCK_* constants to lists of paths
Returns
StatusValue
See also
LockManager\unlockByType()

 getLockPath ( $path)
 Get the path to the lock file for a key.
Protected Member Functions inherited from Wikimedia\LockManager\LockManager
 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

array $handles = []
 Map of (locked key => lock file handle).
bool $isWindows
string $lockDir
 Global dir for all servers.
array $lockTypeMap
 Mapping of lock types to the type actually used.
Protected Attributes inherited from Wikimedia\LockManager\LockManager
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.

Additional Inherited Members

Public Attributes inherited from Wikimedia\LockManager\LockManager
const LOCK_EX = 3
const LOCK_SH = 1
 Lock types; stronger locks have higher values.
const LOCK_UW = 2

Detailed Description

Simple lock management based on server-local temporary files.

All locks are non-blocking, which avoids deadlocks.

This should work fine for small sites running from a single web server. Do not use this with 'lockDirectory' set to an NFS mount unless the NFS client is at least version 2.6.12. Otherwise, the BSD flock() locks will be ignored; see http://nfs.sourceforge.net/#section_d.

Since
1.19

Definition at line 23 of file FSLockManager.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\LockManager\FSLockManager::__construct ( array $config)

Construct a new instance from configuration.

Parameters
array$configIncludes:
  • lockDirectory : Directory containing the lock files

Reimplemented from Wikimedia\LockManager\LockManager.

Definition at line 46 of file FSLockManager.php.

◆ __destruct()

Wikimedia\LockManager\FSLockManager::__destruct ( )

Make sure remaining locks get cleared.

Definition at line 227 of file FSLockManager.php.

References $path, and doSingleUnlock().

Member Function Documentation

◆ doLockByType()

Wikimedia\LockManager\FSLockManager::doLockByType ( array $pathsByType)
protected

Acquire a set of locks without blocking.If some locks could not be acquired, then the other locks should be released. This must set the "lockmanager-fail-conflict" error if there are any lock conflicts.

Parameters
array$pathsByTypeMap of LockManager::LOCK_* constants to lists of paths
Returns
StatusValue
See also
LockManager\lockByType()

Reimplemented from Wikimedia\LockManager\LockManager.

Definition at line 54 of file FSLockManager.php.

References $path, doSingleLock(), and doUnlockByType().

◆ doSingleLock()

Wikimedia\LockManager\FSLockManager::doSingleLock ( $path,
$type )
protected

Lock a single resource key.

Parameters
string$path
int$type
Returns
StatusValue

Definition at line 91 of file FSLockManager.php.

References $path, getLockPath(), Wikimedia\LockManager\LockManager\LOCK_EX, and Wikimedia\LockManager\LockManager\LOCK_SH.

Referenced by doLockByType().

◆ doSingleUnlock()

Wikimedia\LockManager\FSLockManager::doSingleUnlock ( $path,
$type )
protected

Unlock a single resource key.

Parameters
string$path
int$type
Returns
StatusValue

Definition at line 141 of file FSLockManager.php.

References $path.

Referenced by __destruct(), and doUnlockByType().

◆ doUnlockByType()

Wikimedia\LockManager\FSLockManager::doUnlockByType ( array $pathsByType)
protected

Release a set of locks.

Parameters
array$pathsByTypeMap of LockManager::LOCK_* constants to lists of paths
Returns
StatusValue
See also
LockManager\unlockByType()

Reimplemented from Wikimedia\LockManager\LockManager.

Definition at line 73 of file FSLockManager.php.

References $path, and doSingleUnlock().

Referenced by doLockByType().

◆ getLockPath()

Wikimedia\LockManager\FSLockManager::getLockPath ( $path)
protected

Get the path to the lock file for a key.

Parameters
string$path
Returns
string

Definition at line 220 of file FSLockManager.php.

References $path.

Referenced by doSingleLock().

Member Data Documentation

◆ $handles

array Wikimedia\LockManager\FSLockManager::$handles = []
protected

Map of (locked key => lock file handle).

Definition at line 35 of file FSLockManager.php.

◆ $isWindows

bool Wikimedia\LockManager\FSLockManager::$isWindows
protected

Definition at line 38 of file FSLockManager.php.

◆ $lockDir

string Wikimedia\LockManager\FSLockManager::$lockDir
protected

Global dir for all servers.

Definition at line 32 of file FSLockManager.php.

◆ $lockTypeMap

array Wikimedia\LockManager\FSLockManager::$lockTypeMap
protected
Initial value:
= [
self::LOCK_SH => self::LOCK_SH,
self::LOCK_UW => self::LOCK_SH,
self::LOCK_EX => self::LOCK_EX
]

Mapping of lock types to the type actually used.

Definition at line 25 of file FSLockManager.php.


The documentation for this class was generated from the following file: