Go to the documentation of this file.
75 parent::__construct( $config );
77 $this->dbServers = isset( $config[
'dbServers'] )
78 ? $config[
'dbServers']
81 $this->srvsByBucket = array_filter( $config[
'dbsByBucket'],
'is_array' );
82 $this->srvsByBucket = array_values( $this->srvsByBucket );
84 if ( isset( $config[
'lockExpiry'] ) ) {
85 $this->lockExpiry = $config[
'lockExpiry'];
87 $met = ini_get(
'max_execution_time' );
88 $this->lockExpiry = $met ? $met : 60;
90 $this->safeDelay = ( $this->lockExpiry <= 0 )
94 foreach ( $this->srvsByBucket
as $bucket ) {
95 if ( count( $bucket ) > 1 ) {
101 trigger_error( __CLASS__ .
102 " using multiple DB peers without apc, xcache, or wincache." );
114 foreach ( $pathsByType
as $type => $paths ) {
115 $status->merge( $this->doGetLocksOnServer( $lockSrv, $paths,
$type ) );
153 if ( !isset( $this->conns[$lockDb] ) ) {
155 if ( $lockDb ===
'localDBMaster' ) {
158 } elseif ( isset( $this->dbServers[$lockDb] ) ) {
159 $config = $this->dbServers[$lockDb];
165 $this->conns[$lockDb] = $db;
166 $this->conns[$lockDb]->clearFlag(
DBO_TRX );
167 # If the connection drops, try to avoid letting the DB rollback
168 # and release the locks before the file operations are finished.
169 # This won't handle the case of DB server restarts however.
171 if ( $this->lockExpiry > 0 ) {
174 $this->conns[$lockDb]->setSessionOptions(
$options );
177 if ( !$this->conns[$lockDb]->trxLevel() ) {
178 $this->conns[$lockDb]->begin( __METHOD__ );
181 return $this->conns[$lockDb];
202 return ( $this->statusCache && $this->safeDelay > 0 )
203 ? !$this->statusCache->get( $this->
getMissKey( $lockDb ) )
214 return ( $this->statusCache && $this->safeDelay > 0 )
215 ? $this->statusCache->set( $this->
getMissKey( $lockDb ), 1, $this->safeDelay )
226 $lockDb = ( $lockDb ===
'localDBMaster' ) ?
wfWikiID() : $lockDb;
227 return 'dblockmanager:downservers:' . str_replace(
' ',
'_', $lockDb );
235 foreach ( $this->conns
as $db ) {
250 self::LOCK_SH => self::LOCK_SH,
251 self::LOCK_UW => self::LOCK_SH,
252 self::LOCK_EX => self::LOCK_EX
260 # Let this transaction see lock rows from other transactions
261 $db->
query(
"SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;" );
281 $checkEXKeys =
array();
282 # Build up values for INSERT clause
286 $data[] =
array(
'fls_key' => $key,
'fls_session' => $this->session );
287 if ( !isset( $this->locksHeld[
$path][self::LOCK_EX] ) ) {
288 $checkEXKeys[] = $key;
292 # Block new writers (both EX and SH locks leave entries here)...
293 $db->
insert(
'filelocks_shared', $data, __METHOD__,
array(
'IGNORE' ) );
294 # Actually do the locking queries...
295 if (
$type == self::LOCK_SH ) {
297 # Bail if there are any existing writers...
298 if ( count( $checkEXKeys ) ) {
299 $blocked = $db->
selectField(
'filelocks_exclusive',
'1',
300 array(
'fle_key' => $checkEXKeys ),
304 # Other prospective writers that haven't yet updated filelocks_exclusive
305 # will recheck filelocks_shared after doing so and bail due to this entry.
307 $encSession = $db->
addQuotes( $this->session );
308 # Bail if there are any existing writers...
309 # This may detect readers, but the safe check for them is below.
310 # Note: if two writers come at the same time, both bail :)
311 $blocked = $db->
selectField(
'filelocks_shared',
'1',
312 array(
'fls_key' =>
$keys,
"fls_session != $encSession" ),
316 # Build up values for INSERT clause
319 $data[] =
array(
'fle_key' => $key );
321 # Block new readers/writers...
322 $db->
insert(
'filelocks_exclusive', $data, __METHOD__ );
323 # Bail if there are any existing readers...
324 $blocked = $db->
selectField(
'filelocks_shared',
'1',
325 array(
'fls_key' =>
$keys,
"fls_session != $encSession" ),
333 $status->fatal(
'lockmanager-fail-acquirelock',
$path );
347 foreach ( $this->conns
as $lockDb => $db ) {
352 $status->fatal(
'lockmanager-fail-db-release', $lockDb );
370 self::LOCK_SH => self::LOCK_SH,
371 self::LOCK_UW => self::LOCK_SH,
372 self::LOCK_EX => self::LOCK_EX
377 if ( !count( $paths ) ) {
382 $bigints = array_unique( array_map(
386 array_map(
array( $this,
'sha1Base16Absolute' ), $paths )
391 foreach ( $bigints
as $bigint ) {
393 ?
"pg_try_advisory_lock_shared({$db->addQuotes( $bigint )}) AS K$bigint"
394 :
"pg_try_advisory_lock({$db->addQuotes( $bigint )}) AS K$bigint";
396 $res = $db->
query(
'SELECT ' . implode(
', ', $fields ), __METHOD__ );
399 if ( in_array(
'f', $row ) ) {
402 foreach ( $row
as $kbigint =>
$ok ) {
404 $bigint = substr( $kbigint, 1 );
406 ?
"pg_advisory_unlock_shared({$db->addQuotes( $bigint )})"
407 :
"pg_advisory_unlock({$db->addQuotes( $bigint )})";
410 if ( count( $fields ) ) {
411 $db->
query(
'SELECT ' . implode(
', ', $fields ), __METHOD__ );
414 $status->fatal(
'lockmanager-fail-acquirelock',
$path );
428 foreach ( $this->conns
as $lockDb => $db ) {
430 $db->
query(
"SELECT pg_advisory_unlock_all()", __METHOD__ );
432 $status->fatal(
'lockmanager-fail-db-release', $lockDb );
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
const LOCK_SH
Lock types; stronger locks have higher values.
query( $sql, $fname=__METHOD__, $tempIgnore=false)
Run an SQL query and return the result.
cacheRecordFailure( $lockDb)
Log a lock request failure to the cache.
static newGood( $value=null)
Factory function for good results.
__construct(array $config)
Construct a new instance from configuration.
getLocksOnServer( $lockSrv, array $pathsByType)
Get a connection to a lock server and acquire locks.
cacheCheckFailures( $lockDb)
Checks if the DB has not recently had connection/query errors.
array $dbServers
Map of DB names to server config *.
if( $wgAPIRequestLog) $lb
addQuotes( $s)
Adds quotes and backslashes.
selectField( $table, $var, $cond='', $fname=__METHOD__, $options=array())
A SELECT wrapper which returns a single field from a single result row.
Version of LockManager that uses a quorum from peer servers for locks.
sha1Base36Absolute( $path)
Get the base 36 SHA-1 of a string, padded to 31 digits.
releaseAllLocks()
Release all locks that this session is holding.
getMissKey( $lockDb)
Get a cache key for recent query misses for a DB.
array $conns
Map Database connections (DB name => Database) *.
array $lockTypeMap
Mapping of lock types to the type actually used *.
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
static factory( $dbType, $p=array())
Given a DB type, construct the name of the appropriate child class of DatabaseBase.
Database error base class.
__destruct()
Make sure remaining locks get cleared for sanity.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
trxLevel()
Gets the current transaction level.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
doGetLocksOnServer( $lockSrv, array $paths, $type)
Get a connection to a lock DB and acquire locks on $paths.
Database abstraction object.
static newAccelerator( $params)
Factory function referenced from DefaultSettings.php for CACHE_ACCEL.
rollback( $fname=__METHOD__, $flush='')
Rollback a transaction previously started using begin().
array $lockTypeMap
Mapping of lock types to the type actually used *.
doGetLocksOnServer( $lockSrv, array $paths, $type)
MySQL version of DBLockManager that supports shared locks.
initConnection( $lockDb, DatabaseBase $db)
& wfGetLBFactory()
Get the load balancer factory object.
wfBaseConvert( $input, $sourceBase, $destBase, $pad=1, $lowercase=true, $engine='auto')
Convert an arbitrarily-long digit string from one numeric base to another, optionally zero-padding to...
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
getConnection( $lockDb)
Get (or reuse) a connection to a lock DB.
initConnection( $lockDb, DatabaseBase $db)
Do additional initialization for new lock DB connection.
Version of LockManager based on using named/row DB locks.
PostgreSQL version of DBLockManager that supports shared locks.
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
insert( $table, $a, $fname=__METHOD__, $options=array())
INSERT wrapper, inserts an array into a table.
freeLocksOnServer( $lockSrv, array $pathsByType)
Get a connection to a lock server and release locks on $paths.