MediaWiki  master
ILoadBalancer.php
Go to the documentation of this file.
1 <?php
23 namespace Wikimedia\Rdbms;
24 
28 
81 interface ILoadBalancer {
83  const DB_REPLICA = -1;
85  const DB_MASTER = -2;
86 
88  const DOMAIN_ANY = '';
90  const GROUP_GENERIC = '';
91 
93  const CONN_TRX_AUTOCOMMIT = 1;
95  const CONN_SILENCE_ERRORS = 2;
97  const CONN_INTENT_WRITABLE = 4;
98 
100  const STAGE_POSTCOMMIT_CALLBACKS = 'stage-postcommit-callbacks';
102  const STAGE_POSTROLLBACK_CALLBACKS = 'stage-postrollback-callbacks';
103 
132  public function __construct( array $params );
133 
141  public function getLocalDomainID();
142 
148  public function resolveDomainID( $domain );
149 
156  public function redefineLocalDomain( $domain );
157 
173  public function getReaderIndex( $group = false, $domain = false );
174 
187  public function waitFor( $pos );
188 
198  public function waitForOne( $pos, $timeout = null );
199 
207  public function waitForAll( $pos, $timeout = null );
208 
220  public function getAnyOpenConnection( $i, $flags = 0 );
221 
284  public function getConnection( $i, $groups = [], $domain = false, $flags = 0 );
285 
301  public function getServerConnection( $i, $domain, $flags = 0 );
302 
316  public function reuseConnection( IDatabase $conn );
317 
334  public function getConnectionRef( $i, $groups = [], $domain = false, $flags = 0 );
335 
355  public function getLazyConnectionRef( $i, $groups = [], $domain = false, $flags = 0 );
356 
377  public function getMaintenanceConnectionRef( $i, $groups = [], $domain = false, $flags = 0 );
378 
384  public function getWriterIndex();
385 
391  public function getServerCount();
392 
402  public function hasReplicaServers();
403 
423  public function hasStreamingReplicaServers();
424 
431  public function getServerName( $i );
432 
439  public function getServerInfo( $i );
440 
448  public function getServerType( $i );
449 
455  public function getServerAttributes( $i );
456 
463  public function getMasterPos();
464 
480  public function getReplicaResumePos();
481 
486  public function disable();
487 
491  public function closeAll();
492 
501  public function closeConnection( IDatabase $conn );
502 
509  public function commitAll( $fname = __METHOD__, $owner = null );
510 
520  public function finalizeMasterChanges( $fname = __METHOD__, $owner = null );
521 
533  public function approveMasterChanges( array $options, $fname, $owner = null );
534 
548  public function beginMasterChanges( $fname = __METHOD__, $owner = null );
549 
556  public function commitMasterChanges( $fname = __METHOD__, $owner = null );
557 
565  public function runMasterTransactionIdleCallbacks( $fname = __METHOD__, $owner = null );
566 
574  public function runMasterTransactionListenerCallbacks( $fname = __METHOD__, $owner = null );
575 
582  public function rollbackMasterChanges( $fname = __METHOD__, $owner = null );
583 
589  public function flushReplicaSnapshots( $fname = __METHOD__ );
590 
598  public function flushMasterSnapshots( $fname = __METHOD__ );
599 
603  public function hasMasterConnection();
604 
609  public function hasMasterChanges();
610 
615  public function lastMasterChangeTimestamp();
616 
624  public function hasOrMadeRecentMasterChanges( $age = null );
625 
631  public function pendingMasterChangeCallers();
632 
638  public function getLaggedReplicaMode( $domain = false );
639 
648  public function laggedReplicaUsed();
649 
656  public function getReadOnlyReason( $domain = false, IDatabase $conn = null );
657 
663  public function allowLagged( $mode = null );
664 
668  public function pingAll();
669 
675  public function forEachOpenConnection( $callback, array $params = [] );
676 
682  public function forEachOpenMasterConnection( $callback, array $params = [] );
683 
689  public function forEachOpenReplicaConnection( $callback, array $params = [] );
690 
701  public function getMaxLag( $domain = false );
702 
713  public function getLagTimes( $domain = false );
714 
728  public function waitForMasterPos( IDatabase $conn, $pos = false, $timeout = 10 );
729 
737  public function setTransactionListener( $name, callable $callback = null );
738 
745  public function setLocalDomainPrefix( $prefix );
746 
759  public function setTableAliases( array $aliases );
760 
773  public function setIndexAliases( array $aliases );
774 }
commitMasterChanges( $fname=__METHOD__, $owner=null)
Issue COMMIT on all open master connections to flush changes and view snapshots.
waitFor( $pos)
Set the master position to reach before the next generic group DB handle query.
getAnyOpenConnection( $i, $flags=0)
Get any open connection to a given server index, local or foreign.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
forEachOpenMasterConnection( $callback, array $params=[])
Call a function with each open connection object to a master.
flushMasterSnapshots( $fname=__METHOD__)
Commit all master DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
getConnection( $i, $groups=[], $domain=false, $flags=0)
Get a live handle for a real or virtual (DB_MASTER/DB_REPLICA) server index.
disable()
Disable this load balancer.
redefineLocalDomain( $domain)
Close all connection and redefine the local domain for testing or schema creation.
getLagTimes( $domain=false)
Get an estimate of replication lag (in seconds) for each server.
setLocalDomainPrefix( $prefix)
Set a new table prefix for the existing local domain ID for testing.
closeConnection(IDatabase $conn)
Close a connection.
getLazyConnectionRef( $i, $groups=[], $domain=false, $flags=0)
Get a database handle reference for a real or virtual (DB_MASTER/DB_REPLICA) server index...
runMasterTransactionIdleCallbacks( $fname=__METHOD__, $owner=null)
Consume and run all pending post-COMMIT/ROLLBACK callbacks and commit dangling transactions.
const DB_MASTER
Definition: defines.php:26
getServerType( $i)
Get DB type of the server with the specified index.
waitForAll( $pos, $timeout=null)
Set the master wait position and wait for ALL replica DBs to catch up to it.
getServerCount()
Get the number of servers defined in configuration.
getReaderIndex( $group=false, $domain=false)
Get the server index of the reader connection for a given group.
flushReplicaSnapshots( $fname=__METHOD__)
Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
lastMasterChangeTimestamp()
Get the timestamp of the latest write query done by this thread.
hasMasterChanges()
Whether there are pending changes or callbacks in a transaction by this thread.
allowLagged( $mode=null)
Disables/enables lag checks.
getServerName( $i)
Get the host name or IP address of the server with the specified index.
setIndexAliases(array $aliases)
Convert certain index names to alternative names before querying the DB.
forEachOpenReplicaConnection( $callback, array $params=[])
Call a function with each open replica DB connection object.
forEachOpenConnection( $callback, array $params=[])
Call a function with each open connection object.
laggedReplicaUsed()
Checks whether the database for generic connections this request was both:
rollbackMasterChanges( $fname=__METHOD__, $owner=null)
Issue ROLLBACK only on master, only if queries were done on connection.
$params
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 & $options
Definition: hooks.txt:1972
hasStreamingReplicaServers()
Whether any replica servers use streaming replication from the master server.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
getMaintenanceConnectionRef( $i, $groups=[], $domain=false, $flags=0)
Get a live database handle for a real or virtual (DB_MASTER/DB_REPLICA) server index that can be used...
beginMasterChanges( $fname=__METHOD__, $owner=null)
Flush any master transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set)
getServerConnection( $i, $domain, $flags=0)
Get a live handle for a server index.
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings, LocalSettings).
Definition: Setup.php:131
getServerInfo( $i)
Return the server info structure for a given index or false if the index is invalid.
hasOrMadeRecentMasterChanges( $age=null)
Check if this load balancer object had any recent or still pending writes issued against it by this P...
getConnectionRef( $i, $groups=[], $domain=false, $flags=0)
Get a live database handle reference for a real or virtual (DB_MASTER/DB_REPLICA) server index...
runMasterTransactionListenerCallbacks( $fname=__METHOD__, $owner=null)
Run all recurring post-COMMIT/ROLLBACK listener callbacks.
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
getLaggedReplicaMode( $domain=false)
getWriterIndex()
Get the server index of the master server.
Database cluster connection, tracking, load balancing, and transaction manager interface.
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
hasReplicaServers()
Whether there are any replica servers configured.
getMasterPos()
Get the current master replication position.
reuseConnection(IDatabase $conn)
Mark a live handle as being available for reuse under a different database domain.
approveMasterChanges(array $options, $fname, $owner=null)
Perform all pre-commit checks for things like replication safety.
waitForOne( $pos, $timeout=null)
Set the master wait position and wait for a generic replica DB to catch up to it. ...
commitAll( $fname=__METHOD__, $owner=null)
Commit transactions on all open connections.
setTableAliases(array $aliases)
Make certain table names use their own database, schema, and table prefix when passed into SQL querie...
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
getLocalDomainID()
Get the local (and default) database domain ID of connection handles.
const DB_REPLICA
Definition: defines.php:25
getReadOnlyReason( $domain=false, IDatabase $conn=null)
closeAll()
Close all open connections.
waitForMasterPos(IDatabase $conn, $pos=false, $timeout=10)
Wait for a replica DB to reach a specified master position.
__construct(array $params)
Construct a manager of IDatabase connection objects.
getReplicaResumePos()
Get the highest DB replication position for chronology control purposes.
finalizeMasterChanges( $fname=__METHOD__, $owner=null)
Run pre-commit callbacks and defer execution of post-commit callbacks.
pendingMasterChangeCallers()
Get the list of callers that have pending master changes.
getMaxLag( $domain=false)
Get the hostname and lag time of the most-lagged replica server.
setTransactionListener( $name, callable $callback=null)
Set a callback via IDatabase::setTransactionListener() on all current and future master connections o...