54 if ( isset( $conf[
'readOnlyReason'] ) && is_string( $conf[
'readOnlyReason'] ) ) {
55 $this->readOnlyReason = $conf[
'readOnlyReason'];
60 $this->logger = LoggerFactory::getInstance(
'DBTransaction' );
80 if ( is_null( self::$instance ) ) {
81 $class = self::getLBFactoryClass( $wgLBFactoryConf );
83 if ( !isset( $config[
'readOnlyReason'] ) ) {
86 self::$instance =
new $class( $config );
89 return self::$instance;
102 'LBFactory_Simple' =>
'LBFactorySimple',
103 'LBFactory_Single' =>
'LBFactorySingle',
104 'LBFactory_Multi' =>
'LBFactoryMulti',
105 'LBFactory_Fake' =>
'LBFactoryFake',
108 $class = $config[
'class'];
110 if ( isset( $bcClasses[$class] ) ) {
111 $class = $bcClasses[$class];
113 '$wgLBFactoryConf must be updated. See RELEASE-NOTES for details',
125 if ( self::$instance ) {
126 self::$instance->shutdown();
127 self::$instance->forEachLBCallMethod(
'closeAll' );
128 self::$instance = null;
138 self::destroyInstance();
149 abstract public function newMainLB( $wiki =
false );
157 abstract public function getMainLB( $wiki =
false );
168 abstract protected function newExternalLB( $cluster, $wiki =
false );
177 abstract public function &
getExternalLB( $cluster, $wiki =
false );
206 call_user_func_array( [ $loadBalancer, $methodName ], $args );
208 [ $methodName,
$args ]
221 $start = microtime(
true );
223 $timeMs = 1000 * ( microtime(
true ) - $start );
271 $callersByDB[$masterName] = $callers;
275 if ( count( $callersByDB ) >= 2 ) {
276 $dbs = implode(
', ', array_keys( $callersByDB ) );
277 $msg =
"Multi-DB transaction [{$dbs}]:\n";
278 foreach ( $callersByDB
as $db => $callers ) {
279 $msg .=
"$db: " . implode(
'; ', $callers ) .
"\n";
281 $this->logger->info( $msg );
355 'ifWritesSince' => null
361 if ( $opts[
'cluster'] !==
false ) {
363 } elseif ( $opts[
'wiki'] !==
false ) {
364 $lbs[] = $this->
getMainLB( $opts[
'wiki'] );
377 $masterPositions = array_fill( 0, count( $lbs ),
false );
378 foreach ( $lbs
as $i => $lb ) {
379 if ( $lb->getServerCount() <= 1 ) {
383 } elseif ( $opts[
'ifWritesSince']
384 && $lb->lastMasterChangeTimestamp() < $opts[
'ifWritesSince']
388 $masterPositions[$i] = $lb->getMasterPos();
392 foreach ( $lbs
as $i => $lb ) {
393 if ( $masterPositions[$i] ) {
396 if ( !$lb->waitForAll( $masterPositions[$i], $opts[
'timeout'] ) ) {
397 $failed[] = $lb->getServerName( $lb->getWriterIndex() );
404 "Could not wait for slaves to catch up to " .
405 implode(
', ', $failed )
418 $this->chronProt->setEnabled(
false );
430 'agent' =>
$request->getHeader(
'User-Agent' )
433 if ( PHP_SAPI ===
'cli' ) {
435 } elseif (
$request->getHeader(
'ChronologyProtection' ) ===
'false' ) {
453 $unsavedPositions = $cp->
shutdown();
460 if ( isset( $unsavedPositions[$masterName] ) ) {
461 $lb->
waitForAll( $unsavedPositions[$masterName] );
472 parent::__construct(
"Mediawiki tried to access the database via wfGetDB(). " .
473 "This is not allowed." );
static setInstance($instance)
Set the instance to be the given object.
newMainLB($wiki=false)
Create a new load balancer object.
the array() calling protocol came about after MediaWiki 1.4rc1.
commitAll($fname=__METHOD__)
Commit on all connections.
shutdownChronologyProtector(ChronologyProtector $cp)
shutdown($flags=0)
Prepare all tracked load balancers for shutdown.
& getExternalLB($cluster, $wiki=false)
Get a cached (tracked) load balancer for external storage.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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 noclasses & $ret
__construct(array $conf)
Construct a factory based on a configuration array (typically from $wgLBFactoryConf) ...
static instance()
Singleton.
forEachLB($callback, array $params=[])
Execute a function for each tracked load balancer The callback is called with the load balancer as th...
it s the revision text itself In either if gzip is the revision text is gzipped $flags
newExternalLB($cluster, $wiki=false)
Create a new load balancer for external storage.
static getMainStashInstance()
Get the cache object for the main stash.
when a variable name is used in a it is silently declared as a new local masking the global
forEachOpenConnection($callback, array $params=[])
Call a function with each open connection object.
static disableBackend()
Disables all access to the load balancer, will cause all database access to throw a DBAccessError...
see documentation in includes Linker php for Linker::makeImageLink & $time
commitMasterChanges($fname=__METHOD__, array $options=[])
Commit changes on all master connections.
shutdownLB(LoadBalancer $lb)
Notify the ChronologyProtector that the LoadBalancer is about to shut down.
Database load balancing object.
const SHUTDOWN_NO_CHRONPROT
rollbackMasterChanges($fname=__METHOD__)
Rollback changes on all master connections.
wfConfiguredReadOnlyReason()
Get the value of $wgReadOnly or the contents of $wgReadOnlyFile.
Exception class for replica DB wait timeouts.
static singleton()
Get an LBFactory instance.
static getMain()
Static methods.
An interface for generating database load balancers.
logMultiDbTransaction()
Log query info if multi DB transactions are going to be committed now.
pendingWriteQueryDuration()
Get the time spend running write queries for this transaction.
waitForReplication(array $opts=[])
Waits for the slave DBs to catch up to the current master position.
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 and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
hasMasterChanges()
Determine if there are pending changes in a transaction by this thread.
Exception class for attempted DB access.
hasMasterChanges()
Determine if any master connection has pending changes.
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 noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock()-offset Set to overwrite offset parameter in $wgRequest set to ''to unsetoffset-wrap String Wrap the message in html(usually something like"<
string bool $readOnlyReason
Reason all LBs are read-only or false if not.
wfDeprecated($function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
static destroyInstance()
Shut down, close connections and destroy the cached instance.
getMainLB($wiki=false)
Get a cached (tracked) load balancer object.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
disableChronologyProtection()
Disable the ChronologyProtector for all load balancers.
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
hasOrMadeRecentMasterChanges($age=null)
Check if this load balancer object had any recent or still pending writes issued against it by this P...
forEachLBCallMethod($methodName, array $args=[])
Call a method of each tracked load balancer.
static getLBFactoryClass(array $config)
Returns the LBFactory class to use and the load balancer configuration.
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
Class for ensuring a consistent ordering of events as seen by the user, despite replication.
error also a ContextSource you ll probably need to make sure the header is varied on $request
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined...
shutdown()
Notify the ChronologyProtector that the LBFactory is done calling shutdownLB() for now...
static LBFactory $instance
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 and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive $limit
MediaWiki Logger LoggerFactory implements a PSR[0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method.MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances.The"Spi"in MediaWiki\Logger\Spi stands for"service provider interface".An SPI is an API intended to be implemented or extended by a third party.This software design pattern is intended to enable framework extension and replaceable components.It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki.The service provider interface allows the backend logging library to be implemented in multiple ways.The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime.This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance.Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
laggedSlaveUsed()
Detemine if any lagged slave connection was used.
pendingMasterChangeCallers()
Get the list of callers that have pending master changes.
$wgLBFactoryConf
Load balancer factory configuration To set up a multi-master wiki farm, set the class here to somethi...
TransactionProfiler $trxProfiler
getServerName($i)
Get the host name or IP address of the server with the specified index Prefer a readable name if avai...
LBFactory class that throws an error on any attempt to use it.
waitForAll($pos, $timeout=null)
Set the master wait position and wait for ALL slaves to catch up to it.
Basic database interface for live and lazy-loaded DB handles.
hasOrMadeRecentMasterChanges()
Determine if any master connection has pending/written changes from this request. ...
ChronologyProtector $chronProt