MediaWiki  1.29.1
ILoadBalancer.php
Go to the documentation of this file.
1 <?php
24 namespace Wikimedia\Rdbms;
25 
26 use Exception;
27 use InvalidArgumentException;
28 
79 interface ILoadBalancer {
81  const DB_REPLICA = -1;
83  const DB_MASTER = -2;
84 
86  const DOMAIN_ANY = '';
87 
112  public function __construct( array $params );
113 
126  public function getReaderIndex( $group = false, $domain = false );
127 
140  public function waitFor( $pos );
141 
151  public function waitForOne( $pos, $timeout = null );
152 
160  public function waitForAll( $pos, $timeout = null );
161 
168  public function getAnyOpenConnection( $i );
169 
180  public function getConnection( $i, $groups = [], $domain = false );
181 
191  public function reuseConnection( $conn );
192 
205  public function getConnectionRef( $i, $groups = [], $domain = false );
206 
219  public function getLazyConnectionRef( $i, $groups = [], $domain = false );
220 
233  public function getMaintenanceConnectionRef( $db, $groups = [], $domain = false );
234 
247  public function openConnection( $i, $domain = false );
248 
252  public function getWriterIndex();
253 
260  public function haveIndex( $i );
261 
268  public function isNonZeroLoad( $i );
269 
275  public function getServerCount();
276 
283  public function getServerName( $i );
284 
290  public function getServerInfo( $i );
291 
298  public function setServerInfo( $i, array $serverInfo );
299 
304  public function getMasterPos();
305 
310  public function disable();
311 
315  public function closeAll();
316 
325  public function closeConnection( IDatabase $conn );
326 
332  public function commitAll( $fname = __METHOD__ );
333 
340  public function finalizeMasterChanges();
341 
351  public function approveMasterChanges( array $options );
352 
365  public function beginMasterChanges( $fname = __METHOD__ );
366 
372  public function commitMasterChanges( $fname = __METHOD__ );
373 
382  public function runMasterPostTrxCallbacks( $type );
383 
389  public function rollbackMasterChanges( $fname = __METHOD__ );
390 
398  public function suppressTransactionEndCallbacks();
399 
405  public function flushReplicaSnapshots( $fname = __METHOD__ );
406 
410  public function hasMasterConnection();
411 
416  public function hasMasterChanges();
417 
422  public function lastMasterChangeTimestamp();
423 
431  public function hasOrMadeRecentMasterChanges( $age = null );
432 
438  public function pendingMasterChangeCallers();
439 
445  public function getLaggedReplicaMode( $domain = false );
446 
455  public function laggedReplicaUsed();
456 
463  public function getReadOnlyReason( $domain = false, IDatabase $conn = null );
464 
470  public function allowLagged( $mode = null );
471 
475  public function pingAll();
476 
482  public function forEachOpenConnection( $callback, array $params = [] );
483 
489  public function forEachOpenMasterConnection( $callback, array $params = [] );
490 
496  public function forEachOpenReplicaConnection( $callback, array $params = [] );
497 
508  public function getMaxLag( $domain = false );
509 
520  public function getLagTimes( $domain = false );
521 
536  public function safeGetLag( IDatabase $conn );
537 
548  public function safeWaitForMasterPos( IDatabase $conn, $pos = false, $timeout = 10 );
549 
557  public function setTransactionListener( $name, callable $callback = null );
558 
564  public function setDomainPrefix( $prefix );
565 
578  public function setTableAliases( array $aliases );
579 }
Wikimedia\Rdbms\ILoadBalancer\haveIndex
haveIndex( $i)
Returns true if the specified index is a valid server index.
Wikimedia\Rdbms\ILoadBalancer\pendingMasterChangeCallers
pendingMasterChangeCallers()
Get the list of callers that have pending master changes.
Wikimedia\Rdbms\ILoadBalancer\setDomainPrefix
setDomainPrefix( $prefix)
Set a new table prefix for the existing local domain ID for testing.
Wikimedia\Rdbms\ILoadBalancer\pingAll
pingAll()
Wikimedia\Rdbms\ILoadBalancer\waitForAll
waitForAll( $pos, $timeout=null)
Set the master wait position and wait for ALL replica DBs to catch up to it.
Wikimedia\Rdbms\ILoadBalancer\runMasterPostTrxCallbacks
runMasterPostTrxCallbacks( $type)
Issue all pending post-COMMIT/ROLLBACK callbacks.
Wikimedia\Rdbms\ILoadBalancer\forEachOpenMasterConnection
forEachOpenMasterConnection( $callback, array $params=[])
Call a function with each open connection object to a master.
Wikimedia\Rdbms\ILoadBalancer\getServerInfo
getServerInfo( $i)
Return the server info structure for a given index, or false if the index is invalid.
Wikimedia\Rdbms\ILoadBalancer\disable
disable()
Disable this load balancer.
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
Wikimedia\Rdbms\ILoadBalancer\reuseConnection
reuseConnection( $conn)
Mark a foreign connection as being available for reuse under a different DB domain.
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24
Wikimedia\Rdbms\ILoadBalancer\isNonZeroLoad
isNonZeroLoad( $i)
Returns true if the specified index is valid and has non-zero load.
$fname
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition: Setup.php:36
Wikimedia\Rdbms\ILoadBalancer\safeWaitForMasterPos
safeWaitForMasterPos(IDatabase $conn, $pos=false, $timeout=10)
Wait for a replica DB to reach a specified master position.
$params
$params
Definition: styleTest.css.php:40
Wikimedia\Rdbms\ILoadBalancer\getServerCount
getServerCount()
Get the number of defined servers (not the number of open connections)
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:304
$type
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 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
Definition: hooks.txt:2536
Wikimedia\Rdbms\ILoadBalancer\getAnyOpenConnection
getAnyOpenConnection( $i)
Get any open connection to a given server index, local or foreign.
Wikimedia\Rdbms\ILoadBalancer\rollbackMasterChanges
rollbackMasterChanges( $fname=__METHOD__)
Issue ROLLBACK only on master, only if queries were done on connection.
php
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
Definition: injection.txt:35
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:40
Wikimedia\Rdbms\ILoadBalancer\setTableAliases
setTableAliases(array $aliases)
Make certain table names use their own database, schema, and table prefix when passed into SQL querie...
Wikimedia\Rdbms\ILoadBalancer\allowLagged
allowLagged( $mode=null)
Disables/enables lag checks.
Wikimedia\Rdbms\ILoadBalancer\getLazyConnectionRef
getLazyConnectionRef( $i, $groups=[], $domain=false)
Get a database connection handle reference without connecting yet.
Wikimedia\Rdbms\ILoadBalancer\finalizeMasterChanges
finalizeMasterChanges()
Perform all pre-commit callbacks that remain part of the atomic transactions and disable any post-com...
Wikimedia\Rdbms\ILoadBalancer\openConnection
openConnection( $i, $domain=false)
Open a connection to the server given by the specified index Index must be an actual index into the a...
Wikimedia\Rdbms\ILoadBalancer\getServerName
getServerName( $i)
Get the host name or IP address of the server with the specified index Prefer a readable name if avai...
Wikimedia\Rdbms\ILoadBalancer\suppressTransactionEndCallbacks
suppressTransactionEndCallbacks()
Suppress all pending post-COMMIT/ROLLBACK callbacks.
Wikimedia\Rdbms\ILoadBalancer\forEachOpenConnection
forEachOpenConnection( $callback, array $params=[])
Call a function with each open connection object.
Wikimedia\Rdbms\ILoadBalancer\getMaintenanceConnectionRef
getMaintenanceConnectionRef( $db, $groups=[], $domain=false)
Get a maintenance database connection handle reference for migrations and schema changes.
Wikimedia\Rdbms\ILoadBalancer\getMaxLag
getMaxLag( $domain=false)
Get the hostname and lag time of the most-lagged replica DB.
Wikimedia\Rdbms\ILoadBalancer\safeGetLag
safeGetLag(IDatabase $conn)
Get the lag in seconds for a given connection, or zero if this load balancer does not have replicatio...
Wikimedia\Rdbms\ILoadBalancer\getMasterPos
getMasterPos()
Get the current master position for chronology control purposes.
Wikimedia\Rdbms\ILoadBalancer\hasMasterConnection
hasMasterConnection()
Wikimedia\Rdbms\ILoadBalancer\setTransactionListener
setTransactionListener( $name, callable $callback=null)
Set a callback via IDatabase::setTransactionListener() on all current and future master connections o...
Wikimedia\Rdbms\ILoadBalancer\getWriterIndex
getWriterIndex()
Wikimedia\Rdbms\ILoadBalancer\waitFor
waitFor( $pos)
Set the master wait position.
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
DB_MASTER
const DB_MASTER
Definition: defines.php:26
Wikimedia\Rdbms\ILoadBalancer\getLaggedReplicaMode
getLaggedReplicaMode( $domain=false)
Wikimedia\Rdbms\ILoadBalancer\flushReplicaSnapshots
flushReplicaSnapshots( $fname=__METHOD__)
Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshot.
Wikimedia\Rdbms\ILoadBalancer\commitAll
commitAll( $fname=__METHOD__)
Commit transactions on all open connections.
Wikimedia\Rdbms\ILoadBalancer\hasOrMadeRecentMasterChanges
hasOrMadeRecentMasterChanges( $age=null)
Check if this load balancer object had any recent or still pending writes issued against it by this P...
Wikimedia\Rdbms\ILoadBalancer\forEachOpenReplicaConnection
forEachOpenReplicaConnection( $callback, array $params=[])
Call a function with each open replica DB connection object.
Wikimedia\Rdbms\ILoadBalancer\laggedReplicaUsed
laggedReplicaUsed()
Checks whether the database for generic connections this request was both:
Wikimedia\Rdbms\ILoadBalancer\getReaderIndex
getReaderIndex( $group=false, $domain=false)
Get the index of the reader connection, which may be a replica DB.
Wikimedia\Rdbms\ILoadBalancer\setServerInfo
setServerInfo( $i, array $serverInfo)
Sets the server info structure for the given index.
Wikimedia\Rdbms\ILoadBalancer\approveMasterChanges
approveMasterChanges(array $options)
Perform all pre-commit checks for things like replication safety.
Wikimedia\Rdbms\ILoadBalancer\getConnection
getConnection( $i, $groups=[], $domain=false)
Get a connection by index.
Wikimedia\Rdbms\ILoadBalancer\__construct
__construct(array $params)
Construct a manager of IDatabase connection objects.
Wikimedia\Rdbms\ILoadBalancer\commitMasterChanges
commitMasterChanges( $fname=__METHOD__)
Issue COMMIT on all master connections where writes where done.
Wikimedia\Rdbms\ILoadBalancer\hasMasterChanges
hasMasterChanges()
Determine if there are pending changes in a transaction by this thread.
Wikimedia\Rdbms\ILoadBalancer\getConnectionRef
getConnectionRef( $i, $groups=[], $domain=false)
Get a database connection handle reference.
Wikimedia\Rdbms\ILoadBalancer\waitForOne
waitForOne( $pos, $timeout=null)
Set the master wait position and wait for a "generic" replica DB to catch up to it.
Wikimedia\Rdbms\ILoadBalancer\closeConnection
closeConnection(IDatabase $conn)
Close a connection.
Wikimedia\Rdbms\ILoadBalancer\getReadOnlyReason
getReadOnlyReason( $domain=false, IDatabase $conn=null)
Wikimedia\Rdbms\ILoadBalancer\lastMasterChangeTimestamp
lastMasterChangeTimestamp()
Get the timestamp of the latest write query done by this thread.
Wikimedia\Rdbms\ILoadBalancer\beginMasterChanges
beginMasterChanges( $fname=__METHOD__)
Flush any master transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set)
$options
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup 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
Definition: hooks.txt:1049
Wikimedia\Rdbms\ILoadBalancer\closeAll
closeAll()
Close all open connections.
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:79
Wikimedia\Rdbms\ILoadBalancer\getLagTimes
getLagTimes( $domain=false)
Get an estimate of replication lag (in seconds) for each server.
array
the array() calling protocol came about after MediaWiki 1.4rc1.