MediaWiki
1.34.0
|
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. More... | |
__destruct () | |
allowLagged ( $mode=null) | |
Disables/enables lag checks. More... | |
approveMasterChanges (array $options, $fname=__METHOD__, $owner=null) | |
Perform all pre-commit checks for things like replication safety. More... | |
beginMasterChanges ( $fname=__METHOD__, $owner=null) | |
Flush any master transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set) More... | |
closeAll ( $fname=__METHOD__, $owner=null) | |
Close all open connections. More... | |
closeConnection (IDatabase $conn) | |
Close a connection. More... | |
commitAll ( $fname=__METHOD__, $owner=null) | |
Commit transactions on all open connections. More... | |
commitMasterChanges ( $fname=__METHOD__, $owner=null) | |
Issue COMMIT on all open master connections to flush changes and view snapshots. More... | |
disable ( $fname=__METHOD__, $owner=null) | |
Close all connections and disable this load balancer. More... | |
finalizeMasterChanges ( $fname=__METHOD__, $owner=null) | |
Run pre-commit callbacks and defer execution of post-commit callbacks. More... | |
flushMasterSnapshots ( $fname=__METHOD__, $owner=null) | |
Commit all master DB transactions so as to flush any REPEATABLE-READ or SSI snapshots. More... | |
flushReplicaSnapshots ( $fname=__METHOD__, $owner=null) | |
Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshots. More... | |
forEachOpenConnection ( $callback, array $params=[]) | |
Call a function with each open connection object. More... | |
forEachOpenMasterConnection ( $callback, array $params=[]) | |
Call a function with each open connection object to a master. More... | |
forEachOpenReplicaConnection ( $callback, array $params=[]) | |
Call a function with each open replica DB connection object. More... | |
getAnyOpenConnection ( $i, $flags=0) | |
Get any open connection to a given server index, local or foreign. More... | |
getConnection ( $i, $groups=[], $domain=false, $flags=0) | |
Get a live handle for a real or virtual (DB_MASTER/DB_REPLICA) server index. More... | |
getConnectionRef ( $i, $groups=[], $domain=false, $flags=0) | |
Get a live database handle reference for a real or virtual (DB_MASTER/DB_REPLICA) server index. More... | |
getLaggedReplicaMode ( $domain=false) | |
getLagTimes ( $domain=false) | |
Get an estimate of replication lag (in seconds) for each server. More... | |
getLazyConnectionRef ( $i, $groups=[], $domain=false, $flags=0) | |
Get a database handle reference for a real or virtual (DB_MASTER/DB_REPLICA) server index. More... | |
getLocalDomainID () | |
Get the local (and default) database domain ID of connection handles. More... | |
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 for data migrations and schema changes. More... | |
getMasterPos () | |
Get the current master replication position. More... | |
getMaxLag ( $domain=false) | |
Get the hostname and lag time of the most-lagged replica server. More... | |
getReaderIndex ( $group=false, $domain=false) | |
Get the server index of the reader connection for a given group. More... | |
getReadOnlyReason ( $domain=false) | |
getReplicaResumePos () | |
Get the highest DB replication position for chronology control purposes. More... | |
getServerAttributes ( $i) | |
getServerConnection ( $i, $domain, $flags=0) | |
getServerCount () | |
Get the number of servers defined in configuration. More... | |
getServerInfo ( $i) | |
Return the server info structure for a given index or false if the index is invalid. More... | |
getServerName ( $i) | |
Get the host name or IP address of the server with the specified index. More... | |
getServerType ( $i) | |
Get DB type of the server with the specified index. More... | |
getTransactionRoundStage () | |
getWriterIndex () | |
Get the server index of the master server. More... | |
hasMasterChanges () | |
Whether there are pending changes or callbacks in a transaction by this thread. More... | |
hasMasterConnection () | |
hasOrMadeRecentMasterChanges ( $age=null) | |
Check if this load balancer object had any recent or still pending writes issued against it by this PHP thread. More... | |
hasReplicaServers () | |
Whether there are any replica servers configured. More... | |
hasStreamingReplicaServers () | |
Whether any replica servers use streaming replication from the master server. More... | |
haveIndex ( $i) | |
Returns true if the specified index is a valid server index. More... | |
isNonZeroLoad ( $i) | |
Returns true if the specified index is valid and has non-zero load. More... | |
laggedReplicaUsed () | |
Checks whether the database for generic connections this request was both: More... | |
lastMasterChangeTimestamp () | |
Get the timestamp of the latest write query done by this thread. More... | |
openConnection ( $i, $domain=false, $flags=0) | |
pendingMasterChangeCallers () | |
Get the list of callers that have pending master changes. More... | |
pingAll () | |
redefineLocalDomain ( $domain) | |
Close all connection and redefine the local domain for testing or schema creation. More... | |
resolveDomainID ( $domain) | |
reuseConnection (IDatabase $conn) | |
Mark a live handle as being available for reuse under a different database domain. More... | |
rollbackMasterChanges ( $fname=__METHOD__, $owner=null) | |
Issue ROLLBACK only on master, only if queries were done on connection. More... | |
runMasterTransactionIdleCallbacks ( $fname=__METHOD__, $owner=null) | |
Consume and run all pending post-COMMIT/ROLLBACK callbacks and commit dangling transactions. More... | |
runMasterTransactionListenerCallbacks ( $fname=__METHOD__, $owner=null) | |
Run all recurring post-COMMIT/ROLLBACK listener callbacks. More... | |
safeGetLag (IDatabase $conn) | |
Get the lag in seconds for a given connection, or zero if this load balancer does not have replication enabled. More... | |
safeWaitForMasterPos (IDatabase $conn, $pos=false, $timeout=null) | |
Wait for a replica DB to reach a specified master position. More... | |
setIndexAliases (array $aliases) | |
Convert certain index names to alternative names before querying the DB. More... | |
setLocalDomainPrefix ( $prefix) | |
Set a new table prefix for the existing local domain ID for testing. More... | |
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. More... | |
setTempTablesOnlyMode ( $value, $domain) | |
Indicate whether the tables on this domain are only temporary tables for testing. More... | |
setTransactionListener ( $name, callable $callback=null) | |
Set a callback via IDatabase::setTransactionListener() on all current and future master connections of this load balancer. More... | |
waitFor ( $pos) | |
Set the master position to reach before the next generic group DB handle query. More... | |
waitForAll ( $pos, $timeout=null) | |
Set the master wait position and wait for ALL replica DBs to catch up to it. More... | |
waitForMasterPos (IDatabase $conn, $pos=false, $timeout=null) | |
Wait for a replica DB to reach a specified master position. More... | |
waitForOne ( $pos, $timeout=null) | |
Set the master wait position and wait for a generic replica DB to catch up to it. More... | |
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 "waitForPos". More... | |
getExistingReaderIndex ( $group) | |
Get the server index chosen by the load balancer for use with the given query group. More... | |
reallyOpenConnection (array $server, DatabaseDomain $domain) | |
Open a new network connection to a server (uncached) More... | |
Private Member Functions | |
applyTransactionRoundFlags (Database $conn) | |
Make all DB servers with DBO_DEFAULT/DBO_TRX set join the transaction round. More... | |
assertOwnership ( $fname, $owner) | |
Assure that if this instance is owned, the caller is either the owner or is internal. More... | |
assertTransactionRoundStage ( $stage) | |
enforceConnectionFlags (IDatabase $conn, $flags) | |
getConnectionIndex ( $i, array $groups, $domain) | |
Get the server index to use for a specified server index and query group list. More... | |
getCurrentConnectionCount () | |
getForeignConnection ( $i, $domain, $flags=0) | |
Open a connection to a foreign DB, or return one if it is already open. More... | |
getLoadMonitor () | |
Get a LoadMonitor instance. More... | |
getLocalConnection ( $i, $flags=0) | |
Open a connection to a local DB, or return one if it is already open. More... | |
getMasterServerName () | |
getRandomNonLagged (array $loads, $domain=false, $maxLag=INF) | |
getRoleFromIndex ( $i) | |
getServerInfoStrict ( $i, $field=null) | |
isMasterConnectionReadOnly (IDatabase $conn, $flags=0) | |
isMasterRunningReadOnly (DatabaseDomain $domain) | |
isOpen ( $index) | |
Test if the specified index represents an open connection. More... | |
lazyLoadReplicationPositions () | |
Make sure that any "waitForPos" positions are loaded and available to doWait() More... | |
pickAnyOpenConnection ( $candidateConns, $autocommit) | |
pickReaderIndex (array $loads, $domain=false) | |
reportConnectionError () | |
resolveGroups ( $groups, $i) | |
Resolve $groups into a list of query groups defining as having database servers. More... | |
sanitizeConnectionFlags ( $flags, $i, $domain) | |
serverHasLoadInAnyGroup ( $i) | |
setExistingReaderIndex ( $group, $index) | |
Set the server index chosen by the load balancer for use with the given query group. More... | |
setLocalDomain (DatabaseDomain $domain) | |
setWaitForPositionIfHigher ( $pos) | |
undoTransactionRoundFlags (Database $conn) | |
Static Private Member Functions | |
static | newTrackedConnectionsArray () |
Private Attributes | |
string | $agent |
Agent name for query profiling. More... | |
bool | $allowLagged |
Whether to disregard replica DB lag as a factor in replica DB selection. More... | |
callable null | $chronologyCallback |
Callback to run before the first connection attempt. More... | |
bool | $cliMode |
Whether this PHP instance is for a CLI script. More... | |
bool | $connectionAttempted = false |
Whether any connection has been attempted yet. More... | |
int | $connectionCounter = 0 |
Total number of new connections ever made with this instance. More... | |
LoggerInterface | $connLogger |
IDatabase[][][] Database[][][] | $conns |
Map of (connection category => server index => IDatabase[]) More... | |
string null | $defaultGroup |
Default query group to use with getConnection() More... | |
callable | $deprecationLogger |
Deprecation logger. More... | |
bool | $disabled = false |
Database | $errorConnection |
Connection handle that caused a problem. More... | |
callable | $errorLogger |
Exception logger. More... | |
array[] | $groupLoads |
Map of (group => server index => weight) More... | |
string | $hostname |
Current server name. More... | |
$id | |
var int An identifier for this class instance More... | |
string[] | $indexAliases = [] |
Map of (index alias => index) More... | |
bool | $laggedReplicaMode = false |
Whether the generic reader fell back to a lagged replica DB. More... | |
string | $lastError = 'Unknown error' |
The last DB selection or connection error. More... | |
ILoadMonitor | $loadMonitor |
array | $loadMonitorConfig |
The LoadMonitor configuration. More... | |
DatabaseDomain | $localDomain |
Local DB domain ID and default for selectDB() calls. More... | |
string | $localDomainIdAlias |
Alternate local DB domain instead of DatabaseDomain::getId() More... | |
int | $maxLag |
Amount of replication lag, in seconds, that is considered "high". More... | |
int null | $ownerId |
Integer ID of the managing LBFactory instance or null if none. More... | |
LoggerInterface | $perfLogger |
mixed | $profiler |
Class name or object With profileIn/profileOut methods. More... | |
LoggerInterface | $queryLogger |
int[] | $readIndexByGroup = [] |
The group replica server indexes keyed by group. More... | |
string bool | $readOnlyReason = false |
Reason this instance is read-only or false if not. More... | |
LoggerInterface | $replLogger |
array[] | $servers |
Map of (server index => server config array) More... | |
BagOStuff | $srvCache |
array[] | $tableAliases = [] |
$aliases Map of (table => (dbname, schema, prefix) map) More... | |
bool[] | $tempTablesOnlyMode = [] |
Map of (domain => whether to use "temp tables only" mode) More... | |
TransactionProfiler | $trxProfiler |
callable[] | $trxRecurringCallbacks = [] |
Map of (name => callable) More... | |
string bool | $trxRoundId = false |
Explicit DBO_TRX transaction round active or false if none. More... | |
string | $trxRoundStage = self::ROUND_CURSORY |
Stage of the current transaction round in the transaction round life-cycle. More... | |
bool DBMasterPos | $waitForPos |
Replication sync position or false if not set. More... | |
int | $waitTimeout |
Seconds to spend waiting on replica DB lag to resolve. More... | |
WANObjectCache | $wanCache |
Database connection, tracking, load balancing, and transaction manager for a cluster.
Definition at line 42 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 168 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$localDomain, Wikimedia\Rdbms\LoadBalancer\$maxLag, Wikimedia\Rdbms\LoadBalancer\allowLagged(), WANObjectCache\newEmpty(), Wikimedia\Rdbms\DatabaseDomain\newFromId(), Wikimedia\Rdbms\LoadBalancer\newTrackedConnectionsArray(), Wikimedia\Rdbms\DatabaseDomain\newUnspecified(), and Wikimedia\Rdbms\LoadBalancer\setLocalDomain().
Wikimedia\Rdbms\LoadBalancer::__destruct | ( | ) |
Reimplemented in Wikimedia\Rdbms\LoadBalancerSingle.
Definition at line 2392 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 2073 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$allowLagged.
Referenced by Wikimedia\Rdbms\LoadBalancer\__construct(), 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 1873 of file LoadBalancer.php.
References DBO_DEFAULT, DBO_TRX, 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, |
$fname = __METHOD__ , |
|||
$owner = null |
|||
) |
Perform all pre-commit checks for things like replication safety.
Use this only for mutli-database commits
array | $options | Includes:
|
string | $fname | Caller name |
int | null | $owner | ID of the calling instance (e.g. the LBFactory ID) |
DBTransactionError |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1587 of file LoadBalancer.php.
References Wikimedia\Rdbms\IDatabase\assertNoOpenTransactions(), Wikimedia\Rdbms\LoadBalancer\assertOwnership(), Wikimedia\Rdbms\LoadBalancer\assertTransactionRoundStage(), Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), Wikimedia\Rdbms\IDatabase\pendingWriteQueryDuration(), Wikimedia\Rdbms\IDatabase\ping(), and Wikimedia\Rdbms\IDatabase\writesOrCallbacksPending().
|
private |
Assure that if this instance is owned, the caller is either the owner or is internal.
If an LBFactory owns the LoadBalancer, then certain methods should only called through that LBFactory to avoid broken contracts. Otherwise, those methods can publically be called by anything. In any case, internal methods from the LoadBalancer itself should always be allowed.
string | $fname | |
int | null | $owner | Owner ID of the caller |
DBTransactionError |
Definition at line 1855 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\approveMasterChanges(), Wikimedia\Rdbms\LoadBalancer\beginMasterChanges(), Wikimedia\Rdbms\LoadBalancer\closeAll(), Wikimedia\Rdbms\LoadBalancer\commitMasterChanges(), Wikimedia\Rdbms\LoadBalancer\disable(), Wikimedia\Rdbms\LoadBalancer\finalizeMasterChanges(), Wikimedia\Rdbms\LoadBalancer\flushMasterSnapshots(), Wikimedia\Rdbms\LoadBalancer\flushReplicaSnapshots(), Wikimedia\Rdbms\LoadBalancer\rollbackMasterChanges(), Wikimedia\Rdbms\LoadBalancer\runMasterTransactionIdleCallbacks(), and Wikimedia\Rdbms\LoadBalancer\runMasterTransactionListenerCallbacks().
|
private |
string | string[] | $stage |
DBTransactionError |
Definition at line 1826 of file LoadBalancer.php.
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__ , |
|
$owner = null |
|||
) |
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 | Caller name |
int | null | $owner | ID of the calling instance (e.g. the LBFactory ID) |
DBExpectedError |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1625 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\applyTransactionRoundFlags(), Wikimedia\Rdbms\LoadBalancer\assertOwnership(), Wikimedia\Rdbms\LoadBalancer\assertTransactionRoundStage(), Wikimedia\Rdbms\LoadBalancer\flushMasterSnapshots(), and Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection().
Wikimedia\Rdbms\LoadBalancer::closeAll | ( | $fname = __METHOD__ , |
|
$owner = null |
|||
) |
Close all open connections.
string | $fname | Caller name |
int | null | $owner | ID of the calling instance (e.g. the LBFactory ID) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1511 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\assertOwnership(), Wikimedia\Rdbms\IDatabase\close(), Wikimedia\Rdbms\LoadBalancer\forEachOpenConnection(), Wikimedia\Rdbms\IDatabase\getServer(), and Wikimedia\Rdbms\LoadBalancer\newTrackedConnectionsArray().
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 1526 of file LoadBalancer.php.
References $type, Wikimedia\Rdbms\IDatabase\close(), Wikimedia\Rdbms\IDatabase\getLBInfo(), and Wikimedia\Rdbms\LoadBalancer\getServerName().
Referenced by Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getMasterPos(), and Wikimedia\Rdbms\LoadBalancer\waitForMasterPos().
Wikimedia\Rdbms\LoadBalancer::commitAll | ( | $fname = __METHOD__ , |
|
$owner = null |
|||
) |
Commit transactions on all open connections.
string | $fname | Caller name |
int | null | $owner | ID of the calling instance (e.g. the LBFactory ID) |
DBExpectedError |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1552 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\commitMasterChanges(), Wikimedia\Rdbms\LoadBalancer\flushMasterSnapshots(), and Wikimedia\Rdbms\LoadBalancer\flushReplicaSnapshots().
Wikimedia\Rdbms\LoadBalancer::commitMasterChanges | ( | $fname = __METHOD__ , |
|
$owner = null |
|||
) |
Issue COMMIT on all open master connections to flush changes and view snapshots.
string | $fname | Caller name |
int | null | $owner | ID of the calling instance (e.g. the LBFactory ID) |
DBExpectedError |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1654 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$errorLogger, Wikimedia\Rdbms\LoadBalancer\assertOwnership(), Wikimedia\Rdbms\LoadBalancer\assertTransactionRoundStage(), Wikimedia\Rdbms\IDatabase\commit(), Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), and Wikimedia\Rdbms\LoadBalancer\undoTransactionRoundFlags().
Referenced by Wikimedia\Rdbms\LoadBalancer\commitAll().
Wikimedia\Rdbms\LoadBalancer::disable | ( | $fname = __METHOD__ , |
|
$owner = null |
|||
) |
Close all connections and disable this load balancer.
Any attempt to open a new connection will result in a DBAccessError.
string | $fname | Caller name |
int | null | $owner | ID of the calling instance (e.g. the LBFactory ID) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1505 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\assertOwnership(), and 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 "waitForPos".
int | $index | Specific 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" |
Definition at line 798 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\closeConnection(), Wikimedia\Rdbms\LoadBalancer\getAnyOpenConnection(), Wikimedia\Rdbms\LoadBalancer\getServerConnection(), Wikimedia\Rdbms\LoadBalancer\getServerName(), Wikimedia\Rdbms\DBMasterPos\hasReached(), and IExpiringStore\TTL_DAY.
Referenced by Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), Wikimedia\Rdbms\LoadBalancer\waitFor(), Wikimedia\Rdbms\LoadBalancer\waitForAll(), and Wikimedia\Rdbms\LoadBalancer\waitForOne().
|
private |
IDatabase | $conn | |
int | $flags |
DBUnexpectedError |
Definition at line 348 of file LoadBalancer.php.
References Wikimedia\Rdbms\IDatabase\clearFlag(), DBO_TRX, and Wikimedia\Rdbms\IDatabase\trxLevel().
Referenced by Wikimedia\Rdbms\LoadBalancer\getAnyOpenConnection(), and Wikimedia\Rdbms\LoadBalancer\getServerConnection().
Wikimedia\Rdbms\LoadBalancer::finalizeMasterChanges | ( | $fname = __METHOD__ , |
|
$owner = null |
|||
) |
Run pre-commit callbacks and defer execution of post-commit callbacks.
Use this only for mutli-database commits
string | $fname | Caller name |
int | null | $owner | ID of the calling instance (e.g. the LBFactory ID) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1558 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\assertOwnership(), Wikimedia\Rdbms\LoadBalancer\assertTransactionRoundStage(), Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), Wikimedia\Rdbms\Database\runOnTransactionPreCommitCallbacks(), and Wikimedia\Rdbms\Database\setTrxEndCallbackSuppression().
Wikimedia\Rdbms\LoadBalancer::flushMasterSnapshots | ( | $fname = __METHOD__ , |
|
$owner = null |
|||
) |
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 |
int | null | $owner | ID of the calling instance (e.g. the LBFactory ID) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1913 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\assertOwnership(), 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__ , |
|
$owner = null |
|||
) |
Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
string | $fname | Caller name |
int | null | $owner | ID of the calling instance (e.g. the LBFactory ID) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1906 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\assertOwnership(), 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 2093 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\closeAll(), Wikimedia\Rdbms\LoadBalancer\pingAll(), and Wikimedia\Rdbms\LoadBalancer\setLocalDomainPrefix().
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 2103 of file LoadBalancer.php.
References 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 2115 of file LoadBalancer.php.
References 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 transaction methods like IDatabase::begin() or IDatabase::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 732 of file LoadBalancer.php.
References DB_MASTER, DB_REPLICA, Wikimedia\Rdbms\LoadBalancer\enforceConnectionFlags(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), and Wikimedia\Rdbms\LoadBalancer\pickAnyOpenConnection().
Referenced by Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getMasterPos(), Wikimedia\Rdbms\LoadBalancer\getReplicaResumePos(), Wikimedia\Rdbms\LoadBalancer\isOpen(), and Wikimedia\Rdbms\LoadBalancer\waitForMasterPos().
Wikimedia\Rdbms\LoadBalancer::getConnection | ( | $i, | |
$groups = [] , |
|||
$domain = false , |
|||
$flags = 0 |
|||
) |
Get a live handle for a real or virtual (DB_MASTER/DB_REPLICA) server index.
The server index, $i, can be one of the following:
Handles acquired by this method, getConnectionRef(), getLazyConnectionRef(), and getMaintenanceConnectionRef() use the same set of shared connection pools. Callers that get a local DB domain handle for the same server will share one handle for all of those callers using CONN_TRX_AUTOCOMMIT (via $flags) and one handle for all of those callers not using CONN_TRX_AUTOCOMMIT. Callers that get a foreign DB domain handle (via $domain) will share any handle that has the right CONN_TRX_AUTOCOMMIT mode and is already on the right DB domain. Otherwise, one of the "free for reuse" handles will be claimed or a new handle will be made if there are none.
Handle sharing is particularly useful when callers get local DB domain (the default), transaction round aware (the default), DB_MASTER handles. All such callers will operate within a single database transaction as a consequence. Handle sharing is also useful when callers get local DB domain (the default), transaction round aware (the default), samely query grouped (the default), DB_REPLICA handles. All such callers will operate within a single database transaction as a consequence.
Calling functions that use $domain must call reuseConnection() once the last query of the function is executed. This lets the load balancer share this handle with other callers requesting connections on different database domains.
Use CONN_TRX_AUTOCOMMIT to use a separate pool of only auto-commit handles. This flag is ignored for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in order to avoid deadlocks. getServerAttributes() can be used to check such attributes beforehand. Avoid using IDatabase::begin() and IDatabase::commit() on such handles. If it is not possible to avoid using methods like IDatabase::startAtomic() and IDatabase::endAtomic(), callers should at least make sure that the atomic sections are closed on failure via try/catch and IDatabase::cancelAtomic().
int | $i | Server index (overrides $groups) or DB_MASTER/DB_REPLICA |
string[] | string | $groups | Query group(s) in preference order; [] for the default group |
string | bool | $domain | DB domain ID or false for the local domain |
int | $flags | Bitfield of CONN_* class constants |
DBError | If no live handle can be obtained and CONN_SILENCE_ERRORS is not set |
DBAccessError | If disable() was previously called |
InvalidArgumentException |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 888 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getConnectionIndex(), Wikimedia\Rdbms\LoadBalancer\getExistingReaderIndex(), Wikimedia\Rdbms\LoadBalancer\getLaggedReplicaMode(), Wikimedia\Rdbms\LoadBalancer\getServerConnection(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), Wikimedia\Rdbms\LoadBalancer\resolveDomainID(), Wikimedia\Rdbms\LoadBalancer\resolveGroups(), and Wikimedia\Rdbms\LoadBalancer\sanitizeConnectionFlags().
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnectionRef(), Wikimedia\Rdbms\LoadBalancer\getMaintenanceConnectionRef(), Wikimedia\Rdbms\LoadBalancer\getMasterPos(), and Wikimedia\Rdbms\LoadBalancer\openConnection().
|
private |
Get the server index to use for a specified server index and query group list.
int | $i | Specific server index or DB_MASTER/DB_REPLICA |
string[] | $groups | Non-empty query group list in preference order |
string | bool | $domain |
Definition at line 450 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$lastError, DB_MASTER, DB_REPLICA, Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), and Wikimedia\Rdbms\LoadBalancer\reportConnectionError().
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnection().
Wikimedia\Rdbms\LoadBalancer::getConnectionRef | ( | $i, | |
$groups = [] , |
|||
$domain = false , |
|||
$flags = 0 |
|||
) |
Get a live database handle reference for a real or virtual (DB_MASTER/DB_REPLICA) server index.
The CONN_TRX_AUTOCOMMIT flag is ignored for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in order to avoid deadlocks. 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 |
string[] | string | $groups | Query group(s) in preference order; [] for the default group |
string | bool | $domain | DB domain ID or false for the local domain |
int | $flags | Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1024 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getConnection(), Wikimedia\Rdbms\LoadBalancer\getRoleFromIndex(), and Wikimedia\Rdbms\LoadBalancer\resolveDomainID().
|
private |
Definition at line 2131 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
protected |
Get the server index chosen by the load balancer for use with the given query group.
string | $group | Query group; use false for the generic group |
Definition at line 535 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnection(), Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), Wikimedia\Rdbms\LoadBalancer\getReadOnlyReason(), Wikimedia\Rdbms\LoadBalancer\waitFor(), and Wikimedia\Rdbms\LoadBalancer\waitForOne().
|
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 |
InvalidArgumentException | When the server index is invalid |
UnexpectedValueException | When the DB domain of the connection is corrupted |
Definition at line 1145 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getServerInfoStrict(), 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(), and Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
Referenced by Wikimedia\Rdbms\LoadBalancer\getServerConnection().
Wikimedia\Rdbms\LoadBalancer::getLaggedReplicaMode | ( | $domain = false | ) |
string | bool | $domain | DB domain ID or false for the local domain |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1966 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$laggedReplicaMode, Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), and Wikimedia\Rdbms\LoadBalancer\hasStreamingReplicaServers().
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnection(), and 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 2161 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getLoadMonitor(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), and Wikimedia\Rdbms\LoadBalancer\hasReplicaServers().
Referenced by Wikimedia\Rdbms\LoadBalancer\getMaxLag(), and Wikimedia\Rdbms\LoadBalancer\getRandomNonLagged().
Wikimedia\Rdbms\LoadBalancer::getLazyConnectionRef | ( | $i, | |
$groups = [] , |
|||
$domain = false , |
|||
$flags = 0 |
|||
) |
Get a database handle reference for a real or virtual (DB_MASTER/DB_REPLICA) server index.
The handle's methods simply proxy to those of an underlying IDatabase handle which takes care of the actual connection and query logic.
The CONN_TRX_AUTOCOMMIT flag is ignored for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in order to avoid deadlocks. 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 |
string[] | string | $groups | Query group(s) in preference order; [] for the default group |
string | bool | $domain | DB domain ID or false for the local domain |
int | $flags | Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1031 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getRoleFromIndex(), and Wikimedia\Rdbms\LoadBalancer\resolveDomainID().
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
Get a LoadMonitor instance.
Definition at line 366 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$loadMonitor.
Referenced by Wikimedia\Rdbms\LoadBalancer\getLagTimes(), and Wikimedia\Rdbms\LoadBalancer\getReaderIndex().
|
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 |
InvalidArgumentException | When the server index is invalid |
UnexpectedValueException | When the DB domain of the connection is corrupted |
Definition at line 1081 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getServerInfoStrict(), Wikimedia\Rdbms\LoadBalancer\getServerName(), Wikimedia\Rdbms\LoadBalancer\KEY_LOCAL, Wikimedia\Rdbms\LoadBalancer\KEY_LOCAL_NOROUND, and Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
Referenced by Wikimedia\Rdbms\LoadBalancer\getServerConnection().
Wikimedia\Rdbms\LoadBalancer::getLocalDomainID | ( | ) |
Get the local (and default) database domain ID of connection handles.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 264 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\resolveDomainID().
Wikimedia\Rdbms\LoadBalancer::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 for data migrations and schema changes.
The handle's methods simply proxy to those of an underlying IDatabase handle which takes care of the actual connection and query logic.
The CONN_TRX_AUTOCOMMIT flag is ignored for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in order to avoid deadlocks. 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 |
string[] | string | $groups | Query group(s) in preference order; [] for the default group |
string | bool | $domain | DB domain ID or false for the local domain |
int | $flags | Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1038 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getConnection(), Wikimedia\Rdbms\LoadBalancer\getRoleFromIndex(), and Wikimedia\Rdbms\LoadBalancer\resolveDomainID().
Wikimedia\Rdbms\LoadBalancer::getMasterPos | ( | ) |
Get the current master replication position.
DBError |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1452 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\closeConnection(), Wikimedia\Rdbms\LoadBalancer\getAnyOpenConnection(), Wikimedia\Rdbms\LoadBalancer\getConnection(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), and Wikimedia\Rdbms\LoadBalancer\reportConnectionError().
|
private |
Definition at line 2388 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getServerName(), and Wikimedia\Rdbms\LoadBalancer\getWriterIndex().
Wikimedia\Rdbms\LoadBalancer::getMaxLag | ( | $domain = false | ) |
Get the hostname and lag time of the most-lagged replica server.
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 2142 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$maxLag, Wikimedia\Rdbms\LoadBalancer\getLagTimes(), Wikimedia\Rdbms\LoadBalancer\getServerInfoStrict(), and Wikimedia\Rdbms\LoadBalancer\hasReplicaServers().
|
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 393 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$maxLag, Wikimedia\Rdbms\LoadBalancer\getLagTimes(), Wikimedia\Rdbms\LoadBalancer\getServerName(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), and ArrayUtils\pickRandom().
Referenced by Wikimedia\Rdbms\LoadBalancer\pickReaderIndex().
Wikimedia\Rdbms\LoadBalancer::getReaderIndex | ( | $group = false , |
|
$domain = false |
|||
) |
Get the server index of the reader connection for a given group.
This takes into account load ratios and lag times. It should return a consistent index during the life time of the load balancer. This initially checks replica DBs for connectivity to avoid returning an unusable server. This means that connections might be attempted by calling this method (usally one at the most but possibly more). Subsequent calls with the same $group will not need to make new connection attempts since the acquired connection for each group is preserved.
string | bool | $group | Query group or false for the generic group |
string | bool | $domain | DB domain ID or false for the local domain |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 475 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$laggedReplicaMode, Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getExistingReaderIndex(), Wikimedia\Rdbms\LoadBalancer\getLoadMonitor(), Wikimedia\Rdbms\LoadBalancer\getServerCount(), Wikimedia\Rdbms\LoadBalancer\getServerName(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), Wikimedia\Rdbms\LoadBalancer\lazyLoadReplicationPositions(), Wikimedia\Rdbms\LoadBalancer\pickReaderIndex(), and Wikimedia\Rdbms\LoadBalancer\setExistingReaderIndex().
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnectionIndex(), and Wikimedia\Rdbms\LoadBalancer\getLaggedReplicaMode().
Wikimedia\Rdbms\LoadBalancer::getReadOnlyReason | ( | $domain = false | ) |
string | bool | $domain | DB domain ID or false for the local domain |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1983 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$readOnlyReason, Wikimedia\Rdbms\LoadBalancer\getExistingReaderIndex(), Wikimedia\Rdbms\LoadBalancer\getLaggedReplicaMode(), Wikimedia\Rdbms\LoadBalancer\isMasterRunningReadOnly(), Wikimedia\Rdbms\DatabaseDomain\newFromId(), and Wikimedia\Rdbms\LoadBalancer\resolveDomainID().
Wikimedia\Rdbms\LoadBalancer::getReplicaResumePos | ( | ) |
Get the highest DB replication position for chronology control purposes.
If there is only a master server then this returns false. If replication is present and correctly configured, then this returns the highest replication position of any server with an open connection. That position can later be passed to waitFor() on a new load balancer instance to make sure that queries on the new connections see data at least as up-to-date as queries (prior to this method call) on the old connections.
This can be useful for implementing session consistency, where the session will be resumed accross multiple HTTP requests or CLI script instances.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1475 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getAnyOpenConnection(), Wikimedia\Rdbms\LoadBalancer\getServerCount(), and Wikimedia\Rdbms\LoadBalancer\getWriterIndex().
|
private |
int | $i | Server index or DB_MASTER/DB_REPLICA |
Definition at line 1050 of file LoadBalancer.php.
References DB_MASTER, DB_REPLICA, and Wikimedia\Rdbms\LoadBalancer\getWriterIndex().
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnectionRef(), Wikimedia\Rdbms\LoadBalancer\getLazyConnectionRef(), and Wikimedia\Rdbms\LoadBalancer\getMaintenanceConnectionRef().
Wikimedia\Rdbms\LoadBalancer::getServerAttributes | ( | $i | ) |
int | $i | Server index |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1235 of file LoadBalancer.php.
References Wikimedia\Rdbms\Database\attributesFromType(), and Wikimedia\Rdbms\LoadBalancer\getServerType().
Referenced by Wikimedia\Rdbms\LoadBalancer\sanitizeConnectionFlags().
Wikimedia\Rdbms\LoadBalancer::getServerConnection | ( | $i, | |
$domain, | |||
$flags = 0 |
|||
) |
int | $i | Specific server index |
string | $domain | Resolved DB domain |
int | $flags | Bitfield of class CONN_* constants |
InvalidArgumentException | When the server index is invalid |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 921 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$connectionCounter, Wikimedia\Rdbms\LoadBalancer\$readOnlyReason, Wikimedia\Rdbms\LoadBalancer\enforceConnectionFlags(), Wikimedia\Rdbms\LoadBalancer\getForeignConnection(), Wikimedia\Rdbms\LoadBalancer\getLocalConnection(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), Wikimedia\Rdbms\LoadBalancer\isMasterConnectionReadOnly(), and Wikimedia\Rdbms\LoadBalancer\reportConnectionError().
Referenced by Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getConnection(), Wikimedia\Rdbms\LoadBalancer\isMasterRunningReadOnly(), Wikimedia\Rdbms\LoadBalancer\pickReaderIndex(), and Wikimedia\Rdbms\LoadBalancer\waitForMasterPos().
Wikimedia\Rdbms\LoadBalancer::getServerCount | ( | ) |
Get the number of servers defined in configuration.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1420 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), Wikimedia\Rdbms\LoadBalancer\getReplicaResumePos(), Wikimedia\Rdbms\LoadBalancer\hasReplicaServers(), Wikimedia\Rdbms\LoadBalancer\waitForAll(), and Wikimedia\Rdbms\LoadBalancer\waitForMasterPos().
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 1444 of file LoadBalancer.php.
|
private |
int | $i | Server index |
string | null | $field | Server index field [optional] |
InvalidArgumentException |
Definition at line 2369 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getForeignConnection(), Wikimedia\Rdbms\LoadBalancer\getLocalConnection(), and Wikimedia\Rdbms\LoadBalancer\getMaxLag().
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 1438 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\closeConnection(), Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getLocalConnection(), Wikimedia\Rdbms\LoadBalancer\getMasterServerName(), Wikimedia\Rdbms\LoadBalancer\getRandomNonLagged(), Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), 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 1448 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getServerAttributes(), and Wikimedia\Rdbms\LoadBalancer\sanitizeConnectionFlags().
Wikimedia\Rdbms\LoadBalancer::getTransactionRoundStage | ( | ) |
Definition at line 1924 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$trxRoundStage.
Wikimedia\Rdbms\LoadBalancer::getWriterIndex | ( | ) |
Get the server index of the master server.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1394 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), Wikimedia\Rdbms\LoadBalancer\forEachOpenReplicaConnection(), Wikimedia\Rdbms\LoadBalancer\getAnyOpenConnection(), Wikimedia\Rdbms\LoadBalancer\getConnection(), Wikimedia\Rdbms\LoadBalancer\getConnectionIndex(), Wikimedia\Rdbms\LoadBalancer\getLagTimes(), Wikimedia\Rdbms\LoadBalancer\getMasterPos(), Wikimedia\Rdbms\LoadBalancer\getMasterServerName(), Wikimedia\Rdbms\LoadBalancer\getRandomNonLagged(), Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), Wikimedia\Rdbms\LoadBalancer\getReplicaResumePos(), Wikimedia\Rdbms\LoadBalancer\getRoleFromIndex(), Wikimedia\Rdbms\LoadBalancer\getServerConnection(), Wikimedia\Rdbms\LoadBalancer\hasMasterConnection(), Wikimedia\Rdbms\LoadBalancer\hasStreamingReplicaServers(), Wikimedia\Rdbms\LoadBalancer\isMasterRunningReadOnly(), Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection(), Wikimedia\Rdbms\LoadBalancer\safeGetLag(), Wikimedia\Rdbms\LoadBalancer\sanitizeConnectionFlags(), Wikimedia\Rdbms\LoadBalancer\waitForMasterPos(), 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 1932 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 1928 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 1950 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\hasMasterChanges(), and Wikimedia\Rdbms\LoadBalancer\lastMasterChangeTimestamp().
Wikimedia\Rdbms\LoadBalancer::hasReplicaServers | ( | ) |
Whether there are any replica servers configured.
This counts both servers using streaming replication from the master server and servers that just have a clone of the static dataset found on the master server
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1424 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getServerCount().
Referenced by Wikimedia\Rdbms\LoadBalancer\getLagTimes(), and Wikimedia\Rdbms\LoadBalancer\getMaxLag().
Wikimedia\Rdbms\LoadBalancer::hasStreamingReplicaServers | ( | ) |
Whether any replica servers use streaming replication from the master server.
Generally this is one less than getServerCount(), though it might otherwise return a lower number if some of the servers are configured with "is static". That flag is used when both the server has no active replication setup and the dataset is either read-only or occasionally updated out-of-band. For example, a script might import a new geographic information dataset each week by writing it to each server and later directing the application to use the new version.
It is possible for some replicas to be configured with "is static" but not others, though it generally should either be set for all or none of the replicas.
If this returns zero, this means that there is generally no reason to execute replication wait logic for session consistency and lag reduction.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1428 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getWriterIndex().
Referenced by Wikimedia\Rdbms\LoadBalancer\getLaggedReplicaMode().
Wikimedia\Rdbms\LoadBalancer::haveIndex | ( | $i | ) |
Returns true if the specified index is a valid server index.
int | $i |
Definition at line 1405 of file LoadBalancer.php.
|
private |
IDatabase | $conn | Master connection |
int | $flags | Bitfield of class CONN_* constants |
Definition at line 2004 of file LoadBalancer.php.
References Wikimedia\Rdbms\IDatabase\dbSchema(), Wikimedia\Rdbms\IDatabase\getDBname(), Wikimedia\Rdbms\IDatabase\getServer(), Wikimedia\Rdbms\IDatabase\serverIsReadOnly(), and IExpiringStore\TTL_PROC_SHORT.
Referenced by Wikimedia\Rdbms\LoadBalancer\getServerConnection(), and Wikimedia\Rdbms\LoadBalancer\isMasterRunningReadOnly().
|
private |
DatabaseDomain | $domain |
Definition at line 2041 of file LoadBalancer.php.
References Wikimedia\Rdbms\DatabaseDomain\getDatabase(), Wikimedia\Rdbms\DatabaseDomain\getId(), Wikimedia\Rdbms\DatabaseDomain\getSchema(), Wikimedia\Rdbms\LoadBalancer\getServerConnection(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), Wikimedia\Rdbms\LoadBalancer\isMasterConnectionReadOnly(), Wikimedia\Rdbms\LoadBalancer\reuseConnection(), and IExpiringStore\TTL_PROC_LONG.
Referenced by Wikimedia\Rdbms\LoadBalancer\getReadOnlyReason().
Wikimedia\Rdbms\LoadBalancer::isNonZeroLoad | ( | $i | ) |
Returns true if the specified index is valid and has non-zero load.
int | $i |
Definition at line 1416 of file LoadBalancer.php.
|
private |
Test if the specified index represents an open connection.
int | $index | Server index |
Definition at line 1248 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 1979 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$laggedReplicaMode.
Wikimedia\Rdbms\LoadBalancer::lastMasterChangeTimestamp | ( | ) |
Get the timestamp of the latest write query done by this thread.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1941 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), and Wikimedia\Rdbms\IDatabase\lastDoneWrites().
Referenced by Wikimedia\Rdbms\LoadBalancer\hasOrMadeRecentMasterChanges().
|
private |
Make sure that any "waitForPos" positions are loaded and available to doWait()
Definition at line 1355 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$chronologyCallback.
Referenced by Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), and Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
staticprivate |
Definition at line 251 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\__construct(), and Wikimedia\Rdbms\LoadBalancer\closeAll().
Wikimedia\Rdbms\LoadBalancer::openConnection | ( | $i, | |
$domain = false , |
|||
$flags = 0 |
|||
) |
int | $i | |
string | bool | $domain | |
int | $flags |
Definition at line 1063 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getConnection().
Wikimedia\Rdbms\LoadBalancer::pendingMasterChangeCallers | ( | ) |
Get the list of callers that have pending master changes.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1957 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), and Wikimedia\Rdbms\IDatabase\pendingWriteCallers().
|
private |
IDatabase[] | $candidateConns | |
bool | $autocommit | Whether to only look for auto-commit connections |
Definition at line 767 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getAnyOpenConnection().
|
private |
array | $loads | List of server weights |
string | bool | $domain |
Definition at line 557 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$laggedReplicaMode, Wikimedia\Rdbms\LoadBalancer\allowLagged(), Wikimedia\Rdbms\LoadBalancer\getRandomNonLagged(), Wikimedia\Rdbms\LoadBalancer\getServerConnection(), Wikimedia\Rdbms\LoadBalancer\getServerName(), ArrayUtils\pickRandom(), and Wikimedia\Rdbms\LoadBalancer\reuseConnection().
Referenced by Wikimedia\Rdbms\LoadBalancer\getReaderIndex().
Wikimedia\Rdbms\LoadBalancer::pingAll | ( | ) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 2082 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 1263 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$agent, Wikimedia\Rdbms\LoadBalancer\$cliMode, Wikimedia\Rdbms\LoadBalancer\$connectionCounter, Wikimedia\Rdbms\LoadBalancer\$connLogger, Wikimedia\Rdbms\LoadBalancer\$deprecationLogger, Wikimedia\Rdbms\LoadBalancer\$errorLogger, Wikimedia\Rdbms\LoadBalancer\$id, Wikimedia\Rdbms\LoadBalancer\$profiler, Wikimedia\Rdbms\LoadBalancer\$queryLogger, Wikimedia\Rdbms\LoadBalancer\$srvCache, Wikimedia\Rdbms\LoadBalancer\$trxProfiler, Wikimedia\Rdbms\LoadBalancer\applyTransactionRoundFlags(), DB_MASTER, DBO_DEFAULT, Wikimedia\Rdbms\Database\factory(), Wikimedia\Rdbms\LoadBalancer\getCurrentConnectionCount(), Wikimedia\Rdbms\DatabaseDomain\getDatabase(), Wikimedia\Rdbms\LoadBalancer\getLazyConnectionRef(), Wikimedia\Rdbms\DatabaseDomain\getSchema(), Wikimedia\Rdbms\LoadBalancer\getServerName(), Wikimedia\Rdbms\DatabaseDomain\getTablePrefix(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), and Wikimedia\Rdbms\LoadBalancer\lazyLoadReplicationPositions().
Referenced by Wikimedia\Rdbms\LoadBalancer\getForeignConnection(), and Wikimedia\Rdbms\LoadBalancer\getLocalConnection().
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 2331 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\closeAll(), Wikimedia\Rdbms\DatabaseDomain\newFromId(), and Wikimedia\Rdbms\LoadBalancer\setLocalDomain().
|
private |
DBConnectionError |
Definition at line 1366 of file LoadBalancer.php.
References $context, Wikimedia\Rdbms\LoadBalancer\$errorConnection, and Wikimedia\Rdbms\LoadBalancer\$lastError.
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnectionIndex(), Wikimedia\Rdbms\LoadBalancer\getMasterPos(), and Wikimedia\Rdbms\LoadBalancer\getServerConnection().
Wikimedia\Rdbms\LoadBalancer::resolveDomainID | ( | $domain | ) |
DatabaseDomain | string | bool | $domain | Database domain |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 268 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\getLocalDomainID().
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnection(), Wikimedia\Rdbms\LoadBalancer\getConnectionRef(), Wikimedia\Rdbms\LoadBalancer\getLazyConnectionRef(), Wikimedia\Rdbms\LoadBalancer\getMaintenanceConnectionRef(), and Wikimedia\Rdbms\LoadBalancer\getReadOnlyReason().
|
private |
Resolve $groups into a list of query groups defining as having database servers.
string[] | string | bool | $groups | Query group(s) in preference order, [], or false |
int | $i | Specific server index or DB_MASTER/DB_REPLICA |
Definition at line 284 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$defaultGroup.
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnection().
Wikimedia\Rdbms\LoadBalancer::reuseConnection | ( | IDatabase | $conn | ) |
Mark a live handle as being available for reuse under a different database domain.
This mechanism is reference-counted, and must be called the same number of times as getConnection() to work. Never call this on handles acquired via getConnectionRef(), getLazyConnectionRef(), and getMaintenanceConnectionRef(), as they already manage the logic of calling this method when they fall out of scope in PHP.
IDatabase | $conn |
LogicException |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 974 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\isMasterRunningReadOnly(), and Wikimedia\Rdbms\LoadBalancer\pickReaderIndex().
Wikimedia\Rdbms\LoadBalancer::rollbackMasterChanges | ( | $fname = __METHOD__ , |
|
$owner = null |
|||
) |
Issue ROLLBACK only on master, only if queries were done on connection.
string | $fname | Caller name |
int | null | $owner | ID of the calling instance (e.g. the LBFactory ID) |
DBExpectedError |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1800 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\assertOwnership(), Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), Wikimedia\Rdbms\IDatabase\rollback(), and Wikimedia\Rdbms\LoadBalancer\undoTransactionRoundFlags().
Wikimedia\Rdbms\LoadBalancer::runMasterTransactionIdleCallbacks | ( | $fname = __METHOD__ , |
|
$owner = null |
|||
) |
Consume and run all pending post-COMMIT/ROLLBACK callbacks and commit dangling transactions.
string | $fname | Caller name |
int | null | $owner | ID of the calling instance (e.g. the LBFactory ID) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1694 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$trxRoundStage, $type, Wikimedia\Rdbms\LoadBalancer\assertOwnership(), Wikimedia\Rdbms\Database\commit(), Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), Wikimedia\Rdbms\Database\getDBname(), Wikimedia\Rdbms\Database\getServer(), Wikimedia\Rdbms\Database\pendingWriteAndCallbackCallers(), Wikimedia\Rdbms\Database\runOnTransactionIdleCallbacks(), Wikimedia\Rdbms\Database\setTrxEndCallbackSuppression(), Wikimedia\Rdbms\Database\trxLevel(), and Wikimedia\Rdbms\Database\writesPending().
Wikimedia\Rdbms\LoadBalancer::runMasterTransactionListenerCallbacks | ( | $fname = __METHOD__ , |
|
$owner = null |
|||
) |
Run all recurring post-COMMIT/ROLLBACK listener callbacks.
string | $fname | Caller name |
int | null | $owner | ID of the calling instance (e.g. the LBFactory ID) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1768 of file LoadBalancer.php.
References $type, Wikimedia\Rdbms\LoadBalancer\assertOwnership(), 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 |
Definition at line 2194 of file LoadBalancer.php.
References Wikimedia\Rdbms\IDatabase\getLag(), Wikimedia\Rdbms\IDatabase\getLBInfo(), and Wikimedia\Rdbms\LoadBalancer\getWriterIndex().
Wikimedia\Rdbms\LoadBalancer::safeWaitForMasterPos | ( | IDatabase | $conn, |
$pos = false , |
|||
$timeout = null |
|||
) |
Wait for a replica DB to reach a specified master position.
This will connect to the master to get an accurate position if $pos is not given
IDatabase | $conn | Replica DB |
DBMasterPos | bool | $pos | Master position; default: current position |
int | $timeout | Timeout in seconds [optional] |
Definition at line 2274 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\waitForMasterPos().
|
private |
int | $flags | Bitfield of class CONN_* constants |
int | $i | Specific server index or DB_MASTER/DB_REPLICA |
string | $domain | Database domain |
Definition at line 310 of file LoadBalancer.php.
References $type, DB_MASTER, Wikimedia\Rdbms\LoadBalancer\getServerAttributes(), Wikimedia\Rdbms\LoadBalancer\getServerType(), and Wikimedia\Rdbms\LoadBalancer\getWriterIndex().
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnection().
|
private |
int | $i | Specific server index |
Definition at line 709 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\waitForAll().
|
private |
Set the server index chosen by the load balancer for use with the given query group.
string | $group | Query group; use false for the generic group |
int | $index | The index of a specific server |
Definition at line 545 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getReaderIndex().
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 2295 of file LoadBalancer.php.
|
private |
DatabaseDomain | $domain |
Definition at line 2351 of file LoadBalancer.php.
References Wikimedia\Rdbms\DatabaseDomain\getDatabase().
Referenced by Wikimedia\Rdbms\LoadBalancer\__construct(), Wikimedia\Rdbms\LoadBalancer\redefineLocalDomain(), and Wikimedia\Rdbms\LoadBalancer\setLocalDomainPrefix().
Wikimedia\Rdbms\LoadBalancer::setLocalDomainPrefix | ( | $prefix | ) |
Set a new table prefix for the existing local domain ID for testing.
string | $prefix |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 2299 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\forEachOpenConnection(), Wikimedia\Rdbms\IDatabase\getDomainID(), Wikimedia\Rdbms\IDatabase\getLBInfo(), Wikimedia\Rdbms\LoadBalancer\setLocalDomain(), and Wikimedia\Rdbms\IDatabase\tablePrefix().
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 2291 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::setTempTablesOnlyMode | ( | $value, | |
$domain | |||
) |
Indicate whether the tables on this domain are only temporary tables for testing.
In "temporary tables mode", the ILoadBalancer::CONN_TRX_AUTOCOMMIT flag is ignored
bool | $value | |
string | $domain |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 2337 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 2278 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\forEachOpenMasterConnection(), and Wikimedia\Rdbms\IDatabase\setTransactionListener().
|
private |
DBMasterPos | bool | $pos |
Definition at line 722 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\waitFor().
|
private |
Database | $conn |
Definition at line 1892 of file LoadBalancer.php.
References DBO_DEFAULT, DBO_TRX, 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 position to reach before the next generic group DB handle query.
If a generic replica DB connection is already open then this immediately waits for that DB to catch up to the specified replication position. Otherwise, it will do so once such a connection is opened.
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 635 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$waitForPos, Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getExistingReaderIndex(), 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 678 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$waitForPos, Wikimedia\Rdbms\LoadBalancer\$waitTimeout, Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getServerCount(), and Wikimedia\Rdbms\LoadBalancer\serverHasLoadInAnyGroup().
Wikimedia\Rdbms\LoadBalancer::waitForMasterPos | ( | IDatabase | $conn, |
$pos = false , |
|||
$timeout = null |
|||
) |
Wait for a replica DB to reach a specified master position.
If $conn is not a replica server connection, then this will return true. Otherwise, if $pos is not provided, this will connect to the master server to get an accurate position.
IDatabase | $conn | Replica DB |
DBMasterPos | bool | $pos | Master position; default: current position |
int | $timeout | Timeout in seconds [optional] |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 2204 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\closeConnection(), Wikimedia\Rdbms\LoadBalancer\getAnyOpenConnection(), Wikimedia\Rdbms\IDatabase\getLBInfo(), Wikimedia\Rdbms\IDatabase\getServer(), Wikimedia\Rdbms\LoadBalancer\getServerConnection(), Wikimedia\Rdbms\LoadBalancer\getServerCount(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), and Wikimedia\Rdbms\IDatabase\masterPosWait().
Referenced by Wikimedia\Rdbms\LoadBalancer\safeWaitForMasterPos().
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 651 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\$waitForPos, Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getExistingReaderIndex(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), and ArrayUtils\pickRandom().
|
private |
Agent name for query profiling.
Definition at line 98 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 81 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\allowLagged().
|
private |
Callback to run before the first connection attempt.
Definition at line 46 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\lazyLoadReplicationPositions().
|
private |
Whether this PHP instance is for a CLI script.
Definition at line 96 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
Whether any connection has been attempted yet.
Definition at line 130 of file LoadBalancer.php.
|
private |
Total number of new connections ever made with this instance.
Definition at line 126 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getServerConnection(), and Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
Definition at line 58 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
Map of (connection category => server index => IDatabase[])
Definition at line 74 of file LoadBalancer.php.
|
private |
Default query group to use with getConnection()
Definition at line 91 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\resolveGroups().
|
private |
Deprecation logger.
Definition at line 66 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
Definition at line 128 of file LoadBalancer.php.
|
private |
Connection handle that caused a problem.
Definition at line 114 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reportConnectionError().
|
private |
Exception logger.
Definition at line 64 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 79 of file LoadBalancer.php.
|
private |
Current server name.
Definition at line 94 of file LoadBalancer.php.
|
private |
var int An identifier for this class instance
Definition at line 133 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
Map of (index alias => index)
Definition at line 103 of file LoadBalancer.php.
|
private |
Whether the generic reader fell back to a lagged replica DB.
Definition at line 120 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 122 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getConnectionIndex(), and Wikimedia\Rdbms\LoadBalancer\reportConnectionError().
|
private |
Definition at line 44 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getLoadMonitor().
|
private |
The LoadMonitor configuration.
Definition at line 85 of file LoadBalancer.php.
|
private |
Local DB domain ID and default for selectDB() calls.
Definition at line 69 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\__construct().
|
private |
Alternate local DB domain instead of DatabaseDomain::getId()
Definition at line 87 of file LoadBalancer.php.
|
private |
Amount of replication lag, in seconds, that is considered "high".
Definition at line 89 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\__construct(), Wikimedia\Rdbms\LoadBalancer\getMaxLag(), and Wikimedia\Rdbms\LoadBalancer\getRandomNonLagged().
|
private |
Integer ID of the managing LBFactory instance or null if none.
Definition at line 135 of file LoadBalancer.php.
|
private |
Definition at line 62 of file LoadBalancer.php.
|
private |
Class name or object With profileIn/profileOut methods.
Definition at line 52 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
Definition at line 60 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
The group replica server indexes keyed by group.
Definition at line 116 of file LoadBalancer.php.
|
private |
Reason this instance is read-only or false if not.
Definition at line 124 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getReadOnlyReason(), and Wikimedia\Rdbms\LoadBalancer\getServerConnection().
|
private |
Definition at line 56 of file LoadBalancer.php.
|
private |
Map of (server index => server config array)
Definition at line 77 of file LoadBalancer.php.
|
private |
Definition at line 48 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
$aliases Map of (table => (dbname, schema, prefix) map)
Definition at line 101 of file LoadBalancer.php.
|
private |
Map of (domain => whether to use "temp tables only" mode)
Definition at line 107 of file LoadBalancer.php.
|
private |
Definition at line 54 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\reallyOpenConnection().
|
private |
Map of (name => callable)
Definition at line 105 of file LoadBalancer.php.
|
private |
Explicit DBO_TRX transaction round active or false if none.
Definition at line 110 of file LoadBalancer.php.
|
private |
Stage of the current transaction round in the transaction round life-cycle.
Definition at line 112 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getTransactionRoundStage(), and Wikimedia\Rdbms\LoadBalancer\runMasterTransactionIdleCallbacks().
|
private |
Replication sync position or false if not set.
Definition at line 118 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 83 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\waitForAll().
|
private |
Definition at line 50 of file LoadBalancer.php.
const Wikimedia\Rdbms\LoadBalancer::KEY_FOREIGN_FREE = 'foreignFree' |
Definition at line 148 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getForeignConnection(), and Wikimedia\Rdbms\LoadBalancer\reuseConnection().
const Wikimedia\Rdbms\LoadBalancer::KEY_FOREIGN_FREE_NOROUND = 'foreignFreeAutoCommit' |
Definition at line 152 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getForeignConnection(), and Wikimedia\Rdbms\LoadBalancer\reuseConnection().
const Wikimedia\Rdbms\LoadBalancer::KEY_FOREIGN_INUSE = 'foreignInUse' |
Definition at line 149 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getForeignConnection(), and Wikimedia\Rdbms\LoadBalancer\reuseConnection().
const Wikimedia\Rdbms\LoadBalancer::KEY_FOREIGN_INUSE_NOROUND = 'foreignInUseAutoCommit' |
Definition at line 153 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getForeignConnection(), and Wikimedia\Rdbms\LoadBalancer\reuseConnection().
const Wikimedia\Rdbms\LoadBalancer::KEY_LOCAL = 'local' |
Definition at line 147 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getLocalConnection().
const Wikimedia\Rdbms\LoadBalancer::KEY_LOCAL_NOROUND = 'localAutoCommit' |
Definition at line 151 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\getLocalConnection().