MediaWiki  REL1_19
DBLockManager Class Reference

Version of LockManager based on using DB table locks. More...

Inheritance diagram for DBLockManager:
Collaboration diagram for DBLockManager:

List of all members.

Public Member Functions

 __construct (array $config)
 Construct a new instance from configuration.
 __destruct ()
 Make sure remaining locks get cleared for sanity.

Protected Member Functions

 cacheCheckFailures ($lockDb)
 Checks if the DB has not recently had connection/query errors.
 cacheRecordFailure ($lockDb)
 Log a lock request failure to the cache.
 doLock (array $paths, $type)
 doLockingQuery ($lockDb, array $paths, $type)
 Get a connection to a lock DB and acquire locks on $paths.
 doLockingQueryAll ($bucket, array $paths, $type)
 Attempt to acquire locks with the peers for a bucket.
 doUnlock (array $paths, $type)
 finishLockTransactions ()
 Commit all changes to lock-active databases.
 getBucketFromKey ($path)
 Get the bucket for resource path.
 getConnection ($lockDb)
 Get (or reuse) a connection to a lock DB.
 getMissKey ($lockDb)
 Get a cache key for recent query misses for a DB.
 initConnection ($lockDb, DatabaseBase $db)
 Do additional initialization for new lock DB connection.
 lastErrorIndicatesLocked ($lockDb)
 Check if the last DB error for $lockDb indicates that a requested resource was locked by another process.

Protected Attributes

 $conns = array()
 $dbsByBucket
 $dbServers
 $lockExpiry
 $safeDelay
 $session = 0
 $statusCache

Detailed Description

Version of LockManager based on using DB table locks.

This is meant for multi-wiki systems that may share files. All locks are blocking, so it might be useful to set a small lock-wait timeout via server config to curtail deadlocks.

All lock requests for a resource, identified by a hash string, will map to one bucket. Each bucket maps to one or several peer DBs, each on their own server, all having the filelocks.sql tables (with row-level locking). A majority of peer DBs must agree for a lock to be acquired.

Caching is used to avoid hitting servers that are down.

Since:
1.19

Definition at line 19 of file DBLockManager.php.


Constructor & Destructor Documentation

DBLockManager::__construct ( array $  config)

Construct a new instance from configuration.

$config paramaters include: 'dbServers' : Associative array of DB names to server configuration. Configuration is an associative array that includes: 'host' - DB server name 'dbname' - DB name 'type' - DB type (mysql,postgres,...) 'user' - DB user 'password' - DB user password 'tablePrefix' - DB table prefix 'flags' - DB flags (see DatabaseBase) 'dbsByBucket' : Array of 1-16 consecutive integer keys, starting from 0, each having an odd-numbered list of DB names (peers) as values. Any DB named 'localDBMaster' will automatically use the DB master settings for this wiki (without the need for a dbServers entry). 'lockExpiry' : Lock timeout (seconds) for dropped connections. [optional] This tells the DB server how long to wait before assuming connection failure and releasing all the locks for a session.

Parameters:
Array$config

Reimplemented from LockManager.

Definition at line 57 of file DBLockManager.php.

References wfBaseConvert(), and wfGetMainCache().

Here is the call graph for this function:

Make sure remaining locks get cleared for sanity.

Definition at line 388 of file DBLockManager.php.


Member Function Documentation

DBLockManager::cacheCheckFailures ( lockDb) [protected]

Checks if the DB has not recently had connection/query errors.

This just avoids wasting time on doomed connection attempts.

Parameters:
$lockDbstring
Returns:
bool

Definition at line 335 of file DBLockManager.php.

References $path, and getMissKey().

Referenced by doLockingQueryAll().

Here is the call graph for this function:

Here is the caller graph for this function:

DBLockManager::cacheRecordFailure ( lockDb) [protected]

Log a lock request failure to the cache.

Parameters:
$lockDbstring
Returns:
bool Success

Definition at line 350 of file DBLockManager.php.

References $path, and getMissKey().

Referenced by doLockingQueryAll().

Here is the call graph for this function:

Here is the caller graph for this function:

DBLockManager::doLock ( array $  paths,
type 
) [protected]
See also:
LockManager::doLock()

Reimplemented from LockManager.

Definition at line 94 of file DBLockManager.php.

References $path, $res, doLockingQueryAll(), doUnlock(), getBucketFromKey(), and Status\newGood().

Here is the call graph for this function:

DBLockManager::doLockingQuery ( lockDb,
array $  paths,
type 
) [protected]

Get a connection to a lock DB and acquire locks on $paths.

This does not use GET_LOCK() per http://bugs.mysql.com/bug.php?id=1118.

Parameters:
$lockDbstring
$pathsArray
$typeinteger LockManager::LOCK_EX or LockManager::LOCK_SH
Returns:
bool Resources able to be locked
Exceptions:
DBError

Reimplemented in MySqlLockManager.

Definition at line 181 of file DBLockManager.php.

References $keys, and getConnection().

Referenced by doLockingQueryAll().

Here is the call graph for this function:

Here is the caller graph for this function:

DBLockManager::doLockingQueryAll ( bucket,
array $  paths,
type 
) [protected]

Attempt to acquire locks with the peers for a bucket.

This should avoid throwing any exceptions.

Parameters:
$bucketinteger
$pathsArray List of resource keys to lock
$typeinteger LockManager::LOCK_EX or LockManager::LOCK_SH
Returns:
bool|string One of (true, 'cantacquire', 'dberrors')

Definition at line 208 of file DBLockManager.php.

References cacheCheckFailures(), cacheRecordFailure(), doLockingQuery(), and lastErrorIndicatesLocked().

Referenced by doLock().

Here is the call graph for this function:

Here is the caller graph for this function:

DBLockManager::doUnlock ( array $  paths,
type 
) [protected]
See also:
LockManager::doUnlock()

Reimplemented from LockManager.

Definition at line 144 of file DBLockManager.php.

References $path, finishLockTransactions(), and Status\newGood().

Referenced by doLock().

Here is the call graph for this function:

Here is the caller graph for this function:

Commit all changes to lock-active databases.

This should avoid throwing any exceptions.

Returns:
Status

Definition at line 298 of file DBLockManager.php.

References Status\newGood().

Referenced by doUnlock().

Here is the call graph for this function:

Here is the caller graph for this function:

DBLockManager::getBucketFromKey ( path) [protected]

Get the bucket for resource path.

This should avoid throwing any exceptions.

Parameters:
$pathstring
Returns:
integer

Definition at line 380 of file DBLockManager.php.

References $path.

Referenced by doLock().

Here is the caller graph for this function:

DBLockManager::getConnection ( lockDb) [protected]

Get (or reuse) a connection to a lock DB.

Parameters:
$lockDbstring
Returns:
Database
Exceptions:
DBError

Definition at line 251 of file DBLockManager.php.

References $lb, $options, DatabaseBase\factory(), initConnection(), and wfGetLBFactory().

Referenced by doLockingQuery(), and MySqlLockManager\doLockingQuery().

Here is the call graph for this function:

Here is the caller graph for this function:

DBLockManager::getMissKey ( lockDb) [protected]

Get a cache key for recent query misses for a DB.

Parameters:
$lockDbstring
Returns:
string

Definition at line 369 of file DBLockManager.php.

Referenced by cacheCheckFailures(), and cacheRecordFailure().

Here is the caller graph for this function:

DBLockManager::initConnection ( lockDb,
DatabaseBase db 
) [protected]

Do additional initialization for new lock DB connection.

Parameters:
$lockDbstring
$dbDatabaseBase
Returns:
void
Exceptions:
DBError

Reimplemented in MySqlLockManager.

Definition at line 290 of file DBLockManager.php.

Referenced by getConnection().

Here is the caller graph for this function:

DBLockManager::lastErrorIndicatesLocked ( lockDb) [protected]

Check if the last DB error for $lockDb indicates that a requested resource was locked by another process.

This should avoid throwing any exceptions.

Parameters:
$lockDbstring
Returns:
bool

Definition at line 320 of file DBLockManager.php.

Referenced by doLockingQueryAll().

Here is the caller graph for this function:


Member Data Documentation

DBLockManager::$conns = array() [protected]

Definition at line 32 of file DBLockManager.php.

DBLockManager::$dbsByBucket [protected]

Definition at line 23 of file DBLockManager.php.

DBLockManager::$dbServers [protected]

Definition at line 21 of file DBLockManager.php.

DBLockManager::$lockExpiry [protected]

Definition at line 27 of file DBLockManager.php.

DBLockManager::$safeDelay [protected]

Definition at line 28 of file DBLockManager.php.

DBLockManager::$session = 0 [protected]

Definition at line 30 of file DBLockManager.php.

DBLockManager::$statusCache [protected]

Definition at line 25 of file DBLockManager.php.


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