MediaWiki  1.34.0
ILoadBalancer.php
Go to the documentation of this file.
1 <?php
23 namespace Wikimedia\Rdbms;
24 
25 use Exception;
26 use LogicException;
27 use InvalidArgumentException;
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;
99  const CONN_REFRESH_READ_ONLY = 8;
100 
102  const STAGE_POSTCOMMIT_CALLBACKS = 'stage-postcommit-callbacks';
104  const STAGE_POSTROLLBACK_CALLBACKS = 'stage-postrollback-callbacks';
105 
134  public function __construct( array $params );
135 
143  public function getLocalDomainID();
144 
150  public function resolveDomainID( $domain );
151 
158  public function redefineLocalDomain( $domain );
159 
170  public function setTempTablesOnlyMode( $value, $domain );
171 
186  public function getReaderIndex( $group = false, $domain = false );
187 
200  public function waitFor( $pos );
201 
211  public function waitForOne( $pos, $timeout = null );
212 
220  public function waitForAll( $pos, $timeout = null );
221 
233  public function getAnyOpenConnection( $i, $flags = 0 );
234 
297  public function getConnection( $i, $groups = [], $domain = false, $flags = 0 );
298 
314  public function getServerConnection( $i, $domain, $flags = 0 );
315 
329  public function reuseConnection( IDatabase $conn );
330 
347  public function getConnectionRef( $i, $groups = [], $domain = false, $flags = 0 );
348 
368  public function getLazyConnectionRef( $i, $groups = [], $domain = false, $flags = 0 );
369 
390  public function getMaintenanceConnectionRef( $i, $groups = [], $domain = false, $flags = 0 );
391 
397  public function getWriterIndex();
398 
404  public function getServerCount();
405 
415  public function hasReplicaServers();
416 
436  public function hasStreamingReplicaServers();
437 
444  public function getServerName( $i );
445 
452  public function getServerInfo( $i );
453 
461  public function getServerType( $i );
462 
468  public function getServerAttributes( $i );
469 
476  public function getMasterPos();
477 
493  public function getReplicaResumePos();
494 
503  public function disable( $fname = __METHOD__, $owner = null );
504 
511  public function closeAll( $fname = __METHOD__, $owner = null );
512 
521  public function closeConnection( IDatabase $conn );
522 
529  public function commitAll( $fname = __METHOD__, $owner = null );
530 
540  public function finalizeMasterChanges( $fname = __METHOD__, $owner = null );
541 
553  public function approveMasterChanges( array $options, $fname, $owner = null );
554 
568  public function beginMasterChanges( $fname = __METHOD__, $owner = null );
569 
576  public function commitMasterChanges( $fname = __METHOD__, $owner = null );
577 
585  public function runMasterTransactionIdleCallbacks( $fname = __METHOD__, $owner = null );
586 
594  public function runMasterTransactionListenerCallbacks( $fname = __METHOD__, $owner = null );
595 
602  public function rollbackMasterChanges( $fname = __METHOD__, $owner = null );
603 
610  public function flushReplicaSnapshots( $fname = __METHOD__, $owner = null );
611 
620  public function flushMasterSnapshots( $fname = __METHOD__, $owner = null );
621 
625  public function hasMasterConnection();
626 
631  public function hasMasterChanges();
632 
637  public function lastMasterChangeTimestamp();
638 
646  public function hasOrMadeRecentMasterChanges( $age = null );
647 
653  public function pendingMasterChangeCallers();
654 
660  public function getLaggedReplicaMode( $domain = false );
661 
670  public function laggedReplicaUsed();
671 
677  public function getReadOnlyReason( $domain = false );
678 
684  public function allowLagged( $mode = null );
685 
689  public function pingAll();
690 
696  public function forEachOpenConnection( $callback, array $params = [] );
697 
703  public function forEachOpenMasterConnection( $callback, array $params = [] );
704 
710  public function forEachOpenReplicaConnection( $callback, array $params = [] );
711 
722  public function getMaxLag( $domain = false );
723 
734  public function getLagTimes( $domain = false );
735 
749  public function waitForMasterPos( IDatabase $conn, $pos = false, $timeout = 10 );
750 
758  public function setTransactionListener( $name, callable $callback = null );
759 
766  public function setLocalDomainPrefix( $prefix );
767 
780  public function setTableAliases( array $aliases );
781 
794  public function setIndexAliases( array $aliases );
795 }
Wikimedia\Rdbms\ILoadBalancer\pendingMasterChangeCallers
pendingMasterChangeCallers()
Get the list of callers that have pending master changes.
Wikimedia\Rdbms\ILoadBalancer\resolveDomainID
resolveDomainID( $domain)
Wikimedia\Rdbms\ILoadBalancer\pingAll
pingAll()
Wikimedia\Rdbms\ILoadBalancer\setTempTablesOnlyMode
setTempTablesOnlyMode( $value, $domain)
Indicate whether the tables on this domain are only temporary tables for testing.
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\redefineLocalDomain
redefineLocalDomain( $domain)
Close all connection and redefine the local domain for testing or schema creation.
Wikimedia\Rdbms\ILoadBalancer\forEachOpenMasterConnection
forEachOpenMasterConnection( $callback, array $params=[])
Call a function with each open connection object to a master.
Wikimedia\Rdbms\ILoadBalancer\setIndexAliases
setIndexAliases(array $aliases)
Convert certain index names to alternative names before querying the DB.
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\getLazyConnectionRef
getLazyConnectionRef( $i, $groups=[], $domain=false, $flags=0)
Get a database handle reference for a real or virtual (DB_MASTER/DB_REPLICA) server index.
Wikimedia\Rdbms\ILoadBalancer\getConnection
getConnection( $i, $groups=[], $domain=false, $flags=0)
Get a live handle for a real or virtual (DB_MASTER/DB_REPLICA) server index.
Wikimedia\Rdbms\ILoadBalancer\getReadOnlyReason
getReadOnlyReason( $domain=false)
Wikimedia\Rdbms\ILoadBalancer\disable
disable( $fname=__METHOD__, $owner=null)
Close all connections and disable this load balancer.
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24
Wikimedia\Rdbms\ILoadBalancer\getServerCount
getServerCount()
Get the number of servers defined in configuration.
Wikimedia\Rdbms\ILoadBalancer\setLocalDomainPrefix
setLocalDomainPrefix( $prefix)
Set a new table prefix for the existing local domain ID for testing.
Wikimedia\Rdbms\ILoadBalancer\runMasterTransactionIdleCallbacks
runMasterTransactionIdleCallbacks( $fname=__METHOD__, $owner=null)
Consume and run all pending post-COMMIT/ROLLBACK callbacks and commit dangling transactions.
Wikimedia\Rdbms\ILoadBalancer\getConnectionRef
getConnectionRef( $i, $groups=[], $domain=false, $flags=0)
Get a live database handle reference for a real or virtual (DB_MASTER/DB_REPLICA) server index.
Wikimedia\Rdbms\ILoadBalancer\runMasterTransactionListenerCallbacks
runMasterTransactionListenerCallbacks( $fname=__METHOD__, $owner=null)
Run all recurring post-COMMIT/ROLLBACK listener callbacks.
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
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\getServerAttributes
getServerAttributes( $i)
Wikimedia\Rdbms\ILoadBalancer\allowLagged
allowLagged( $mode=null)
Disables/enables lag checks.
Wikimedia\Rdbms\ILoadBalancer\hasReplicaServers
hasReplicaServers()
Whether there are any replica servers configured.
Wikimedia\Rdbms\ILoadBalancer\reuseConnection
reuseConnection(IDatabase $conn)
Mark a live handle as being available for reuse under a different database domain.
Wikimedia\Rdbms\ILoadBalancer\getServerName
getServerName( $i)
Get the host name or IP address of the server with the specified index.
Wikimedia\Rdbms\ILoadBalancer\forEachOpenConnection
forEachOpenConnection( $callback, array $params=[])
Call a function with each open connection object.
Wikimedia\Rdbms\ILoadBalancer\beginMasterChanges
beginMasterChanges( $fname=__METHOD__, $owner=null)
Flush any master transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set)
Wikimedia\Rdbms\ILoadBalancer\approveMasterChanges
approveMasterChanges(array $options, $fname, $owner=null)
Perform all pre-commit checks for things like replication safety.
Wikimedia\Rdbms\ILoadBalancer\getMaxLag
getMaxLag( $domain=false)
Get the hostname and lag time of the most-lagged replica server.
Wikimedia\Rdbms\ILoadBalancer\getLocalDomainID
getLocalDomainID()
Get the local (and default) database domain ID of connection handles.
Wikimedia\Rdbms\ILoadBalancer\getMasterPos
getMasterPos()
Get the current master replication position.
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()
Get the server index of the master server.
Wikimedia\Rdbms\ILoadBalancer\getMaintenanceConnectionRef
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...
Wikimedia\Rdbms\ILoadBalancer\waitFor
waitFor( $pos)
Set the master position to reach before the next generic group DB handle query.
Wikimedia\Rdbms\ILoadBalancer\flushMasterSnapshots
flushMasterSnapshots( $fname=__METHOD__, $owner=null)
Commit all master DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
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__, $owner=null)
Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
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\waitForMasterPos
waitForMasterPos(IDatabase $conn, $pos=false, $timeout=10)
Wait for a replica DB to reach a specified master position.
Wikimedia\Rdbms\ILoadBalancer\finalizeMasterChanges
finalizeMasterChanges( $fname=__METHOD__, $owner=null)
Run pre-commit callbacks and defer execution of post-commit callbacks.
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 server index of the reader connection for a given group.
Wikimedia\Rdbms\ILoadBalancer\getReplicaResumePos
getReplicaResumePos()
Get the highest DB replication position for chronology control purposes.
Wikimedia\Rdbms\ILoadBalancer\getServerConnection
getServerConnection( $i, $domain, $flags=0)
Get a live handle for a server index.
Wikimedia\Rdbms\ILoadBalancer\rollbackMasterChanges
rollbackMasterChanges( $fname=__METHOD__, $owner=null)
Issue ROLLBACK only on master, only if queries were done on connection.
Wikimedia\Rdbms\ILoadBalancer\__construct
__construct(array $params)
Construct a manager of IDatabase connection objects.
Wikimedia\Rdbms\ILoadBalancer\hasStreamingReplicaServers
hasStreamingReplicaServers()
Whether any replica servers use streaming replication from the master server.
Wikimedia\Rdbms\ILoadBalancer\getAnyOpenConnection
getAnyOpenConnection( $i, $flags=0)
Get any open connection to a given server index, local or foreign.
Wikimedia\Rdbms\ILoadBalancer\hasMasterChanges
hasMasterChanges()
Whether there are pending changes or callbacks in a transaction by this thread.
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\getServerType
getServerType( $i)
Get DB type of the server with the specified index.
Wikimedia\Rdbms\ILoadBalancer\lastMasterChangeTimestamp
lastMasterChangeTimestamp()
Get the timestamp of the latest write query done by this thread.
Wikimedia\Rdbms\ILoadBalancer\closeAll
closeAll( $fname=__METHOD__, $owner=null)
Close all open connections.
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81
Wikimedia\Rdbms\ILoadBalancer\getLagTimes
getLagTimes( $domain=false)
Get an estimate of replication lag (in seconds) for each server.
Wikimedia\Rdbms\ILoadBalancer\commitAll
commitAll( $fname=__METHOD__, $owner=null)
Commit transactions on all open connections.
Wikimedia\Rdbms\ILoadBalancer\commitMasterChanges
commitMasterChanges( $fname=__METHOD__, $owner=null)
Issue COMMIT on all open master connections to flush changes and view snapshots.