26 use Psr\Log\LoggerInterface;
54 if ( isset( $conf[
'readOnlyReason'] ) && is_string( $conf[
'readOnlyReason'] ) ) {
55 $this->readOnlyReason = $conf[
'readOnlyReason'];
60 $this->logger = LoggerFactory::getInstance(
'DBTransaction' );
78 MediaWikiServices::disableStorageBackend();
89 return MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
104 'LBFactory_Simple' =>
'LBFactorySimple',
105 'LBFactory_Single' =>
'LBFactorySingle',
106 'LBFactory_Multi' =>
'LBFactoryMulti',
107 'LBFactory_Fake' =>
'LBFactoryFake',
110 $class = $config[
'class'];
112 if ( isset( $bcClasses[$class] ) ) {
113 $class = $bcClasses[$class];
115 '$wgLBFactoryConf must be updated. See RELEASE-NOTES for details',
129 self::singleton()->destroy();
139 abstract public function newMainLB( $wiki =
false );
147 abstract public function getMainLB( $wiki =
false );
158 abstract protected function newExternalLB( $cluster, $wiki =
false );
167 abstract public function &
getExternalLB( $cluster, $wiki =
false );
196 call_user_func_array( [ $loadBalancer, $methodName ], $args );
198 [ $methodName,
$args ]
254 $callersByDB[$masterName] = $callers;
258 if ( count( $callersByDB ) >= 2 ) {
259 $dbs = implode(
', ', array_keys( $callersByDB ) );
260 $msg =
"Multi-DB transaction [{$dbs}]:\n";
261 foreach ( $callersByDB
as $db => $callers ) {
262 $msg .=
"$db: " . implode(
'; ', $callers ) .
"\n";
264 $this->logger->info( $msg );
338 'ifWritesSince' => null
344 if ( $opts[
'cluster'] !==
false ) {
346 } elseif ( $opts[
'wiki'] !==
false ) {
347 $lbs[] = $this->
getMainLB( $opts[
'wiki'] );
360 $masterPositions = array_fill( 0, count( $lbs ),
false );
361 foreach ( $lbs
as $i => $lb ) {
362 if ( $lb->getServerCount() <= 1 ) {
366 } elseif ( $opts[
'ifWritesSince']
367 && $lb->lastMasterChangeTimestamp() < $opts[
'ifWritesSince']
371 $masterPositions[$i] = $lb->getMasterPos();
375 foreach ( $lbs
as $i => $lb ) {
376 if ( $masterPositions[$i] ) {
379 if ( !$lb->waitForAll( $masterPositions[$i], $opts[
'timeout'] ) ) {
380 $failed[] = $lb->getServerName( $lb->getWriterIndex() );
387 "Could not wait for slaves to catch up to " .
388 implode(
', ', $failed )
401 $this->chronProt->setEnabled(
false );
413 'agent' =>
$request->getHeader(
'User-Agent' )
416 if ( PHP_SAPI ===
'cli' ) {
418 } elseif (
$request->getHeader(
'ChronologyProtection' ) ===
'false' ) {
436 $unsavedPositions = $cp->
shutdown();
443 if ( isset( $unsavedPositions[$masterName] ) ) {
444 $lb->
waitForAll( $unsavedPositions[$masterName] );
464 parent::__construct(
"Mediawiki tried to access the database via wfGetDB(). " .
465 "This is not allowed, because database access has been disabled." );
newMainLB($wiki=false)
Create a new load balancer object.
the array() calling protocol came about after MediaWiki 1.4rc1.
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
__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...
commitAll($fname=__METHOD__, array $options=[])
Commit on all connections.
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 MediaWikiServices
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.
static disableBackend()
Disables all access to the load balancer, will cause all database access to throw a DBAccessError...
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.
Exception class for replica DB wait timeouts.
static singleton()
Get an LBFactory instance.
static getMain()
Static methods.
An interface for generating database load balancers.
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.
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.
closeAll()
Close all open database connections on all open load balancers.
getMainLB($wiki=false)
Get a cached (tracked) load balancer object.
disableChronologyProtection()
Disable the ChronologyProtector for all load balancers.
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
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...
destroy()
Disables all load balancers.
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.
TransactionProfiler $trxProfiler
getServerName($i)
Get the host name or IP address of the server with the specified index Prefer a readable name if avai...
waitForAll($pos, $timeout=null)
Set the master wait position and wait for ALL slaves to catch up to it.
logIfMultiDbTransaction()
Log query info if multi DB transactions are going to be committed now.
hasOrMadeRecentMasterChanges()
Determine if any master connection has pending/written changes from this request. ...
ChronologyProtector $chronProt