MediaWiki REL1_32
|
Database connection, tracking, load balancing, and transaction manager for a cluster. More...
Public Member Functions | |
__construct (array $params) | |
Construct a manager of IDatabase connection objects. | |
__destruct () | |
allowLagged ( $mode=null) | |
Disables/enables lag checks. | |
approveMasterChanges (array $options) | |
Perform all pre-commit checks for things like replication safety. | |
beginMasterChanges ( $fname=__METHOD__) | |
Flush any master transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set) | |
closeAll () | |
Close all open connections. | |
closeConnection (IDatabase $conn) | |
Close a connection. | |
commitAll ( $fname=__METHOD__) | |
Commit transactions on all open connections. | |
commitMasterChanges ( $fname=__METHOD__) | |
Issue COMMIT on all open master connections to flush changes and view snapshots. | |
disable () | |
Disable this load balancer. | |
finalizeMasterChanges () | |
Run pre-commit callbacks and defer execution of post-commit callbacks. | |
flushMasterSnapshots ( $fname=__METHOD__) | |
Commit all master DB transactions so as to flush any REPEATABLE-READ or SSI snapshots. | |
flushReplicaSnapshots ( $fname=__METHOD__) | |
Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshots. | |
forEachOpenConnection ( $callback, array $params=[]) | |
Call a function with each open connection object. | |
forEachOpenMasterConnection ( $callback, array $params=[]) | |
Call a function with each open connection object to a master. | |
forEachOpenReplicaConnection ( $callback, array $params=[]) | |
Call a function with each open replica DB connection object. | |
getAnyOpenConnection ( $i, $flags=0) | |
Get any open connection to a given server index, local or foreign. | |
getConnection ( $i, $groups=[], $domain=false, $flags=0) | |
Get a connection handle by server index. | |
getConnectionRef ( $db, $groups=[], $domain=false, $flags=0) | |
Get a database connection handle reference. | |
getLaggedReplicaMode ( $domain=false) | |
getLagTimes ( $domain=false) | |
Get an estimate of replication lag (in seconds) for each server. | |
getLazyConnectionRef ( $db, $groups=[], $domain=false, $flags=0) | |
Get a database connection handle reference without connecting yet. | |
getLocalDomainID () | |
Get the local (and default) database domain ID of connection handles. | |
getMaintenanceConnectionRef ( $db, $groups=[], $domain=false, $flags=0) | |
Get a maintenance database connection handle reference for migrations and schema changes. | |
getMasterPos () | |
Get the current master position for chronology control purposes. | |
getMaxLag ( $domain=false) | |
Get the hostname and lag time of the most-lagged replica DB. | |
getReaderIndex ( $group=false, $domain=false) | |
Get the index of the reader connection, which may be a replica DB. | |
getReadOnlyReason ( $domain=false, IDatabase $conn=null) | |
getServerAttributes ( $i) | |
getServerCount () | |
Get the number of defined servers (not the number of open connections) | |
getServerInfo ( $i) | |
Return the server info structure for a given index, or false if the index is invalid. | |
getServerName ( $i) | |
Get the host name or IP address of the server with the specified index. | |
getServerType ( $i) | |
Get DB type of the server with the specified index. | |
getTransactionRoundStage () | |
getWriterIndex () | |
hasMasterChanges () | |
Whether there are pending changes or callbacks in a transaction by this thread. | |
hasMasterConnection () | |
hasOrMadeRecentMasterChanges ( $age=null) | |
Check if this load balancer object had any recent or still pending writes issued against it by this PHP thread. | |
haveIndex ( $i) | |
Returns true if the specified index is a valid server 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: | |
laggedSlaveUsed () | |
lastMasterChangeTimestamp () | |
Get the timestamp of the latest write query done by this thread. | |
openConnection ( $i, $domain=false, $flags=0) | |
Open a connection to the server given by the specified index. | |
pendingMasterChangeCallers () | |
Get the list of callers that have pending master changes. | |
pingAll () | |
redefineLocalDomain ( $domain) | |
Close all connection and redefine the local domain for testing or schema creation. | |
resolveDomainID ( $domain) | |
reuseConnection (IDatabase $conn) | |
Mark a foreign connection as being available for reuse under a different DB domain. | |
rollbackMasterChanges ( $fname=__METHOD__) | |
Issue ROLLBACK only on master, only if queries were done on connection. | |
runMasterTransactionIdleCallbacks () | |
Consume and run all pending post-COMMIT/ROLLBACK callbacks and commit dangling transactions. | |
runMasterTransactionListenerCallbacks () | |
Run all recurring post-COMMIT/ROLLBACK listener callbacks. | |
safeGetLag (IDatabase $conn) | |
Get the lag in seconds for a given connection, or zero if this load balancer does not have replication enabled. | |
safeWaitForMasterPos (IDatabase $conn, $pos=false, $timeout=null) | |
setDomainPrefix ( $prefix) | |
Set a new table prefix for the existing local domain ID for testing. | |
setIndexAliases (array $aliases) | |
Convert certain index names to alternative names before querying the DB. | |
setTableAliases (array $aliases) | |
Make certain table names use their own database, schema, and table prefix when passed into SQL queries pre-escaped and without a qualified database name. | |
setTransactionListener ( $name, callable $callback=null) | |
Set a callback via IDatabase::setTransactionListener() on all current and future master connections of this load balancer. | |
waitFor ( $pos) | |
Set the master wait position. | |
waitForAll ( $pos, $timeout=null) | |
Set the master wait position and wait for ALL replica DBs to catch up to it. | |
waitForOne ( $pos, $timeout=null) | |
Set the master wait position and wait for a "generic" replica DB to catch up to it. | |
Public Attributes | |
const | KEY_FOREIGN_FREE = 'foreignFree' |
const | KEY_FOREIGN_FREE_NOROUND = 'foreignFreeAutoCommit' |
const | KEY_FOREIGN_INUSE = 'foreignInUse' |
const | KEY_FOREIGN_INUSE_NOROUND = 'foreignInUseAutoCommit' |
const | KEY_LOCAL = 'local' |
const | KEY_LOCAL_NOROUND = 'localAutoCommit' |
Protected Member Functions | |
doWait ( $index, $open=false, $timeout=null) | |
Wait for a given replica DB to catch up to the master pos stored in $this. | |
getScopedPHPBehaviorForCommit () | |
Make PHP ignore user aborts/disconnects until the returned value leaves scope. | |
reallyOpenConnection (array $server, DatabaseDomain $domain) | |
Open a new network connection to a server (uncached) | |
Private Member Functions | |
applyTransactionRoundFlags (Database $conn) | |
Make all DB servers with DBO_DEFAULT/DBO_TRX set join the transaction round. | |
assertTransactionRoundStage ( $stage) | |
getLoadMonitor () | |
Get a LoadMonitor instance. | |
getRandomNonLagged (array $loads, $domain=false, $maxLag=INF) | |
isOpen ( $index) | |
Test if the specified index represents an open connection. | |
masterRunningReadOnly ( $domain, IDatabase $conn=null) | |
openForeignConnection ( $i, $domain, $flags=0) | |
Open a connection to a foreign DB, or return one if it is already open. | |
openLocalConnection ( $i, $flags=0) | |
Open a connection to a local DB, or return one if it is already open. | |
pickReaderIndex (array $loads, $domain=false) | |
reportConnectionError () | |
setLocalDomain (DatabaseDomain $domain) | |
setWaitForPositionIfHigher ( $pos) | |
undoTransactionRoundFlags (Database $conn) | |
Private Attributes | |
string | $agent |
Agent name for query profiling. | |
bool | $allowLagged |
Whether to disregard replica DB lag as a factor in replica DB selection. | |
bool | $allReplicasDownMode = false |
Whether the generic reader fell back to a lagged replica DB. | |
callable null | $chronologyCallback |
Callback to run before the first connection attempt. | |
bool | $cliMode |
Whether this PHP instance is for a CLI script. | |
bool | $connectionAttempted = false |
Whether any connection has been attempted yet. | |
LoggerInterface | $connLogger |
Database[][][] | $conns |
Map of (connection category => server index => IDatabase[]) | |
int | $connsOpened = 0 |
Total connections opened. | |
string null | $defaultGroup = null |
callable | $deprecationLogger |
Deprecation logger. | |
bool | $disabled = false |
Database | $errorConnection |
DB connection object that caused a problem. | |
callable | $errorLogger |
Exception logger. | |
array[] | $groupLoads |
Map of (group => server index => weight) | |
string | $hostname |
Current server name. | |
string[] | $indexAliases = [] |
Map of (index alias => index) | |
bool | $laggedReplicaMode = false |
Whether the generic reader fell back to a lagged replica DB. | |
string | $lastError = 'Unknown error' |
The last DB selection or connection error. | |
ILoadMonitor | $loadMonitor |
array | $loadMonitorConfig |
The LoadMonitor configuration. | |
float[] | $loads |
Map of (server index => weight) | |
DatabaseDomain | $localDomain |
Local Domain ID and default for selectDB() calls. | |
string | $localDomainIdAlias |
Alternate ID string for the domain instead of DatabaseDomain::getId() | |
int | $maxLag = self::MAX_LAG_DEFAULT |
LoggerInterface | $perfLogger |
object string | $profiler |
Class name or object With profileIn/profileOut methods. | |
LoggerInterface | $queryLogger |
int | $readIndex |
The generic (not query grouped) replica DB index (of $mServers) | |
string bool | $readOnlyReason = false |
Reason the LB is read-only or false if not. | |
LoggerInterface | $replLogger |
array[] | $servers |
Map of (server index => server config array) | |
BagOStuff | $srvCache |
$tableAliases = [] | |
TransactionProfiler | $trxProfiler |
array[] | $trxRecurringCallbacks = [] |
Map of (name => callable) | |
string bool | $trxRoundId = false |
String if a requested DBO_TRX transaction round is active. | |
string | $trxRoundStage = self::ROUND_CURSORY |
Stage of the current transaction round in the transaction round life-cycle. | |
bool DBMasterPos | $waitForPos |
False if not set. | |
int | $waitTimeout |
Seconds to spend waiting on replica DB lag to resolve. | |
WANObjectCache | $wanCache |
Database connection, tracking, load balancing, and transaction manager for a cluster.
Definition at line 41 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::__construct | ( | array | $params | ) |
Construct a manager of IDatabase connection objects.
array | $params | Parameter map with keys:
|
InvalidArgumentException |
Implements Wikimedia\Rdbms\ILoadBalancer.
Reimplemented in Wikimedia\Rdbms\LoadBalancerSingle.
Definition at line 164 of file LoadBalancer.php.
References $e, Wikimedia\Rdbms\LoadBalancer\$localDomain, Wikimedia\Rdbms\LoadBalancer\$maxLag, $params, Wikimedia\Rdbms\LoadBalancer\allowLagged(), Wikimedia\Rdbms\DatabaseDomain\newFromId(), Wikimedia\Rdbms\DatabaseDomain\newUnspecified(), servers, and Wikimedia\Rdbms\LoadBalancer\setLocalDomain().
Wikimedia\Rdbms\LoadBalancer::__destruct | ( | ) |
Definition at line 1996 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\disable().
Wikimedia\Rdbms\LoadBalancer::allowLagged | ( | $mode = null | ) |
Disables/enables lag checks.
null | bool | $mode |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1750 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$allowLagged, and Wikimedia\Rdbms\LoadBalancer\allowLagged().
Referenced by Wikimedia\Rdbms\LoadBalancer\__construct(), Wikimedia\Rdbms\LoadBalancer\allowLagged(), and Wikimedia\Rdbms\LoadBalancer\pickReaderIndex().
|
private |
Make all DB servers with DBO_DEFAULT/DBO_TRX set join the transaction round.
Some servers may have neither flag enabled, meaning that they opt out of such transaction rounds and remain in auto-commit mode. Such behavior might be desired when a DB server is used for something like simple key/value storage.
Database | $conn |
Definition at line 1581 of file LoadBalancer.php.
References Wikimedia\Rdbms\Database\getFlag(), Wikimedia\Rdbms\Database\getLBInfo(), Wikimedia\Rdbms\Database\setFlag(), and Wikimedia\Rdbms\Database\setLBInfo().
Referenced by Wikimedia\Rdbms\LoadBalancer\beginMasterChanges(), and Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
Wikimedia\Rdbms\LoadBalancer::approveMasterChanges | ( | array | $options | ) |
Perform all pre-commit checks for things like replication safety.
Use this only for mutli-database commits
array | $options | Includes:
|
DBTransactionError |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1345 of file LoadBalancer.php.
References $options, $time, Wikimedia\Rdbms\IDatabase\assertNoOpenTransactions(), Wikimedia\Rdbms\LoadBalancer\assertTransactionRoundStage(), Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), Wikimedia\Rdbms\IDatabase\pendingWriteQueryDuration(), Wikimedia\Rdbms\IDatabase\ping(), and Wikimedia\Rdbms\IDatabase\writesOrCallbacksPending().
|
private |
string | string[] | $stage |
Definition at line 1555 of file LoadBalancer.php.
References array().
Referenced by Wikimedia\Rdbms\LoadBalancer\approveMasterChanges(), Wikimedia\Rdbms\LoadBalancer\beginMasterChanges(), Wikimedia\Rdbms\LoadBalancer\commitMasterChanges(), and Wikimedia\Rdbms\LoadBalancer\finalizeMasterChanges().
Wikimedia\Rdbms\LoadBalancer::beginMasterChanges | ( | $fname = __METHOD__ | ) |
Flush any master transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set)
The DBO_TRX setting will be reverted to the default in each of these methods:
string | $fname |
DBExpectedError |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1378 of file LoadBalancer.php.
References $fname, Wikimedia\Rdbms\LoadBalancer\applyTransactionRoundFlags(), Wikimedia\Rdbms\LoadBalancer\assertTransactionRoundStage(), Wikimedia\Rdbms\LoadBalancer\flushMasterSnapshots(), and Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection().
Wikimedia\Rdbms\LoadBalancer::closeAll | ( | ) |
Close all open connections.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1273 of file LoadBalancer.php.
References $fname, Wikimedia\Rdbms\IDatabase\close(), Wikimedia\Rdbms\LoadBalancer\forEachOpenConnection(), and Wikimedia\Rdbms\IDatabase\getServer().
Referenced by Wikimedia\Rdbms\LoadBalancer\disable(), and Wikimedia\Rdbms\LoadBalancer\redefineLocalDomain().
Wikimedia\Rdbms\LoadBalancer::closeConnection | ( | IDatabase | $conn | ) |
Close a connection.
Using this function makes sure the LoadBalancer knows the connection is closed. If you use $conn->close() directly, the load balancer won't update its state.
IDatabase | $conn |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1293 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$connsOpened, $type, Wikimedia\Rdbms\IDatabase\close(), Wikimedia\Rdbms\IDatabase\getLBInfo(), and Wikimedia\Rdbms\LoadBalancer\getServerName().
Referenced by Wikimedia\Rdbms\LoadBalancer\doWait(), and Wikimedia\Rdbms\LoadBalancer\safeWaitForMasterPos().
Wikimedia\Rdbms\LoadBalancer::commitAll | ( | $fname = __METHOD__ | ) |
Commit transactions on all open connections.
string | $fname | Caller name |
DBExpectedError |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1315 of file LoadBalancer.php.
References $fname, Wikimedia\Rdbms\LoadBalancer\commitMasterChanges(), Wikimedia\Rdbms\LoadBalancer\flushMasterSnapshots(), and Wikimedia\Rdbms\LoadBalancer\flushReplicaSnapshots().
Wikimedia\Rdbms\LoadBalancer::commitMasterChanges | ( | $fname = __METHOD__ | ) |
Issue COMMIT on all open master connections to flush changes and view snapshots.
string | $fname | Caller name |
DBExpectedError |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1402 of file LoadBalancer.php.
References $e, Wikimedia\Rdbms\LoadBalancer\$errorLogger, $fname, Wikimedia\Rdbms\LoadBalancer\assertTransactionRoundStage(), Wikimedia\Rdbms\IDatabase\commit(), false, Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), Wikimedia\Rdbms\LoadBalancer\getScopedPHPBehaviorForCommit(), and Wikimedia\Rdbms\LoadBalancer\undoTransactionRoundFlags().
Referenced by Wikimedia\Rdbms\LoadBalancer\commitAll().
Wikimedia\Rdbms\LoadBalancer::disable | ( | ) |
Disable this load balancer.
All connections are closed, and any attempt to open a new connection will result in a DBAccessError.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1268 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\closeAll().
Referenced by Wikimedia\Rdbms\LoadBalancer\__destruct().
|
protected |
Wait for a given replica DB to catch up to the master pos stored in $this.
int | $index | Server index |
bool | $open | Check the server even if a new connection has to be made |
int | null | $timeout | Max seconds to wait; default is "waitTimeout" given to __construct() |
Definition at line 610 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$waitTimeout, Wikimedia\Rdbms\LoadBalancer\closeConnection(), Wikimedia\Rdbms\LoadBalancer\getAnyOpenConnection(), Wikimedia\Rdbms\LoadBalancer\getServerName(), Wikimedia\Rdbms\DBMasterPos\hasReached(), and Wikimedia\Rdbms\LoadBalancer\openConnection().
Referenced by Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), Wikimedia\Rdbms\LoadBalancer\waitFor(), Wikimedia\Rdbms\LoadBalancer\waitForAll(), and Wikimedia\Rdbms\LoadBalancer\waitForOne().
Wikimedia\Rdbms\LoadBalancer::finalizeMasterChanges | ( | ) |
Run pre-commit callbacks and defer execution of post-commit callbacks.
Use this only for mutli-database commits
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1321 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\assertTransactionRoundStage(), Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), Wikimedia\Rdbms\Database\runOnTransactionPreCommitCallbacks(), and Wikimedia\Rdbms\Database\setTrxEndCallbackSuppression().
Wikimedia\Rdbms\LoadBalancer::flushMasterSnapshots | ( | $fname = __METHOD__ | ) |
Commit all master DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
An error will be thrown if a connection has pending writes or callbacks
string | $fname | Caller name |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1620 of file LoadBalancer.php.
References $fname, Wikimedia\Rdbms\IDatabase\flushSnapshot(), and Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection().
Referenced by Wikimedia\Rdbms\LoadBalancer\beginMasterChanges(), and Wikimedia\Rdbms\LoadBalancer\commitAll().
Wikimedia\Rdbms\LoadBalancer::flushReplicaSnapshots | ( | $fname = __METHOD__ | ) |
Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
string | $fname | Caller name |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1614 of file LoadBalancer.php.
References $fname, Wikimedia\Rdbms\IDatabase\flushSnapshot(), and Wikimedia\Rdbms\LoadBalancer\forEachOpenReplicaConnection().
Referenced by Wikimedia\Rdbms\LoadBalancer\commitAll().
Wikimedia\Rdbms\LoadBalancer::forEachOpenConnection | ( | $callback, | |
array | $params = [] ) |
Call a function with each open connection object.
callable | $callback | |
array | $params |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1770 of file LoadBalancer.php.
References $params.
Referenced by Wikimedia\Rdbms\LoadBalancer\closeAll(), Wikimedia\Rdbms\LoadBalancer\pingAll(), and Wikimedia\Rdbms\LoadBalancer\setDomainPrefix().
Wikimedia\Rdbms\LoadBalancer::forEachOpenMasterConnection | ( | $callback, | |
array | $params = [] ) |
Call a function with each open connection object to a master.
callable | $callback | |
array | $params |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1780 of file LoadBalancer.php.
References $params, and Wikimedia\Rdbms\LoadBalancer\getWriterIndex().
Referenced by Wikimedia\Rdbms\LoadBalancer\approveMasterChanges(), DeferredUpdates\areDatabaseTransactionsActive(), Wikimedia\Rdbms\LoadBalancer\beginMasterChanges(), Wikimedia\Rdbms\LoadBalancer\commitMasterChanges(), Wikimedia\Rdbms\LoadBalancer\finalizeMasterChanges(), Wikimedia\Rdbms\LoadBalancer\flushMasterSnapshots(), Wikimedia\Rdbms\LoadBalancer\hasMasterChanges(), Wikimedia\Rdbms\LoadBalancer\lastMasterChangeTimestamp(), Wikimedia\Rdbms\LoadBalancer\pendingMasterChangeCallers(), Wikimedia\Rdbms\LoadBalancer\rollbackMasterChanges(), Wikimedia\Rdbms\LoadBalancer\runMasterTransactionIdleCallbacks(), Wikimedia\Rdbms\LoadBalancer\runMasterTransactionListenerCallbacks(), and Wikimedia\Rdbms\LoadBalancer\setTransactionListener().
Wikimedia\Rdbms\LoadBalancer::forEachOpenReplicaConnection | ( | $callback, | |
array | $params = [] ) |
Call a function with each open replica DB connection object.
callable | $callback | |
array | $params |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1792 of file LoadBalancer.php.
References $params, and Wikimedia\Rdbms\LoadBalancer\getWriterIndex().
Referenced by Wikimedia\Rdbms\LoadBalancer\flushReplicaSnapshots().
Wikimedia\Rdbms\LoadBalancer::getAnyOpenConnection | ( | $i, | |
$flags = 0 ) |
Get any open connection to a given server index, local or foreign.
Use CONN_TRX_AUTOCOMMIT to only look for connections opened with that flag. Avoid the use of begin() or startAtomic() on any such connections.
int | $i | Server index or DB_MASTER/DB_REPLICA |
int | $flags | Bitfield of CONN_* class constants |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 586 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getMasterPos(), Wikimedia\Rdbms\LoadBalancer\isOpen(), and Wikimedia\Rdbms\LoadBalancer\safeWaitForMasterPos().
Wikimedia\Rdbms\LoadBalancer::getConnection | ( | $i, | |
$groups = [], | |||
$domain = false, | |||
$flags = 0 ) |
Get a connection handle by server index.
The CONN_TRX_AUTOCOMMIT flag is ignored for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in order to avoid deadlocks. ILoadBalancer::getServerAttributes() can be used to check such flags beforehand.
If the caller uses $domain or sets CONN_TRX_AUTOCOMMIT in $flags, then it must also call ILoadBalancer::reuseConnection() on the handle when finished using it. In all other cases, this is not necessary, though not harmful either. Avoid the use of begin() or startAtomic() on any such connections.
int | $i | Server index (overrides $groups) or DB_MASTER/DB_REPLICA |
array | string | bool | $groups | Query group(s), or false for the generic reader |
string | bool | $domain | Domain ID, or false for the current domain |
int | $flags | Bitfield of CONN_* class constants |
DBError |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 699 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$connsOpened, Wikimedia\Rdbms\LoadBalancer\$defaultGroup, Wikimedia\Rdbms\LoadBalancer\$lastError, array(), false, Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), Wikimedia\Rdbms\LoadBalancer\getReadOnlyReason(), Wikimedia\Rdbms\LoadBalancer\getServerAttributes(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), Wikimedia\Rdbms\LoadBalancer\openConnection(), and Wikimedia\Rdbms\LoadBalancer\reportConnectionError().
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnectionRef(), Wikimedia\Rdbms\LoadBalancer\getLaggedReplicaMode(), Wikimedia\Rdbms\LoadBalancer\getMaintenanceConnectionRef(), and Wikimedia\Rdbms\LoadBalancer\masterRunningReadOnly().
Wikimedia\Rdbms\LoadBalancer::getConnectionRef | ( | $i, | |
$groups = [], | |||
$domain = false, | |||
$flags = 0 ) |
Get a database connection handle reference.
The handle's methods simply wrap those of a Database handle
The CONN_TRX_AUTOCOMMIT flag is ignored for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in order to avoid deadlocks. ILoadBalancer::getServerAttributes() can be used to check such flags beforehand. Avoid the use of begin() or startAtomic() on any CONN_TRX_AUTOCOMMIT connections.
int | $i | Server index or DB_MASTER/DB_REPLICA |
array | string | bool | $groups | Query group(s), or false for the generic reader |
string | bool | $domain | Domain ID, or false for the current domain |
int | $flags | Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 848 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getConnection(), and Wikimedia\Rdbms\LoadBalancer\resolveDomainID().
Referenced by ImportableOldRevisionImporter\import().
Wikimedia\Rdbms\LoadBalancer::getLaggedReplicaMode | ( | $domain = false | ) |
string | bool | $domain | Domain ID, or false for the current domain |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1672 of file LoadBalancer.php.
References $e, Wikimedia\Rdbms\LoadBalancer\$laggedReplicaMode, Wikimedia\Rdbms\LoadBalancer\getConnection(), Wikimedia\Rdbms\LoadBalancer\getServerCount(), and Wikimedia\Rdbms\LoadBalancer\reuseConnection().
Referenced by Wikimedia\Rdbms\LoadBalancer\getReadOnlyReason().
Wikimedia\Rdbms\LoadBalancer::getLagTimes | ( | $domain = false | ) |
Get an estimate of replication lag (in seconds) for each server.
Results are cached for a short time in memcached/process cache
Values may be "false" if replication is too broken to estimate
string | bool | $domain |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1826 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getLoadMonitor(), Wikimedia\Rdbms\LoadBalancer\getServerCount(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), and servers.
Referenced by Wikimedia\Rdbms\LoadBalancer\getMaxLag(), and Wikimedia\Rdbms\LoadBalancer\getRandomNonLagged().
Wikimedia\Rdbms\LoadBalancer::getLazyConnectionRef | ( | $i, | |
$groups = [], | |||
$domain = false, | |||
$flags = 0 ) |
Get a database connection handle reference without connecting yet.
The handle's methods simply wrap those of a Database handle
The CONN_TRX_AUTOCOMMIT flag is ignored for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in order to avoid deadlocks. ILoadBalancer::getServerAttributes() can be used to check such flags beforehand. Avoid the use of begin() or startAtomic() on any CONN_TRX_AUTOCOMMIT connections.
int | $i | Server index or DB_MASTER/DB_REPLICA |
array | string | bool | $groups | Query group(s), or false for the generic reader |
string | bool | $domain | Domain ID, or false for the current domain |
int | $flags | Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 854 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\resolveDomainID().
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
Get a LoadMonitor instance.
Definition at line 286 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$loadMonitor.
Referenced by Wikimedia\Rdbms\LoadBalancer\getLagTimes(), and Wikimedia\Rdbms\LoadBalancer\getReaderIndex().
Wikimedia\Rdbms\LoadBalancer::getLocalDomainID | ( | ) |
Get the local (and default) database domain ID of connection handles.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 273 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\resolveDomainID().
Wikimedia\Rdbms\LoadBalancer::getMaintenanceConnectionRef | ( | $db, | |
$groups = [], | |||
$domain = false, | |||
$flags = 0 ) |
Get a maintenance database connection handle reference for migrations and schema changes.
The handle's methods simply wrap those of a Database handle
The CONN_TRX_AUTOCOMMIT flag is ignored for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in order to avoid deadlocks. ILoadBalancer::getServerAttributes() can be used to check such flags beforehand. Avoid the use of begin() or startAtomic() on any CONN_TRX_AUTOCOMMIT connections.
int | $db | Server index or DB_MASTER/DB_REPLICA |
array | string | bool | $groups | Query group(s), or false for the generic reader |
string | bool | $domain | Domain ID, or false for the current domain |
int | $flags | Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 860 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getConnection(), and Wikimedia\Rdbms\LoadBalancer\resolveDomainID().
Wikimedia\Rdbms\LoadBalancer::getMasterPos | ( | ) |
Get the current master position for chronology control purposes.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1249 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getAnyOpenConnection(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), and servers.
Wikimedia\Rdbms\LoadBalancer::getMaxLag | ( | $domain = false | ) |
Get the hostname and lag time of the most-lagged replica DB.
This is useful for maintenance scripts that need to throttle their updates. May attempt to open connections to replica DBs on the default DB. If there is no lag, the maximum lag will be reported as -1.
bool | string | $domain | Domain ID, or false for the default database |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1805 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$maxLag, Wikimedia\Rdbms\LoadBalancer\getLagTimes(), Wikimedia\Rdbms\LoadBalancer\getServerCount(), and servers.
|
private |
array | $loads | |
bool | string | $domain | Domain to get non-lagged for |
int | $maxLag | Restrict the maximum allowed lag to this many seconds |
Definition at line 313 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$loads, Wikimedia\Rdbms\LoadBalancer\$maxLag, Wikimedia\Rdbms\LoadBalancer\getLagTimes(), Wikimedia\Rdbms\LoadBalancer\getServerName(), ArrayUtils\pickRandom(), and servers.
Referenced by Wikimedia\Rdbms\LoadBalancer\pickReaderIndex().
Wikimedia\Rdbms\LoadBalancer::getReaderIndex | ( | $group = false, | |
$domain = false ) |
Get the index of the reader connection, which may be a replica DB.
This takes into account load ratios and lag times. It should always return a consistent index during a given invocation.
Side effect: opens connections to databases
string | bool | $group | Query group, or false for the generic reader |
string | bool | $domain | Domain ID, or false for the current domain |
DBError |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 362 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$laggedReplicaMode, Wikimedia\Rdbms\LoadBalancer\$loads, Wikimedia\Rdbms\LoadBalancer\$readIndex, Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getLoadMonitor(), Wikimedia\Rdbms\LoadBalancer\getServerName(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), list, Wikimedia\Rdbms\LoadBalancer\pickReaderIndex(), and servers.
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnection().
Wikimedia\Rdbms\LoadBalancer::getReadOnlyReason | ( | $domain = false, | |
IDatabase | $conn = null ) |
string | bool | $domain | Domain ID, or false for the current domain |
IDatabase | null | $conn | DB master connection; used to avoid loops [optional] |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1702 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$readOnlyReason, Wikimedia\Rdbms\LoadBalancer\getLaggedReplicaMode(), and Wikimedia\Rdbms\LoadBalancer\masterRunningReadOnly().
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnection().
|
finalprotected |
Make PHP ignore user aborts/disconnects until the returned value leaves scope.
This returns null and does nothing in CLI mode.
Definition at line 1985 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\commitMasterChanges().
Wikimedia\Rdbms\LoadBalancer::getServerAttributes | ( | $i | ) |
int | $i | Server index |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1066 of file LoadBalancer.php.
References Wikimedia\Rdbms\Database\attributesFromType(), Wikimedia\Rdbms\LoadBalancer\getServerType(), and servers.
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnection().
Wikimedia\Rdbms\LoadBalancer::getServerCount | ( | ) |
Get the number of defined servers (not the number of open connections)
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1221 of file LoadBalancer.php.
References servers.
Referenced by Wikimedia\Rdbms\LoadBalancer\getLaggedReplicaMode(), Wikimedia\Rdbms\LoadBalancer\getLagTimes(), Wikimedia\Rdbms\LoadBalancer\getMaxLag(), Wikimedia\Rdbms\LoadBalancer\safeGetLag(), and Wikimedia\Rdbms\LoadBalancer\safeWaitForMasterPos().
Wikimedia\Rdbms\LoadBalancer::getServerInfo | ( | $i | ) |
Return the server info structure for a given index, or false if the index is invalid.
int | $i |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1237 of file LoadBalancer.php.
References servers.
Wikimedia\Rdbms\LoadBalancer::getServerName | ( | $i | ) |
Get the host name or IP address of the server with the specified index.
int | $i |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1225 of file LoadBalancer.php.
References $name, and servers.
Referenced by Wikimedia\Rdbms\LoadBalancer\closeConnection(), Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getRandomNonLagged(), Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), Wikimedia\Rdbms\LoadBalancer\masterRunningReadOnly(), Wikimedia\Rdbms\LoadBalancer\openLocalConnection(), Wikimedia\Rdbms\LoadBalancer\pickReaderIndex(), and Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
Wikimedia\Rdbms\LoadBalancer::getServerType | ( | $i | ) |
Get DB type of the server with the specified index.
int | $i |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1245 of file LoadBalancer.php.
References servers.
Referenced by Wikimedia\Rdbms\LoadBalancer\getServerAttributes().
Wikimedia\Rdbms\LoadBalancer::getTransactionRoundStage | ( | ) |
Definition at line 1630 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$trxRoundStage.
Wikimedia\Rdbms\LoadBalancer::getWriterIndex | ( | ) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1209 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), Wikimedia\Rdbms\LoadBalancer\forEachOpenReplicaConnection(), Wikimedia\Rdbms\LoadBalancer\getConnection(), Wikimedia\Rdbms\LoadBalancer\getLagTimes(), Wikimedia\Rdbms\LoadBalancer\getMasterPos(), Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), Wikimedia\Rdbms\LoadBalancer\hasMasterConnection(), Wikimedia\Rdbms\LoadBalancer\masterRunningReadOnly(), Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection(), Wikimedia\Rdbms\LoadBalancer\safeWaitForMasterPos(), and Wikimedia\Rdbms\LoadBalancer\waitForOne().
Wikimedia\Rdbms\LoadBalancer::hasMasterChanges | ( | ) |
Whether there are pending changes or callbacks in a transaction by this thread.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1638 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), and Wikimedia\Rdbms\IDatabase\writesOrCallbacksPending().
Referenced by Wikimedia\Rdbms\LoadBalancer\hasOrMadeRecentMasterChanges().
Wikimedia\Rdbms\LoadBalancer::hasMasterConnection | ( | ) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1634 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), and Wikimedia\Rdbms\LoadBalancer\isOpen().
Wikimedia\Rdbms\LoadBalancer::hasOrMadeRecentMasterChanges | ( | $age = null | ) |
Check if this load balancer object had any recent or still pending writes issued against it by this PHP thread.
float | null | $age | How many seconds ago is "recent" [defaults to mWaitTimeout] |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1656 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\hasMasterChanges(), and Wikimedia\Rdbms\LoadBalancer\lastMasterChangeTimestamp().
Wikimedia\Rdbms\LoadBalancer::haveIndex | ( | $i | ) |
Returns true if the specified index is a valid server index.
int | $i |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1213 of file LoadBalancer.php.
References servers.
Wikimedia\Rdbms\LoadBalancer::isNonZeroLoad | ( | $i | ) |
Returns true if the specified index is valid and has non-zero load.
int | $i |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1217 of file LoadBalancer.php.
References servers.
|
private |
Test if the specified index represents an open connection.
int | $index | Server index |
Definition at line 1080 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getAnyOpenConnection().
Referenced by Wikimedia\Rdbms\LoadBalancer\hasMasterConnection().
Wikimedia\Rdbms\LoadBalancer::laggedReplicaUsed | ( | ) |
Checks whether the database for generic connections this request was both:
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1689 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$laggedReplicaMode.
Referenced by Wikimedia\Rdbms\LoadBalancer\laggedSlaveUsed().
Wikimedia\Rdbms\LoadBalancer::laggedSlaveUsed | ( | ) |
Definition at line 1698 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\laggedReplicaUsed().
Wikimedia\Rdbms\LoadBalancer::lastMasterChangeTimestamp | ( | ) |
Get the timestamp of the latest write query done by this thread.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1647 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), and Wikimedia\Rdbms\IDatabase\lastDoneWrites().
Referenced by Wikimedia\Rdbms\LoadBalancer\hasOrMadeRecentMasterChanges().
|
private |
string | $domain | Domain ID, or false for the current domain |
IDatabase | null | $conn | DB master connectionl used to avoid loops [optional] |
Definition at line 1725 of file LoadBalancer.php.
References $cache, $e, Wikimedia\Rdbms\LoadBalancer\$wanCache, function, Wikimedia\Rdbms\LoadBalancer\getConnection(), Wikimedia\Rdbms\LoadBalancer\getServerName(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), and Wikimedia\Rdbms\LoadBalancer\reuseConnection().
Referenced by Wikimedia\Rdbms\LoadBalancer\getReadOnlyReason().
Wikimedia\Rdbms\LoadBalancer::openConnection | ( | $i, | |
$domain = false, | |||
$flags = 0 ) |
Open a connection to the server given by the specified index.
The index must be an actual index into the array. If a connection to the server is already open and not considered an "in use" foreign connection, this simply returns it.
Avoid using CONN_TRX_AUTOCOMMIT for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in order to avoid deadlocks. ILoadBalancer::getServerAttributes() can be used to check such flags beforehand.
If the caller uses $domain or sets CONN_TRX_AUTOCOMMIT in $flags, then it must also call ILoadBalancer::reuseConnection() on the handle when finished using it. In all other cases, this is not necessary, though not harmful either. Avoid the use of begin() or startAtomic() on any such connections.
int | $i | Server index (does not support DB_MASTER/DB_REPLICA) |
string | bool | $domain | Domain ID, or false for the current domain |
int | $flags | Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT) |
DBAccessError |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 867 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$chronologyCallback, Wikimedia\Rdbms\IDatabase\isOpen(), Wikimedia\Rdbms\LoadBalancer\openForeignConnection(), and Wikimedia\Rdbms\LoadBalancer\openLocalConnection().
Referenced by Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getConnection(), Wikimedia\Rdbms\LoadBalancer\pickReaderIndex(), and Wikimedia\Rdbms\LoadBalancer\safeWaitForMasterPos().
|
private |
Open a connection to a foreign DB, or return one if it is already open.
Increments a reference count on the returned connection which locks the connection to the requested domain. This reference count can be decremented by calling reuseConnection().
If a connection is open to the appropriate server already, but with the wrong database, it will be switched to the right database and returned, as long as it has been freed first with reuseConnection().
On error, returns false, and the connection which caused the error will be available via $this->errorConnection.
int | $i | Server index |
string | $domain | Domain ID to open |
int | $flags | Class CONN_* constant bitfield |
DBError | When database selection fails |
Definition at line 991 of file LoadBalancer.php.
References key, Wikimedia\Rdbms\LoadBalancer\KEY_FOREIGN_FREE, Wikimedia\Rdbms\LoadBalancer\KEY_FOREIGN_FREE_NOROUND, Wikimedia\Rdbms\LoadBalancer\KEY_FOREIGN_INUSE, Wikimedia\Rdbms\LoadBalancer\KEY_FOREIGN_INUSE_NOROUND, Wikimedia\Rdbms\DatabaseDomain\newFromId(), Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection(), and servers.
Referenced by Wikimedia\Rdbms\LoadBalancer\openConnection().
|
private |
Open a connection to a local DB, or return one if it is already open.
On error, returns false, and the connection which caused the error will be available via $this->errorConnection.
int | $i | Server index |
int | $flags | Class CONN_* constant bitfield |
Definition at line 928 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getServerName(), Wikimedia\Rdbms\LoadBalancer\KEY_LOCAL, Wikimedia\Rdbms\LoadBalancer\KEY_LOCAL_NOROUND, Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection(), and servers.
Referenced by Wikimedia\Rdbms\LoadBalancer\openConnection().
Wikimedia\Rdbms\LoadBalancer::pendingMasterChangeCallers | ( | ) |
Get the list of callers that have pending master changes.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1663 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), and Wikimedia\Rdbms\IDatabase\pendingWriteCallers().
|
private |
array | $loads | List of server weights |
string | bool | $domain |
Definition at line 426 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$laggedReplicaMode, Wikimedia\Rdbms\LoadBalancer\$loads, Wikimedia\Rdbms\LoadBalancer\allowLagged(), false, Wikimedia\Rdbms\LoadBalancer\getRandomNonLagged(), Wikimedia\Rdbms\LoadBalancer\getServerName(), Wikimedia\Rdbms\LoadBalancer\openConnection(), ArrayUtils\pickRandom(), and Wikimedia\Rdbms\LoadBalancer\reuseConnection().
Referenced by Wikimedia\Rdbms\LoadBalancer\getReaderIndex().
Wikimedia\Rdbms\LoadBalancer::pingAll | ( | ) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1759 of file LoadBalancer.php.
References $success, Wikimedia\Rdbms\LoadBalancer\forEachOpenConnection(), and Wikimedia\Rdbms\IDatabase\ping().
|
protected |
Open a new network connection to a server (uncached)
Returns a Database object whether or not the connection was successful.
array | $server | |
DatabaseDomain | $domain | Domain the connection is for, possibly unspecified |
DBAccessError | |
InvalidArgumentException |
Reimplemented in Wikimedia\Rdbms\LoadBalancerSingle.
Definition at line 1099 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$agent, Wikimedia\Rdbms\LoadBalancer\$cliMode, Wikimedia\Rdbms\LoadBalancer\$connLogger, Wikimedia\Rdbms\LoadBalancer\$deprecationLogger, $e, Wikimedia\Rdbms\LoadBalancer\$errorLogger, Wikimedia\Rdbms\LoadBalancer\$profiler, Wikimedia\Rdbms\LoadBalancer\$queryLogger, Wikimedia\Rdbms\LoadBalancer\$srvCache, Wikimedia\Rdbms\LoadBalancer\$trxProfiler, Wikimedia\Rdbms\LoadBalancer\applyTransactionRoundFlags(), Wikimedia\Rdbms\Database\factory(), Wikimedia\Rdbms\DatabaseDomain\getDatabase(), Wikimedia\Rdbms\LoadBalancer\getLazyConnectionRef(), Wikimedia\Rdbms\DatabaseDomain\getSchema(), Wikimedia\Rdbms\LoadBalancer\getServerName(), Wikimedia\Rdbms\DatabaseDomain\getTablePrefix(), and Wikimedia\Rdbms\LoadBalancer\getWriterIndex().
Referenced by Wikimedia\Rdbms\LoadBalancer\openForeignConnection(), and Wikimedia\Rdbms\LoadBalancer\openLocalConnection().
Wikimedia\Rdbms\LoadBalancer::redefineLocalDomain | ( | $domain | ) |
Close all connection and redefine the local domain for testing or schema creation.
DatabaseDomain | string | $domain |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1958 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\closeAll(), Wikimedia\Rdbms\DatabaseDomain\newFromId(), and Wikimedia\Rdbms\LoadBalancer\setLocalDomain().
|
private |
DBConnectionError |
Definition at line 1181 of file LoadBalancer.php.
References $context, Wikimedia\Rdbms\LoadBalancer\$errorConnection, and Wikimedia\Rdbms\LoadBalancer\$lastError.
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnection().
Wikimedia\Rdbms\LoadBalancer::resolveDomainID | ( | $domain | ) |
DatabaseDomain | string | bool | $domain | Database domain |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 277 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getLocalDomainID(), and string.
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnectionRef(), Wikimedia\Rdbms\LoadBalancer\getLazyConnectionRef(), and Wikimedia\Rdbms\LoadBalancer\getMaintenanceConnectionRef().
Wikimedia\Rdbms\LoadBalancer::reuseConnection | ( | IDatabase | $conn | ) |
Mark a foreign connection as being available for reuse under a different DB domain.
This mechanism is reference-counted, and must be called the same number of times as getConnection() to work.
IDatabase | $conn |
InvalidArgumentException |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 788 of file LoadBalancer.php.
References Wikimedia\Rdbms\IDatabase\getDomainID(), Wikimedia\Rdbms\IDatabase\getLBInfo(), Wikimedia\Rdbms\LoadBalancer\KEY_FOREIGN_FREE, Wikimedia\Rdbms\LoadBalancer\KEY_FOREIGN_FREE_NOROUND, Wikimedia\Rdbms\LoadBalancer\KEY_FOREIGN_INUSE, Wikimedia\Rdbms\LoadBalancer\KEY_FOREIGN_INUSE_NOROUND, and Wikimedia\Rdbms\IDatabase\setLBInfo().
Referenced by Wikimedia\Rdbms\LoadBalancer\getLaggedReplicaMode(), Wikimedia\Rdbms\LoadBalancer\masterRunningReadOnly(), and Wikimedia\Rdbms\LoadBalancer\pickReaderIndex().
Wikimedia\Rdbms\LoadBalancer::rollbackMasterChanges | ( | $fname = __METHOD__ | ) |
Issue ROLLBACK only on master, only if queries were done on connection.
string | $fname | Caller name |
DBExpectedError |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1536 of file LoadBalancer.php.
References $fname, false, Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), Wikimedia\Rdbms\IDatabase\rollback(), and Wikimedia\Rdbms\LoadBalancer\undoTransactionRoundFlags().
Wikimedia\Rdbms\LoadBalancer::runMasterTransactionIdleCallbacks | ( | ) |
Consume and run all pending post-COMMIT/ROLLBACK callbacks and commit dangling transactions.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1440 of file LoadBalancer.php.
References $e, $fname, Wikimedia\Rdbms\LoadBalancer\$trxRoundStage, $type, Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), Wikimedia\Rdbms\Database\setTrxEndCallbackSuppression(), Wikimedia\Rdbms\Database\trxLevel(), and Wikimedia\Rdbms\Database\writesPending().
Wikimedia\Rdbms\LoadBalancer::runMasterTransactionListenerCallbacks | ( | ) |
Run all recurring post-COMMIT/ROLLBACK listener callbacks.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1509 of file LoadBalancer.php.
References $e, $type, Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), and Wikimedia\Rdbms\Database\runTransactionListenerCallbacks().
Wikimedia\Rdbms\LoadBalancer::safeGetLag | ( | IDatabase | $conn | ) |
Get the lag in seconds for a given connection, or zero if this load balancer does not have replication enabled.
This should be used in preference to Database::getLag() in cases where replication may not be in use, since there is no way to determine if replication is in use at the connection level without running potentially restricted queries such as SHOW SLAVE STATUS. Using this function instead of Database::getLag() avoids a fatal error in this case on many installations.
IDatabase | $conn |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1844 of file LoadBalancer.php.
References Wikimedia\Rdbms\IDatabase\getLag(), and Wikimedia\Rdbms\LoadBalancer\getServerCount().
Wikimedia\Rdbms\LoadBalancer::safeWaitForMasterPos | ( | IDatabase | $conn, |
$pos = false, | |||
$timeout = null ) |
IDatabase | $conn | |
DBMasterPos | bool | $pos | |
int | null | $timeout |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1858 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$waitTimeout, Wikimedia\Rdbms\LoadBalancer\closeConnection(), Wikimedia\Rdbms\LoadBalancer\getAnyOpenConnection(), Wikimedia\Rdbms\IDatabase\getLBInfo(), Wikimedia\Rdbms\IDatabase\getServer(), Wikimedia\Rdbms\LoadBalancer\getServerCount(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), Wikimedia\Rdbms\IDatabase\masterPosWait(), and Wikimedia\Rdbms\LoadBalancer\openConnection().
Wikimedia\Rdbms\LoadBalancer::setDomainPrefix | ( | $prefix | ) |
Set a new table prefix for the existing local domain ID for testing.
string | $prefix |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1926 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\forEachOpenConnection(), Wikimedia\Rdbms\IDatabase\getLBInfo(), and Wikimedia\Rdbms\LoadBalancer\setLocalDomain().
Wikimedia\Rdbms\LoadBalancer::setIndexAliases | ( | array | $aliases | ) |
Convert certain index names to alternative names before querying the DB.
Note that this applies to indexes regardless of the table they belong to.
This can be employed when an index was renamed X => Y in code, but the new Y-named indexes were not yet built on all DBs. After all the Y-named ones are added by the DBA, the aliases can be removed, and then the old X-named indexes dropped.
string[] | $aliases |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1922 of file LoadBalancer.php.
|
private |
DatabaseDomain | $domain |
Definition at line 1967 of file LoadBalancer.php.
References Wikimedia\Rdbms\DatabaseDomain\getDatabase().
Referenced by Wikimedia\Rdbms\LoadBalancer\__construct(), Wikimedia\Rdbms\LoadBalancer\redefineLocalDomain(), and Wikimedia\Rdbms\LoadBalancer\setDomainPrefix().
Wikimedia\Rdbms\LoadBalancer::setTableAliases | ( | array | $aliases | ) |
Make certain table names use their own database, schema, and table prefix when passed into SQL queries pre-escaped and without a qualified database name.
For example, "user" can be converted to "myschema.mydbname.user" for convenience. Appearances like user
, somedb.user, somedb.someschema.user will used literally.
Calling this twice will completely clear any old table aliases. Also, note that callers are responsible for making sure the schemas and databases actually exist.
array[] | $aliases | Map of (table => (dbname, schema, prefix) map) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1918 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::setTransactionListener | ( | $name, | |
callable | $callback = null ) |
Set a callback via IDatabase::setTransactionListener() on all current and future master connections of this load balancer.
string | $name | Callback name |
callable | null | $callback |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1905 of file LoadBalancer.php.
References $name, Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), and Wikimedia\Rdbms\IDatabase\setTransactionListener().
|
private |
DBMasterPos | bool | $pos |
Definition at line 576 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\waitFor().
|
private |
Database | $conn |
Definition at line 1600 of file LoadBalancer.php.
References Wikimedia\Rdbms\Database\getFlag(), Wikimedia\Rdbms\Database\getLBInfo(), Wikimedia\Rdbms\Database\restoreFlags(), and Wikimedia\Rdbms\Database\setLBInfo().
Referenced by Wikimedia\Rdbms\LoadBalancer\commitMasterChanges(), and Wikimedia\Rdbms\LoadBalancer\rollbackMasterChanges().
Wikimedia\Rdbms\LoadBalancer::waitFor | ( | $pos | ) |
Set the master wait position.
If a DB_REPLICA connection has been opened already, then wait immediately. Otherwise sets a variable telling it to wait if such a connection is opened.
This only applies to connections to the generic replica DB for this request. If a timeout happens when waiting, then getLaggedReplicaMode()/laggedReplicaUsed() will return true.
DBMasterPos | bool | $pos | Master position or false |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 502 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$readIndex, Wikimedia\Rdbms\LoadBalancer\$waitForPos, Wikimedia\Rdbms\LoadBalancer\doWait(), and Wikimedia\Rdbms\LoadBalancer\setWaitForPositionIfHigher().
Wikimedia\Rdbms\LoadBalancer::waitForAll | ( | $pos, | |
$timeout = null ) |
Set the master wait position and wait for ALL replica DBs to catch up to it.
DBMasterPos | bool | $pos | Master position or false |
int | null | $timeout | Max seconds to wait; default is mWaitTimeout |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 546 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$waitForPos, Wikimedia\Rdbms\LoadBalancer\$waitTimeout, Wikimedia\Rdbms\LoadBalancer\doWait(), and servers.
Wikimedia\Rdbms\LoadBalancer::waitForOne | ( | $pos, | |
$timeout = null ) |
Set the master wait position and wait for a "generic" replica DB to catch up to it.
This can be used a faster proxy for waitForAll()
DBMasterPos | bool | $pos | Master position or false |
int | null | $timeout | Max seconds to wait; default is mWaitTimeout |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 519 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$loads, Wikimedia\Rdbms\LoadBalancer\$readIndex, Wikimedia\Rdbms\LoadBalancer\$waitForPos, Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), and ArrayUtils\pickRandom().
|
private |
Agent name for query profiling.
Definition at line 95 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
Whether to disregard replica DB lag as a factor in replica DB selection.
Definition at line 80 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\allowLagged().
|
private |
Whether the generic reader fell back to a lagged replica DB.
Definition at line 113 of file LoadBalancer.php.
|
private |
Callback to run before the first connection attempt.
Definition at line 45 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\openConnection().
|
private |
Whether this PHP instance is for a CLI script.
Definition at line 93 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
Whether any connection has been attempted yet.
Definition at line 123 of file LoadBalancer.php.
|
private |
Definition at line 57 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
Map of (connection category => server index => IDatabase[])
Definition at line 71 of file LoadBalancer.php.
|
private |
Total connections opened.
Definition at line 119 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\closeConnection(), and Wikimedia\Rdbms\LoadBalancer\getConnection().
|
private |
Definition at line 131 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnection().
|
private |
Deprecation logger.
Definition at line 65 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
Definition at line 121 of file LoadBalancer.php.
|
private |
DB connection object that caused a problem.
Definition at line 105 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reportConnectionError().
|
private |
Exception logger.
Definition at line 63 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\commitMasterChanges(), and Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
Map of (group => server index => weight)
Definition at line 78 of file LoadBalancer.php.
|
private |
Current server name.
Definition at line 91 of file LoadBalancer.php.
|
private |
Map of (index alias => index)
Definition at line 100 of file LoadBalancer.php.
|
private |
Whether the generic reader fell back to a lagged replica DB.
Definition at line 111 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getLaggedReplicaMode(), Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), Wikimedia\Rdbms\LoadBalancer\laggedReplicaUsed(), and Wikimedia\Rdbms\LoadBalancer\pickReaderIndex().
|
private |
The last DB selection or connection error.
Definition at line 115 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnection(), and Wikimedia\Rdbms\LoadBalancer\reportConnectionError().
|
private |
Definition at line 43 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getLoadMonitor().
|
private |
The LoadMonitor configuration.
Definition at line 84 of file LoadBalancer.php.
|
private |
Map of (server index => weight)
Definition at line 76 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getRandomNonLagged(), Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), Wikimedia\Rdbms\LoadBalancer\pickReaderIndex(), and Wikimedia\Rdbms\LoadBalancer\waitForOne().
|
private |
Local Domain ID and default for selectDB() calls.
Definition at line 68 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\__construct().
|
private |
Alternate ID string for the domain instead of DatabaseDomain::getId()
Definition at line 86 of file LoadBalancer.php.
|
private |
Definition at line 88 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\__construct(), Wikimedia\Rdbms\LoadBalancer\getMaxLag(), and Wikimedia\Rdbms\LoadBalancer\getRandomNonLagged().
|
private |
Definition at line 61 of file LoadBalancer.php.
|
private |
Class name or object With profileIn/profileOut methods.
Definition at line 51 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
Definition at line 59 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
The generic (not query grouped) replica DB index (of $mServers)
Definition at line 107 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), Wikimedia\Rdbms\LoadBalancer\waitFor(), and Wikimedia\Rdbms\LoadBalancer\waitForOne().
|
private |
Reason the LB is read-only or false if not.
Definition at line 117 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getReadOnlyReason().
|
private |
Definition at line 55 of file LoadBalancer.php.
|
private |
Map of (server index => server config array)
Definition at line 74 of file LoadBalancer.php.
|
private |
Definition at line 47 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
Definition at line 98 of file LoadBalancer.php.
|
private |
Definition at line 53 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
Map of (name => callable)
Definition at line 102 of file LoadBalancer.php.
|
private |
String if a requested DBO_TRX transaction round is active.
Definition at line 126 of file LoadBalancer.php.
|
private |
Stage of the current transaction round in the transaction round life-cycle.
Definition at line 128 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getTransactionRoundStage(), and Wikimedia\Rdbms\LoadBalancer\runMasterTransactionIdleCallbacks().
|
private |
False if not set.
Definition at line 109 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\waitFor(), Wikimedia\Rdbms\LoadBalancer\waitForAll(), and Wikimedia\Rdbms\LoadBalancer\waitForOne().
|
private |
Seconds to spend waiting on replica DB lag to resolve.
Definition at line 82 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\safeWaitForMasterPos(), and Wikimedia\Rdbms\LoadBalancer\waitForAll().
|
private |
Definition at line 49 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\masterRunningReadOnly().
const Wikimedia\Rdbms\LoadBalancer::KEY_FOREIGN_FREE = 'foreignFree' |
Definition at line 144 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\openForeignConnection(), and Wikimedia\Rdbms\LoadBalancer\reuseConnection().
const Wikimedia\Rdbms\LoadBalancer::KEY_FOREIGN_FREE_NOROUND = 'foreignFreeAutoCommit' |
Definition at line 148 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\openForeignConnection(), and Wikimedia\Rdbms\LoadBalancer\reuseConnection().
const Wikimedia\Rdbms\LoadBalancer::KEY_FOREIGN_INUSE = 'foreignInUse' |
Definition at line 145 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\openForeignConnection(), and Wikimedia\Rdbms\LoadBalancer\reuseConnection().
const Wikimedia\Rdbms\LoadBalancer::KEY_FOREIGN_INUSE_NOROUND = 'foreignInUseAutoCommit' |
Definition at line 149 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\openForeignConnection(), and Wikimedia\Rdbms\LoadBalancer\reuseConnection().
const Wikimedia\Rdbms\LoadBalancer::KEY_LOCAL = 'local' |
Definition at line 143 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\openLocalConnection().
const Wikimedia\Rdbms\LoadBalancer::KEY_LOCAL_NOROUND = 'localAutoCommit' |
Definition at line 147 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\openLocalConnection().