MediaWiki REL1_33
|
Database cluster connection, tracking, load balancing, and transaction manager interface. More...
Public Member Functions | |
__construct (array $params) | |
Construct a manager of IDatabase connection objects. | |
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 ( $i, $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 ( $i, $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 ( $i, $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. | |
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: | |
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=10) | |
Wait for a replica DB to reach a specified master position. | |
setIndexAliases (array $aliases) | |
Convert certain index names to alternative names before querying the DB. | |
setLocalDomainPrefix ( $prefix) | |
Set a new table prefix for the existing local domain ID for testing. | |
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. | |
Database cluster connection, tracking, load balancing, and transaction manager interface.
A "cluster" is considered to be one master database and zero or more replica databases. Typically, the replica DBs replicate from the master asynchronously. The first node in the "servers" configuration array is always considered the "master". However, this class can still be used when all or some of the "replica" DBs are multi-master peers of the master or even when all the DBs are non-replicating clones of each other holding read-only data. Thus, the role of "master" is in some cases merely nominal.
By default, each DB server uses DBO_DEFAULT for its 'flags' setting, unless explicitly set otherwise in configuration. DBO_DEFAULT behavior depends on whether 'cliMode' is set:
The typical caller will use LoadBalancer::getConnection( DB_* ) to yield a live database connection handle. The choice of which DB server to use is based on pre-defined loads for weighted random selection, adjustments thereof by LoadMonitor, and the amount of replication lag on each DB server. Lag checks might cause problems in certain setups, so they should be tuned in the server configuration maps as follows:
If using a SQL proxy service, it would probably be best to have two proxy hosts for the load balancer to talk to. One would be the 'host' of the master server entry and another for the (logical) replica server entry. The proxy could map the load balancer's "replica" DB to any number of physical replica DBs.
Definition at line 78 of file ILoadBalancer.php.
Wikimedia\Rdbms\ILoadBalancer::__construct | ( | array | $params | ) |
Construct a manager of IDatabase connection objects.
array | $params | Parameter map with keys:
|
InvalidArgumentException |
Implemented in Wikimedia\Rdbms\LoadBalancer, and Wikimedia\Rdbms\LoadBalancerSingle.
Wikimedia\Rdbms\ILoadBalancer::allowLagged | ( | $mode = null | ) |
Disables/enables lag checks.
null | bool | $mode |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::approveMasterChanges | ( | array | $options | ) |
Perform all pre-commit checks for things like replication safety.
Use this only for mutli-database commits
array | $options | Includes:
|
DBTransactionError |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\initLoadBalancer().
Wikimedia\Rdbms\ILoadBalancer::closeAll | ( | ) |
Close all open connections.
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::commitAll | ( | $fname = __METHOD__ | ) |
Commit transactions on all open connections.
string | $fname | Caller name |
DBExpectedError |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::commitMasterChanges | ( | $fname = __METHOD__ | ) |
Issue COMMIT on all open master connections to flush changes and view snapshots.
string | $fname | Caller name |
DBExpectedError |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::disable | ( | ) |
Disable this load balancer.
All connections are closed, and any attempt to open a new connection will result in a DBAccessError.
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::finalizeMasterChanges | ( | ) |
Run pre-commit callbacks and defer execution of post-commit callbacks.
Use this only for mutli-database commits
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\commitMasterChanges().
Wikimedia\Rdbms\ILoadBalancer::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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::flushReplicaSnapshots | ( | $fname = __METHOD__ | ) |
Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
string | $fname | Caller name |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::forEachOpenConnection | ( | $callback, | |
array | $params = [] ) |
Call a function with each open connection object.
callable | $callback | |
array | $params |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::forEachOpenMasterConnection | ( | $callback, | |
array | $params = [] ) |
Call a function with each open connection object to a master.
callable | $callback | |
array | $params |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::forEachOpenReplicaConnection | ( | $callback, | |
array | $params = [] ) |
Call a function with each open replica DB connection object.
callable | $callback | |
array | $params |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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) |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by DBConnRefTest\innerMethodForTestDestruct().
Wikimedia\Rdbms\ILoadBalancer::getLaggedReplicaMode | ( | $domain = false | ) |
string | bool | $domain | Domain ID, or false for the current domain |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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) |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::getLocalDomainID | ( | ) |
Get the local (and default) database domain ID of connection handles.
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::getMaintenanceConnectionRef | ( | $i, | |
$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 | $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) |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::getMasterPos | ( | ) |
Get the current master position for chronology control purposes.
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\ChronologyProtector\shutdownLB().
Wikimedia\Rdbms\ILoadBalancer::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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
string | bool | $domain | Domain ID, or false for the current domain |
IDatabase | null | $conn | DB master connection; used to avoid loops [optional] |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::getServerAttributes | ( | $i | ) |
int | $i | Server index |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::getServerCount | ( | ) |
Get the number of defined servers (not the number of open connections)
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\appendShutdownCPIndexAsQuery(), Wikimedia\Rdbms\ChronologyProtector\initLB(), and Wikimedia\Rdbms\ChronologyProtector\shutdownLB().
Wikimedia\Rdbms\ILoadBalancer::getServerInfo | ( | $i | ) |
Return the server info structure for a given index, or false if the index is invalid.
int | $i |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::getServerName | ( | $i | ) |
Get the host name or IP address of the server with the specified index.
int | $i |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\ChronologyProtector\initLB(), Wikimedia\Rdbms\LBFactory\logIfMultiDbTransaction(), Wikimedia\Rdbms\LBFactory\shutdownChronologyProtector(), and Wikimedia\Rdbms\ChronologyProtector\shutdownLB().
Wikimedia\Rdbms\ILoadBalancer::getServerType | ( | $i | ) |
Get DB type of the server with the specified index.
int | $i |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::getWriterIndex | ( | ) |
Wikimedia\Rdbms\ILoadBalancer::hasMasterChanges | ( | ) |
Whether there are pending changes or callbacks in a transaction by this thread.
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\hasMasterChanges().
Wikimedia\Rdbms\ILoadBalancer::hasMasterConnection | ( | ) |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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] |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\hasOrMadeRecentMasterChanges(), and Wikimedia\Rdbms\ChronologyProtector\shutdownLB().
Wikimedia\Rdbms\ILoadBalancer::haveIndex | ( | $i | ) |
Returns true if the specified index is a valid server index.
int | $i |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::isNonZeroLoad | ( | $i | ) |
Returns true if the specified index is valid and has non-zero load.
int | $i |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::laggedReplicaUsed | ( | ) |
Checks whether the database for generic connections this request was both:
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\laggedReplicaUsed().
Wikimedia\Rdbms\ILoadBalancer::lastMasterChangeTimestamp | ( | ) |
Get the timestamp of the latest write query done by this thread.
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::pendingMasterChangeCallers | ( | ) |
Get the list of callers that have pending master changes.
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\logIfMultiDbTransaction().
Wikimedia\Rdbms\ILoadBalancer::pingAll | ( | ) |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::redefineLocalDomain | ( | $domain | ) |
Close all connection and redefine the local domain for testing or schema creation.
DatabaseDomain | string | $domain |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\redefineLocalDomain().
Wikimedia\Rdbms\ILoadBalancer::resolveDomainID | ( | $domain | ) |
DatabaseDomain | string | bool | $domain | Database domain |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::rollbackMasterChanges | ( | $fname = __METHOD__ | ) |
Issue ROLLBACK only on master, only if queries were done on connection.
string | $fname | Caller name |
DBExpectedError |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::runMasterTransactionIdleCallbacks | ( | ) |
Consume and run all pending post-COMMIT/ROLLBACK callbacks and commit dangling transactions.
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\executePostTransactionCallbacks().
Wikimedia\Rdbms\ILoadBalancer::runMasterTransactionListenerCallbacks | ( | ) |
Run all recurring post-COMMIT/ROLLBACK listener callbacks.
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\executePostTransactionCallbacks().
Wikimedia\Rdbms\ILoadBalancer::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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::safeWaitForMasterPos | ( | IDatabase | $conn, |
$pos = false, | |||
$timeout = 10 ) |
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] |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\initLoadBalancer().
Wikimedia\Rdbms\ILoadBalancer::setLocalDomainPrefix | ( | $prefix | ) |
Set a new table prefix for the existing local domain ID for testing.
string | $prefix |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\setLocalDomainPrefix().
Wikimedia\Rdbms\ILoadBalancer::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) |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\initLoadBalancer().
Wikimedia\Rdbms\ILoadBalancer::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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\ChronologyProtector\initLB().
Wikimedia\Rdbms\ILoadBalancer::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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\shutdownChronologyProtector().
Wikimedia\Rdbms\ILoadBalancer::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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.