MediaWiki REL1_33
ILoadBalancer.php
Go to the documentation of this file.
1<?php
23namespace Wikimedia\Rdbms;
24
25use Exception;
26use InvalidArgumentException;
27
78interface ILoadBalancer {
80 const DB_REPLICA = -1;
82 const DB_MASTER = -2;
83
85 const DOMAIN_ANY = '';
86
88 const CONN_TRX_AUTOCOMMIT = 1;
89
91 const STAGE_POSTCOMMIT_CALLBACKS = 'stage-postcommit-callbacks';
93 const STAGE_POSTROLLBACK_CALLBACKS = 'stage-postrollback-callbacks';
94
121 public function __construct( array $params );
122
130 public function getLocalDomainID();
131
137 public function resolveDomainID( $domain );
138
145 public function redefineLocalDomain( $domain );
146
159 public function getReaderIndex( $group = false, $domain = false );
160
173 public function waitFor( $pos );
174
184 public function waitForOne( $pos, $timeout = null );
185
193 public function waitForAll( $pos, $timeout = null );
194
205 public function getAnyOpenConnection( $i, $flags = 0 );
206
229 public function getConnection( $i, $groups = [], $domain = false, $flags = 0 );
230
240 public function reuseConnection( IDatabase $conn );
241
260 public function getConnectionRef( $i, $groups = [], $domain = false, $flags = 0 );
261
280 public function getLazyConnectionRef( $i, $groups = [], $domain = false, $flags = 0 );
281
300 public function getMaintenanceConnectionRef( $i, $groups = [], $domain = false, $flags = 0 );
301
325 public function openConnection( $i, $domain = false, $flags = 0 );
326
330 public function getWriterIndex();
331
338 public function haveIndex( $i );
339
346 public function isNonZeroLoad( $i );
347
353 public function getServerCount();
354
361 public function getServerName( $i );
362
369 public function getServerInfo( $i );
370
378 public function getServerType( $i );
379
385 public function getServerAttributes( $i );
386
391 public function getMasterPos();
392
397 public function disable();
398
402 public function closeAll();
403
412 public function closeConnection( IDatabase $conn );
413
419 public function commitAll( $fname = __METHOD__ );
420
428 public function finalizeMasterChanges();
429
440
453 public function beginMasterChanges( $fname = __METHOD__ );
454
460 public function commitMasterChanges( $fname = __METHOD__ );
461
468
475
481 public function rollbackMasterChanges( $fname = __METHOD__ );
482
488 public function flushReplicaSnapshots( $fname = __METHOD__ );
489
497 public function flushMasterSnapshots( $fname = __METHOD__ );
498
502 public function hasMasterConnection();
503
508 public function hasMasterChanges();
509
514 public function lastMasterChangeTimestamp();
515
523 public function hasOrMadeRecentMasterChanges( $age = null );
524
530 public function pendingMasterChangeCallers();
531
537 public function getLaggedReplicaMode( $domain = false );
538
547 public function laggedReplicaUsed();
548
555 public function getReadOnlyReason( $domain = false, IDatabase $conn = null );
556
562 public function allowLagged( $mode = null );
563
567 public function pingAll();
568
574 public function forEachOpenConnection( $callback, array $params = [] );
575
581 public function forEachOpenMasterConnection( $callback, array $params = [] );
582
588 public function forEachOpenReplicaConnection( $callback, array $params = [] );
589
600 public function getMaxLag( $domain = false );
601
612 public function getLagTimes( $domain = false );
613
628 public function safeGetLag( IDatabase $conn );
629
640 public function safeWaitForMasterPos( IDatabase $conn, $pos = false, $timeout = 10 );
641
649 public function setTransactionListener( $name, callable $callback = null );
650
657 public function setLocalDomainPrefix( $prefix );
658
671 public function setTableAliases( array $aliases );
672
685 public function setIndexAliases( array $aliases );
686}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition Setup.php:123
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:1999
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:37
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
Database cluster connection, tracking, load balancing, and transaction manager interface.
approveMasterChanges(array $options)
Perform all pre-commit checks for things like replication safety.
reuseConnection(IDatabase $conn)
Mark a foreign connection as being available for reuse under a different DB domain.
forEachOpenConnection( $callback, array $params=[])
Call a function with each open connection object.
finalizeMasterChanges()
Run pre-commit callbacks and defer execution of post-commit callbacks.
getConnection( $i, $groups=[], $domain=false, $flags=0)
Get a connection handle by server index.
rollbackMasterChanges( $fname=__METHOD__)
Issue ROLLBACK only on master, only if queries were done on connection.
getServerType( $i)
Get DB type of the server with the specified index.
getMaxLag( $domain=false)
Get the hostname and lag time of the most-lagged replica DB.
waitFor( $pos)
Set the master wait position.
safeWaitForMasterPos(IDatabase $conn, $pos=false, $timeout=10)
Wait for a replica DB to reach a specified master position.
runMasterTransactionIdleCallbacks()
Consume and run all pending post-COMMIT/ROLLBACK callbacks and commit dangling transactions.
setTransactionListener( $name, callable $callback=null)
Set a callback via IDatabase::setTransactionListener() on all current and future master connections o...
getReaderIndex( $group=false, $domain=false)
Get the index of the reader connection, which may be a replica DB.
hasOrMadeRecentMasterChanges( $age=null)
Check if this load balancer object had any recent or still pending writes issued against it by this P...
forEachOpenMasterConnection( $callback, array $params=[])
Call a function with each open connection object to a master.
beginMasterChanges( $fname=__METHOD__)
Flush any master transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set)
getReadOnlyReason( $domain=false, IDatabase $conn=null)
getLaggedReplicaMode( $domain=false)
pendingMasterChangeCallers()
Get the list of callers that have pending master changes.
flushMasterSnapshots( $fname=__METHOD__)
Commit all master DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
getMasterPos()
Get the current master position for chronology control purposes.
haveIndex( $i)
Returns true if the specified index is a valid server index.
hasMasterChanges()
Whether there are pending changes or callbacks in a transaction by this thread.
setTableAliases(array $aliases)
Make certain table names use their own database, schema, and table prefix when passed into SQL querie...
redefineLocalDomain( $domain)
Close all connection and redefine the local domain for testing or schema creation.
__construct(array $params)
Construct a manager of IDatabase connection objects.
commitMasterChanges( $fname=__METHOD__)
Issue COMMIT on all open master connections to flush changes and view snapshots.
forEachOpenReplicaConnection( $callback, array $params=[])
Call a function with each open replica DB connection object.
disable()
Disable this load balancer.
openConnection( $i, $domain=false, $flags=0)
Open a connection to the server given by the specified index.
isNonZeroLoad( $i)
Returns true if the specified index is valid and has non-zero load.
laggedReplicaUsed()
Checks whether the database for generic connections this request was both:
getServerCount()
Get the number of defined servers (not the number of open connections)
getLocalDomainID()
Get the local (and default) database domain ID of connection handles.
getServerInfo( $i)
Return the server info structure for a given index, or false if the index is invalid.
getConnectionRef( $i, $groups=[], $domain=false, $flags=0)
Get a database connection handle reference.
flushReplicaSnapshots( $fname=__METHOD__)
Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
getMaintenanceConnectionRef( $i, $groups=[], $domain=false, $flags=0)
Get a maintenance database connection handle reference for migrations and schema changes.
setIndexAliases(array $aliases)
Convert certain index names to alternative names before querying the DB.
getLazyConnectionRef( $i, $groups=[], $domain=false, $flags=0)
Get a database connection handle reference without connecting yet.
lastMasterChangeTimestamp()
Get the timestamp of the latest write query done by this thread.
runMasterTransactionListenerCallbacks()
Run all recurring post-COMMIT/ROLLBACK listener callbacks.
setLocalDomainPrefix( $prefix)
Set a new table prefix for the existing local domain ID for testing.
closeConnection(IDatabase $conn)
Close a connection.
commitAll( $fname=__METHOD__)
Commit transactions on all open connections.
allowLagged( $mode=null)
Disables/enables lag checks.
closeAll()
Close all open connections.
getLagTimes( $domain=false)
Get an estimate of replication lag (in seconds) for each server.
waitForOne( $pos, $timeout=null)
Set the master wait position and wait for a "generic" replica DB to catch up to it.
getServerName( $i)
Get the host name or IP address 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.
getAnyOpenConnection( $i, $flags=0)
Get any open connection to a given server index, local or foreign.
safeGetLag(IDatabase $conn)
Get the lag in seconds for a given connection, or zero if this load balancer does not have replicatio...
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
const DB_REPLICA
Definition defines.php:25
const DB_MASTER
Definition defines.php:26
$params