MediaWiki  1.23.3
LockManager Class Reference

Class for handling resource locking. More...

Inheritance diagram for LockManager:

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 = array()
 Map of (resource path => lock type => count) *. More...
 
 $lockTTL
 
array $lockTypeMap
 Mapping of lock types to the type actually used *. More...
 

Detailed Description

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 proccess 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.

Since
1.19

Definition at line 45 of file LockManager.php.

Constructor & Destructor Documentation

◆ __construct()

LockManager::__construct ( array  $config)

Construct a new instance from configuration.

Parameters
array$configParamaters include:
  • domain : Domain (usually wiki ID) that all resources are relative to [optional]
  • lockTTL : Age (in seconds) at which resource locks should expire. This only applies if locks are not tied to a connection/process.

Reimplemented in DBLockManager, RedisLockManager, MemcLockManager, and FSLockManager.

Definition at line 70 of file LockManager.php.

References wfWikiID().

Member Function Documentation

◆ doLock()

LockManager::doLock ( array  $paths,
  $type 
)
abstractprotected

Lock resources with the given keys and lock type.

Parameters
array$pathsList of paths
int$typeLockManager::LOCK_* constant
Returns
Status

Reimplemented in NullLockManager, FSLockManager, and QuorumLockManager.

Referenced by doLockByType().

◆ doLockByType()

LockManager::doLockByType ( array  $pathsByType)
protected
See also
LockManager::lockByType()
Parameters
array$pathsByTypeMap of LockManager::LOCK_* constants to lists of paths
Returns
Status
Since
1.22

Reimplemented in QuorumLockManager.

Definition at line 196 of file LockManager.php.

References $type, array(), as, doLock(), doUnlock(), and Status\newGood().

Referenced by lockByType().

◆ doUnlock()

LockManager::doUnlock ( array  $paths,
  $type 
)
abstractprotected

Unlock resources with the given keys and lock type.

Parameters
array$pathsList of paths
int$typeLockManager::LOCK_* constant
Returns
Status

Reimplemented in NullLockManager, FSLockManager, and QuorumLockManager.

Referenced by doLockByType(), and doUnlockByType().

◆ doUnlockByType()

LockManager::doUnlockByType ( array  $pathsByType)
protected
See also
LockManager::unlockByType()
Parameters
array$pathsByTypeMap of LockManager::LOCK_* constants to lists of paths
Returns
Status
Since
1.22

Reimplemented in QuorumLockManager.

Definition at line 230 of file LockManager.php.

References $type, as, doUnlock(), and Status\newGood().

Referenced by unlockByType().

◆ lock()

LockManager::lock ( array  $paths,
  $type = self::LOCK_EX,
  $timeout = 0 
)
final

Lock the resources at the given abstract paths.

Parameters
array$pathsList of resource names
int$typeLockManager::LOCK_* constant
int$timeoutTimeout in seconds (0 means non-blocking) (since 1.21)
Returns
Status

Definition at line 90 of file LockManager.php.

References $type, array(), and lockByType().

Referenced by RedisLockManager\getLocksOnServer().

◆ lockByType()

LockManager::lockByType ( array  $pathsByType,
  $timeout = 0 
)
final

Lock the resources at the given abstract paths.

Parameters
array$pathsByTypeMap of LockManager::LOCK_* constants to lists of paths
int$timeoutTimeout in seconds (0 means non-blocking) (since 1.21)
Returns
Status
Since
1.22

Definition at line 102 of file LockManager.php.

References array(), doLockByType(), Status\newGood(), normalizePathsByType(), wfProfileIn(), and wfProfileOut().

Referenced by ScopedLock\factory(), and lock().

◆ normalizePathsByType()

LockManager::normalizePathsByType ( array  $pathsByType)
finalprotected

Normalize the $paths array by converting LOCK_UW locks into the appropriate type and removing any duplicated paths for each lock type.

Parameters
array$pathsByTypeMap of LockManager::LOCK_* constants to lists of paths
Returns
array
Since
1.22

Definition at line 181 of file LockManager.php.

References $res, $type, array(), and as.

Referenced by lockByType(), and unlockByType().

◆ sha1Base16Absolute()

LockManager::sha1Base16Absolute (   $path)
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 interally for lock key or file names.

Parameters
string$path
Returns
string

Definition at line 169 of file LockManager.php.

◆ sha1Base36Absolute()

LockManager::sha1Base36Absolute (   $path)
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 interally for lock key or file names.

Parameters
string$path
Returns
string

Definition at line 157 of file LockManager.php.

References wfBaseConvert().

Referenced by MySqlLockManager\doGetLocksOnServer(), RedisLockManager\recordKeyForPath(), and MemcLockManager\recordKeyForPath().

◆ unlock()

LockManager::unlock ( array  $paths,
  $type = self::LOCK_EX 
)
final

Unlock the resources at the given abstract paths.

Parameters
array$pathsList of paths
int$typeLockManager::LOCK_* constant
Returns
Status

Definition at line 129 of file LockManager.php.

References $type, array(), and unlockByType().

◆ unlockByType()

LockManager::unlockByType ( array  $pathsByType)
final

Unlock the resources at the given abstract paths.

Parameters
array$pathsByTypeMap of LockManager::LOCK_* constants to lists of paths
Returns
Status
Since
1.22

Definition at line 140 of file LockManager.php.

References doUnlockByType(), normalizePathsByType(), wfProfileIn(), and wfProfileOut().

Referenced by RedisLockManager\__destruct(), and unlock().

Member Data Documentation

◆ $domain

LockManager::$domain
protected

Definition at line 54 of file LockManager.php.

◆ $locksHeld

array LockManager::$locksHeld = array()
protected

Map of (resource path => lock type => count) *.

Definition at line 52 of file LockManager.php.

Referenced by MemcLockManager\doFreeLocksOnServer(), and MemcLockManager\doGetLocksOnServer().

◆ $lockTTL

LockManager::$lockTTL
protected

Definition at line 55 of file LockManager.php.

Referenced by MemcLockManager\doGetLocksOnServer().

◆ $lockTypeMap

array LockManager::$lockTypeMap
protected
Initial value:
self::LOCK_SH => self::LOCK_SH,
self::LOCK_UW => self::LOCK_EX,
self::LOCK_EX => self::LOCK_EX
)

Mapping of lock types to the type actually used *.

Definition at line 46 of file LockManager.php.

◆ LOCK_EX

◆ LOCK_SH

const LockManager::LOCK_SH = 1

◆ LOCK_UW


The documentation for this class was generated from the following file:
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.