MediaWiki  master
FSLockManager Class Reference

Simple version of LockManager based on using FS lock files. More...

Inheritance diagram for FSLockManager:
Collaboration diagram for FSLockManager:

Public Member Functions

 __construct (array $config)
 Construct a new instance from configuration. More...
 
 __destruct ()
 Make sure remaining locks get cleared for sanity. More...
 
- Public Member Functions inherited from LockManager
 __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...
 

Protected Member Functions

 doLock (array $paths, $type)
 
 doSingleLock ( $path, $type)
 Lock a single resource key. More...
 
 doSingleUnlock ( $path, $type)
 Unlock a single resource key. More...
 
 doUnlock (array $paths, $type)
 
 getLockPath ( $path)
 Get the path to the lock file for a key. More...
 
- Protected Member Functions inherited from LockManager
 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

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

Private Member Functions

 closeLockHandles ( $path, array $handlesToClose)
 
 pruneKeyLockFiles ( $path)
 

Additional Inherited Members

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

Detailed Description

Simple version of LockManager based on using FS lock files.

All locks are non-blocking, which avoids deadlocks.

This should work fine for small sites running off one 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 36 of file FSLockManager.php.

Constructor & Destructor Documentation

◆ __construct()

FSLockManager::__construct ( array  $config)

Construct a new instance from configuration.

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

Definition at line 59 of file FSLockManager.php.

◆ __destruct()

FSLockManager::__destruct ( )

Make sure remaining locks get cleared for sanity.

Definition at line 249 of file FSLockManager.php.

References $path, as, and doSingleUnlock().

Member Function Documentation

◆ closeLockHandles()

FSLockManager::closeLockHandles (   $path,
array  $handlesToClose 
)
private
Parameters
string$path
array$handlesToClose
Returns
StatusValue

Definition at line 206 of file FSLockManager.php.

References $path, as, and StatusValue\newGood().

Referenced by doSingleUnlock().

◆ doLock()

FSLockManager::doLock ( array  $paths,
  $type 
)
protected
See also
LockManager::doLock()
Parameters
array$paths
int$type
Returns
StatusValue

Definition at line 72 of file FSLockManager.php.

References $path, $type, as, doSingleLock(), doUnlock(), and StatusValue\newGood().

◆ doSingleLock()

FSLockManager::doSingleLock (   $path,
  $type 
)
protected

Lock a single resource key.

Parameters
string$path
int$type
Returns
StatusValue

Definition at line 114 of file FSLockManager.php.

References $path, $type, getLockPath(), LockManager\LOCK_EX, LockManager\LOCK_SH, and StatusValue\newGood().

Referenced by doLock().

◆ doSingleUnlock()

FSLockManager::doSingleUnlock (   $path,
  $type 
)
protected

Unlock a single resource key.

Parameters
string$path
int$type
Returns
StatusValue

Definition at line 163 of file FSLockManager.php.

References $path, $type, closeLockHandles(), StatusValue\newGood(), and pruneKeyLockFiles().

Referenced by __destruct(), and doUnlock().

◆ doUnlock()

FSLockManager::doUnlock ( array  $paths,
  $type 
)
protected
See also
LockManager::doUnlock()
Parameters
array$paths
int$type
Returns
StatusValue

Definition at line 97 of file FSLockManager.php.

References $path, $type, as, doSingleUnlock(), and StatusValue\newGood().

Referenced by doLock().

◆ getLockPath()

FSLockManager::getLockPath (   $path)
protected

Get the path to the lock file for a key.

Parameters
string$path
Returns
string

Definition at line 242 of file FSLockManager.php.

Referenced by doSingleLock(), and pruneKeyLockFiles().

◆ pruneKeyLockFiles()

FSLockManager::pruneKeyLockFiles (   $path)
private
Parameters
string$path
Returns
StatusValue

Definition at line 224 of file FSLockManager.php.

References $path, getLockPath(), and StatusValue\newGood().

Referenced by doSingleUnlock().

Member Data Documentation

◆ $handles

array FSLockManager::$handles = []
protected

Map of (locked key => lock file handle)

Definition at line 48 of file FSLockManager.php.

◆ $isWindows

bool FSLockManager::$isWindows
protected

Definition at line 51 of file FSLockManager.php.

◆ $lockDir

string FSLockManager::$lockDir
protected

Global dir for all servers.

Definition at line 45 of file FSLockManager.php.

◆ $lockTypeMap

array FSLockManager::$lockTypeMap
protected
Initial value:
= [
self::LOCK_SH => self::LOCK_SH

Mapping of lock types to the type actually used.

Definition at line 38 of file FSLockManager.php.


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