Go to the documentation of this file.
41 self::LOCK_SH => self::LOCK_SH,
42 self::LOCK_UW => self::LOCK_SH,
43 self::LOCK_EX => self::LOCK_EX
67 parent::__construct( $config );
70 $this->srvsByBucket = array_filter( $config[
'srvsByBucket'],
'is_array' );
71 $this->srvsByBucket = array_values( $this->srvsByBucket );
73 $memcConfig = isset( $config[
'memcConfig'] )
74 ? $config[
'memcConfig']
75 :
array(
'class' =>
'MemcachedPhpBagOStuff' );
77 foreach ( $config[
'lockServers']
as $name => $address ) {
84 'Only MemcachedBagOStuff classes are supported by MemcLockManager.' );
95 $lockedPaths =
array();
96 foreach ( $pathsByType
as $type => $paths ) {
98 if ( $status->isOK() ) {
99 $lockedPaths[
$type] = isset( $lockedPaths[
$type] )
100 ? array_merge( $lockedPaths[
$type], $paths )
103 foreach ( $lockedPaths
as $lType => $lPaths ) {
117 foreach ( $pathsByType
as $type => $paths ) {
134 $memc = $this->
getCache( $lockSrv );
135 $keys = array_map(
array( $this,
'recordKeyForPath' ), $paths );
140 $status->fatal(
'lockmanager-fail-acquirelock',
$path );
147 $lockRecords = $memc->getMulti(
$keys );
157 if ( $expiry < $now ) {
159 } elseif (
$session !== $this->session ) {
160 $status->fatal(
'lockmanager-fail-acquirelock',
$path );
163 if (
$type === self::LOCK_EX ) {
165 if ( $expiry < $now ) {
167 } elseif (
$session !== $this->session ) {
168 $status->fatal(
'lockmanager-fail-acquirelock',
$path );
172 if ( $status->isOK() ) {
181 if ( $status->isOK() ) {
187 $status->fatal(
'lockmanager-fail-acquirelock',
$path );
189 wfDebug( __METHOD__ .
": acquired lock on key $locksKey.\n" );
210 $memc = $this->
getCache( $lockSrv );
211 $keys = array_map(
array( $this,
'recordKeyForPath' ), $paths );
216 $status->fatal(
'lockmanager-fail-releaselock',
$path );
223 $lockRecords = $memc->getMulti(
$keys );
228 if ( !isset( $lockRecords[$locksKey] ) ) {
229 $status->warning(
'lockmanager-fail-releaselock',
$path );
236 $ok = $memc->delete( $locksKey );
241 $status->fatal(
'lockmanager-fail-releaselock',
$path );
244 $status->warning(
'lockmanager-fail-releaselock',
$path );
246 wfDebug( __METHOD__ .
": released lock on key $locksKey.\n" );
269 return (
bool)$this->
getCache( $lockSrv );
278 protected function getCache( $lockSrv ) {
280 if ( isset( $this->bagOStuffs[$lockSrv] ) ) {
281 $memc = $this->bagOStuffs[$lockSrv];
282 if ( !isset( $this->serversUp[$lockSrv] ) ) {
283 $this->serversUp[$lockSrv] = $memc->set( __CLASS__ .
':ping', 1, 1 );
284 if ( !$this->serversUp[$lockSrv] ) {
285 trigger_error( __METHOD__ .
": Could not contact $lockSrv.", E_USER_WARNING );
288 if ( !$this->serversUp[$lockSrv] ) {
316 if ( is_array( $a ) && isset( $a[self::LOCK_EX] ) && isset( $a[self::LOCK_SH] ) ) {
319 trigger_error( __METHOD__ .
": reset invalid lock array.", E_USER_WARNING );
331 $lockedKeys =
array();
341 $start = microtime(
true );
343 if ( ( ++$rounds % 4 ) == 0 ) {
346 foreach ( array_diff(
$keys, $lockedKeys )
as $key ) {
347 if ( $memc->
add(
"$key:mutex", 1, 180 ) ) {
348 $lockedKeys[] = $key;
353 }
while ( count( $lockedKeys ) < count(
$keys ) && ( microtime(
true ) - $start ) <= 3 );
355 if ( count( $lockedKeys ) != count(
$keys ) ) {
369 $memc->
delete(
"$key:mutex" );
377 while ( count( $this->locksHeld ) ) {
378 foreach ( $this->locksHeld
as $path => $locks ) {
doGetLocksOnServer( $lockSrv, array $paths, $type)
array $locksHeld
Map of (resource path => lock type => count) *.
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
freeLocksOnServer( $lockSrv, array $pathsByType)
Get a connection to a lock server and release locks on $paths.
Base class for memcached clients.
string $session
random UUID *
static sanitizeLockArray( $a)
static newGood( $value=null)
Factory function for good results.
acquireMutexes(MemcachedBagOStuff $memc, array $keys)
array $bagOStuffs
Map server names to MemcachedBagOStuff objects *.
__construct(array $config)
Construct a new instance from configuration.
array $serversUp
(server name => bool) *
getCache( $lockSrv)
Get the MemcachedBagOStuff object for a $lockSrv.
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.
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
doFreeLocksOnServer( $lockSrv, array $paths, $type)
doUnlock(array $paths, $type)
Unlock resources with the given keys and lock type.
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Allows to change the fields on the form that will be generated $name
__destruct()
Make sure remaining locks get cleared for sanity.
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
Manage locks using memcached servers.
add( $key, $value, $exptime=0)
static newFromParams( $params)
Create a new cache object from parameters.
releaseMutexes(MemcachedBagOStuff $memc, array $keys)
array $lockTypeMap
Mapping of lock types to the type actually used *.
getLocksOnServer( $lockSrv, array $pathsByType)
Get a connection to a lock server and acquire locks.
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.