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 : [
'class' =>
'MemcachedPhpBagOStuff' ];
77 foreach ( $config[
'lockServers']
as $name => $address ) {
78 $params = [
'servers' => [ $address ] ] + $memcConfig;
84 'Only MemcachedBagOStuff classes are supported by MemcLockManager.' );
96 foreach ( $pathsByType
as $type => $paths ) {
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( [ $this,
'recordKeyForPath' ], $paths );
140 $status->fatal(
'lockmanager-fail-acquirelock', $path );
147 $lockRecords = $memc->getMulti(
$keys );
154 ? self::sanitizeLockArray( $lockRecords[$locksKey] )
155 : self::newLockArray();
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 );
182 foreach ( $paths
as $path ) {
185 $ok = $memc->set( $locksKey,
$locksHeld, 7 * 86400 );
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( [ $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 );
232 $locksHeld = self::sanitizeLockArray( $lockRecords[$locksKey] );
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 );
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] ) {
308 return [ self::LOCK_SH => [], self::LOCK_EX => [] ];
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 );
321 return self::newLockArray();
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 ) ) {
368 foreach ( $keys
as $key ) {
369 $memc->
delete(
"$key:mutex" );
377 while ( count( $this->locksHeld ) ) {
378 foreach ( $this->locksHeld
as $path => $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.
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
static sanitizeLockArray($a)
doGetLocksOnServer($lockSrv, array $paths, $type)
doFreeLocksOnServer($lockSrv, array $paths, $type)
__construct(array $config)
Construct a new instance from configuration.
array $lockTypeMap
Mapping of lock types to the type actually used.
wfRandomString($length=32)
Get a random string containing a number of pseudo-random hex characters.
array $serversUp
(server name => bool)
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
array $bagOStuffs
Map server names to MemcachedBagOStuff objects.
string $session
Random UUID.
static newFromParams($params)
Create a new cache object from parameters.
array $locksHeld
Map of (resource path => lock type => count)
doUnlock(array $paths, $type)
acquireMutexes(MemcachedBagOStuff $memc, array $keys)
Manage locks using memcached servers.
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
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
releaseMutexes(MemcachedBagOStuff $memc, array $keys)
getLocksOnServer($lockSrv, array $pathsByType)
Base class for memcached clients.
add($key, $value, $exptime=0)
__destruct()
Make sure remaining locks get cleared for sanity.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
freeLocksOnServer($lockSrv, array $pathsByType)
getCache($lockSrv)
Get the MemcachedBagOStuff object for a $lockSrv.
Version of LockManager that uses a quorum from peer servers for locks.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
static newGood($value=null)
Factory function for good results.
Allows to change the fields on the form that will be generated $name