MediaWiki  REL1_22
LockManager Class Reference

Class for handling resource locking. More...

Inheritance diagram for LockManager:
Collaboration diagram for LockManager:

List of all members.

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.
 sha1Base16Absolute ($path)
 Get the base 16 SHA-1 of a string, padded to 31 digits.
 sha1Base36Absolute ($path)
 Get the base 36 SHA-1 of a string, padded to 31 digits.

Protected Attributes

 $domain
Array $locksHeld = array()
 Map of (resource path => lock type => count) *.
 $lockTTL
Array $lockTypeMap
 Mapping of lock types to the type actually used *.

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 a new instance from configuration.

$config paramaters 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.
Parameters:
$configArray

Reimplemented in DBLockManager, LSLockManager, RedisLockManager, MemcLockManager, and FSLockManager.

Definition at line 72 of file LockManager.php.


Member Function Documentation

LockManager::doLock ( array paths,
type 
) [abstract, protected]

Lock resources with the given keys and lock type.

Parameters:
array$pathsList of paths
$typeinteger LockManager::LOCK_* constant
Returns:
Status

Reimplemented in NullLockManager, FSLockManager, and QuorumLockManager.

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

Reimplemented in QuorumLockManager.

Definition at line 195 of file LockManager.php.

LockManager::doUnlock ( array paths,
type 
) [abstract, protected]

Unlock resources with the given keys and lock type.

Parameters:
array$pathsList of paths
$typeinteger LockManager::LOCK_* constant
Returns:
Status

Reimplemented in NullLockManager, FSLockManager, and QuorumLockManager.

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

Reimplemented in QuorumLockManager.

Definition at line 228 of file LockManager.php.

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
$typeinteger LockManager::LOCK_* constant
integer$timeoutTimeout in seconds (0 means non-blocking) (since 1.21)
Returns:
Status

Definition at line 92 of file LockManager.php.

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
integer$timeoutTimeout in seconds (0 means non-blocking) (since 1.21)
Returns:
Status
Since:
1.22

Definition at line 104 of file LockManager.php.

LockManager::normalizePathsByType ( array pathsByType) [final, protected]

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

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

Definition at line 181 of file LockManager.php.

LockManager::sha1Base16Absolute ( path) [final, protected]

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:
$pathstring
Returns:
string

Definition at line 169 of file LockManager.php.

LockManager::sha1Base36Absolute ( path) [final, protected]

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:
$pathstring
Returns:
string

Definition at line 157 of file LockManager.php.

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

Unlock the resources at the given abstract paths.

Parameters:
array$pathsList of paths
$typeinteger LockManager::LOCK_* constant
Returns:
Status

Definition at line 130 of file LockManager.php.

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 141 of file LockManager.php.


Member Data Documentation

LockManager::$domain [protected]

Definition at line 54 of file LockManager.php.

Array LockManager::$locksHeld = array() [protected]

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

Definition at line 52 of file LockManager.php.

LockManager::$lockTTL [protected]

Definition at line 55 of file LockManager.php.

Array LockManager::$lockTypeMap [protected]
Initial value:
 array(
        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 *.

Reimplemented in PostgreSqlLockManager, MySqlLockManager, RedisLockManager, LSLockManager, MemcLockManager, and FSLockManager.

Definition at line 46 of file LockManager.php.

Definition at line 60 of file LockManager.php.

Referenced by SyncFileBackend\syncFileBatch().

Lock types; stronger locks have higher values.

Definition at line 58 of file LockManager.php.

Definition at line 59 of file LockManager.php.

Referenced by SyncFileBackend\syncFileBatch().


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