MediaWiki fundraising/REL1_35
ILoadBalancer.php
Go to the documentation of this file.
1<?php
23namespace Wikimedia\Rdbms;
24
25use Exception;
26use InvalidArgumentException;
27use LogicException;
28
81interface ILoadBalancer {
83 public const DB_REPLICA = -1;
84
89 public const DB_PRIMARY = -2;
95
97 public const DOMAIN_ANY = '';
99 public const GROUP_GENERIC = '';
100
102 public const CONN_TRX_AUTOCOMMIT = 1;
104 public const CONN_SILENCE_ERRORS = 2;
106 public const CONN_INTENT_WRITABLE = 4;
108 public const CONN_REFRESH_READ_ONLY = 8;
109
111 public const STAGE_POSTCOMMIT_CALLBACKS = 'stage-postcommit-callbacks';
113 public const STAGE_POSTROLLBACK_CALLBACKS = 'stage-postrollback-callbacks';
114
143 public function __construct( array $params );
144
152 public function getLocalDomainID();
153
159 public function resolveDomainID( $domain );
160
167 public function redefineLocalDomain( $domain );
168
179 public function setTempTablesOnlyMode( $value, $domain );
180
195 public function getReaderIndex( $group = false, $domain = false );
196
209 public function waitFor( $pos );
210
220 public function waitForOne( $pos, $timeout = null );
221
229 public function waitForAll( $pos, $timeout = null );
230
242 public function getAnyOpenConnection( $i, $flags = 0 );
243
306 public function getConnection( $i, $groups = [], $domain = false, $flags = 0 );
307
323 public function getServerConnection( $i, $domain, $flags = 0 );
324
338 public function reuseConnection( IDatabase $conn );
339
356 public function getConnectionRef( $i, $groups = [], $domain = false, $flags = 0 );
357
377 public function getLazyConnectionRef( $i, $groups = [], $domain = false, $flags = 0 );
378
399 public function getMaintenanceConnectionRef( $i, $groups = [], $domain = false, $flags = 0 );
400
406 public function getWriterIndex();
407
413 public function getServerCount();
414
424 public function hasReplicaServers();
425
445 public function hasStreamingReplicaServers();
446
453 public function getServerName( $i );
454
461 public function getServerInfo( $i );
462
470 public function getServerType( $i );
471
477 public function getServerAttributes( $i );
478
485 public function getMasterPos();
486
502 public function getReplicaResumePos();
503
512 public function disable( $fname = __METHOD__, $owner = null );
513
520 public function closeAll( $fname = __METHOD__, $owner = null );
521
530 public function closeConnection( IDatabase $conn );
531
538 public function commitAll( $fname = __METHOD__, $owner = null );
539
549 public function finalizeMasterChanges( $fname = __METHOD__, $owner = null );
550
562 public function approveMasterChanges( array $options, $fname, $owner = null );
563
577 public function beginMasterChanges( $fname = __METHOD__, $owner = null );
578
585 public function commitMasterChanges( $fname = __METHOD__, $owner = null );
586
594 public function runMasterTransactionIdleCallbacks( $fname = __METHOD__, $owner = null );
595
603 public function runMasterTransactionListenerCallbacks( $fname = __METHOD__, $owner = null );
604
611 public function rollbackMasterChanges( $fname = __METHOD__, $owner = null );
612
619 public function flushReplicaSnapshots( $fname = __METHOD__, $owner = null );
620
629 public function flushMasterSnapshots( $fname = __METHOD__, $owner = null );
630
634 public function hasMasterConnection();
635
640 public function hasMasterChanges();
641
646 public function lastMasterChangeTimestamp();
647
655 public function hasOrMadeRecentMasterChanges( $age = null );
656
662 public function pendingMasterChangeCallers();
663
669 public function getLaggedReplicaMode( $domain = false );
670
679 public function laggedReplicaUsed();
680
686 public function getReadOnlyReason( $domain = false );
687
693 public function allowLagged( $mode = null );
694
698 public function pingAll();
699
705 public function forEachOpenConnection( $callback, array $params = [] );
706
712 public function forEachOpenMasterConnection( $callback, array $params = [] );
713
719 public function forEachOpenReplicaConnection( $callback, array $params = [] );
720
731 public function getMaxLag( $domain = false );
732
743 public function getLagTimes( $domain = false );
744
758 public function waitForMasterPos( IDatabase $conn, $pos = false, $timeout = 10 );
759
767 public function setTransactionListener( $name, callable $callback = null );
768
775 public function setLocalDomainPrefix( $prefix );
776
789 public function setTableAliases( array $aliases );
790
803 public function setIndexAliases( array $aliases );
804
813 public function setDomainAliases( array $aliases );
814}
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.
runMasterTransactionIdleCallbacks( $fname=__METHOD__, $owner=null)
Consume and run all pending post-COMMIT/ROLLBACK callbacks and commit dangling transactions.
flushMasterSnapshots( $fname=__METHOD__, $owner=null)
Commit all master DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
reuseConnection(IDatabase $conn)
Mark a live handle as being available for reuse under a different database domain.
forEachOpenConnection( $callback, array $params=[])
Call a function with each open connection object.
waitForMasterPos(IDatabase $conn, $pos=false, $timeout=10)
Wait for a replica DB to reach a specified master position.
getConnection( $i, $groups=[], $domain=false, $flags=0)
Get a live handle for a real or virtual (DB_MASTER/DB_REPLICA) server index.
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 server.
waitFor( $pos)
Set the master position to reach before the next generic group DB handle query.
rollbackMasterChanges( $fname=__METHOD__, $owner=null)
Issue ROLLBACK only on master, only if queries were done on connection.
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.
getReadOnlyReason( $domain=false)
getReplicaResumePos()
Get the highest DB replication position for chronology control purposes.
setTransactionListener( $name, callable $callback=null)
Set a callback via IDatabase::setTransactionListener() on all current and future master connections o...
commitMasterChanges( $fname=__METHOD__, $owner=null)
Issue COMMIT on all open master connections to flush changes and view snapshots.
disable( $fname=__METHOD__, $owner=null)
Close all connections and disable this load balancer.
getReaderIndex( $group=false, $domain=false)
Get the server index of the reader connection for a given group.
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.
getLaggedReplicaMode( $domain=false)
pendingMasterChangeCallers()
Get the list of callers that have pending master changes.
getMasterPos()
Get the current master replication position.
closeAll( $fname=__METHOD__, $owner=null)
Close all open connections.
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.
commitAll( $fname=__METHOD__, $owner=null)
Commit transactions on all open connections.
forEachOpenReplicaConnection( $callback, array $params=[])
Call a function with each open replica DB connection object.
setTempTablesOnlyMode( $value, $domain)
Indicate whether the tables on this domain are only temporary tables for testing.
getWriterIndex()
Get the server index of the master server.
setDomainAliases(array $aliases)
Convert certain database domains to alternative ones.
runMasterTransactionListenerCallbacks( $fname=__METHOD__, $owner=null)
Run all recurring post-COMMIT/ROLLBACK listener callbacks.
laggedReplicaUsed()
Checks whether the database for generic connections this request was both:
getServerCount()
Get the number of servers defined in configuration.
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 live database handle reference for a real or virtual (DB_MASTER/DB_REPLICA) server index.
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...
approveMasterChanges(array $options, $fname, $owner=null)
Perform all pre-commit checks for things like replication safety.
setIndexAliases(array $aliases)
Convert certain index names to alternative names before querying the DB.
getLazyConnectionRef( $i, $groups=[], $domain=false, $flags=0)
Get a database handle reference for a real or virtual (DB_MASTER/DB_REPLICA) server index.
const DB_MASTER
Request a primary, write-enabled DB connection.
lastMasterChangeTimestamp()
Get the timestamp of the latest write query done by this thread.
const DB_PRIMARY
Request a primary, write-enabled DB connection.
setLocalDomainPrefix( $prefix)
Set a new table prefix for the existing local domain ID for testing.
closeConnection(IDatabase $conn)
Close a connection.
finalizeMasterChanges( $fname=__METHOD__, $owner=null)
Run pre-commit callbacks and defer execution of post-commit callbacks.
allowLagged( $mode=null)
Disables/enables lag checks.
hasReplicaServers()
Whether there are any replica servers configured.
getLagTimes( $domain=false)
Get an estimate of replication lag (in seconds) for each server.
hasStreamingReplicaServers()
Whether any replica servers use streaming replication from the master 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.
flushReplicaSnapshots( $fname=__METHOD__, $owner=null)
Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
const DB_REPLICA
Definition defines.php:25