24use Psr\Log\LoggerInterface;
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 ) ) {
83 if ( !isset( $config[
'readOnlyReason'] ) ) {
86 self::$instance =
new $class( $config );
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;
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." );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgLBFactoryConf
Load balancer factory configuration To set up a multi-master wiki farm, set the class here to somethi...
wfConfiguredReadOnlyReason()
Get the value of $wgReadOnly or the contents of $wgReadOnlyFile.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Class for ensuring a consistent ordering of events as seen by the user, despite replication.
setWaitEnabled( $enabled)
shutdownLB(LoadBalancer $lb)
Notify the ChronologyProtector that the LoadBalancer is about to shut down.
shutdown()
Notify the ChronologyProtector that the LBFactory is done calling shutdownLB() for now.
getRequest()
Get the WebRequest object.
Exception class for attempted DB access.
Exception class for replica DB wait timeouts.
LBFactory class that throws an error on any attempt to use it.
An interface for generating database load balancers.
forEachLBCallMethod( $methodName, array $args=[])
Call a method of each tracked load balancer.
const SHUTDOWN_NO_CHRONPROT
logMultiDbTransaction()
Log query info if multi DB transactions are going to be committed now.
laggedSlaveUsed()
Detemine if any lagged slave connection was used.
static setInstance( $instance)
Set the instance to be the given object.
static getLBFactoryClass(array $config)
Returns the LBFactory class to use and the load balancer configuration.
static singleton()
Get an LBFactory instance.
newExternalLB( $cluster, $wiki=false)
Create a new load balancer for external storage.
& getExternalLB( $cluster, $wiki=false)
Get a cached (tracked) load balancer for external storage.
static LBFactory $instance
__construct(array $conf)
Construct a factory based on a configuration array (typically from $wgLBFactoryConf)
disableChronologyProtection()
Disable the ChronologyProtector for all load balancers.
rollbackMasterChanges( $fname=__METHOD__)
Rollback changes on all master connections.
ChronologyProtector $chronProt
getMainLB( $wiki=false)
Get a cached (tracked) load balancer object.
hasMasterChanges()
Determine if any master connection has pending changes.
commitAll( $fname=__METHOD__)
Commit on all connections.
commitMasterChanges( $fname=__METHOD__, array $options=[])
Commit changes on all master connections.
shutdownChronologyProtector(ChronologyProtector $cp)
newMainLB( $wiki=false)
Create a new load balancer object.
static destroyInstance()
Shut down, close connections and destroy the cached instance.
static disableBackend()
Disables all access to the load balancer, will cause all database access to throw a DBAccessError.
hasOrMadeRecentMasterChanges()
Determine if any master connection has pending/written changes from this request.
string bool $readOnlyReason
Reason all LBs are read-only or false if not.
forEachLB( $callback, array $params=[])
Execute a function for each tracked load balancer The callback is called with the load balancer as th...
waitForReplication(array $opts=[])
Waits for the slave DBs to catch up to the current master position.
shutdown( $flags=0)
Prepare all tracked load balancers for shutdown.
TransactionProfiler $trxProfiler
Database load balancing object.
pendingMasterChangeCallers()
Get the list of callers that have pending master changes.
forEachOpenConnection( $callback, array $params=[])
Call a function with each open connection object.
hasMasterChanges()
Determine if there are pending changes in a transaction by this thread.
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.
hasOrMadeRecentMasterChanges( $age=null)
Check if this load balancer object had any recent or still pending writes issued against it by this P...
static getMainStashInstance()
Get the cache object for the main stash.
static instance()
Singleton.
static getMain()
Static methods.
Helper class that detects high-contention DB queries via profiling calls.
when a variable name is used in a it is silently declared as a new local masking the global
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
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
the array() calling protocol came about after MediaWiki 1.4rc1.
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 unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
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
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
it s the revision text itself In either if gzip is the revision text is gzipped $flags
error also a ContextSource you ll probably need to make sure the header is varied on $request
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
see documentation in includes Linker php for Linker::makeImageLink & $time
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
Basic database interface for live and lazy-loaded DB handles.
pendingWriteQueryDuration()
Get the time spend running write queries for this transaction.