MediaWiki REL1_39
|
Public Member Functions | |
__construct (array $params) | |
approvePrimaryChanges (array $options, $fname=__METHOD__) | |
Perform all pre-commit checks for things like replication safety. | |
beginPrimaryChanges ( $fname=__METHOD__) | |
Flush any primary transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set) | |
closeAll ( $fname=__METHOD__) | |
Close all open connections. | |
closeConnection (IDatabase $conn) | |
Close a connection. | |
commitAll ( $fname=__METHOD__) | |
Commit transactions on all open connections. | |
commitPrimaryChanges ( $fname=__METHOD__) | |
Issue COMMIT on all open primary connections to flush changes and view snapshots. | |
disable ( $fname=__METHOD__) | |
Close all connections and disable this load balancer. | |
explicitTrxActive () | |
Determine whether an explicit transaction is active on any open primary connection. | |
finalizePrimaryChanges ( $fname=__METHOD__) | |
Run pre-commit callbacks and defer execution of post-commit callbacks. | |
flushPrimarySessions ( $fname=__METHOD__) | |
Release/destroy session-level named locks, table locks, and temp tables. | |
flushPrimarySnapshots ( $fname=__METHOD__) | |
Commit all primary 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. | |
forEachOpenPrimaryConnection ( $callback, array $params=[]) | |
Call a function with each open connection object to a primary. | |
getAnyOpenConnection ( $i, $flags=0) | |
Get an existing DB handle to the given server index (on any domain) | |
getClusterName () | |
Get the logical name of the database cluster. | |
getConnection ( $i, $groups=[], $domain=false, $flags=0) | |
Get a lazy-connecting database handle for a specific or virtual (DB_PRIMARY/DB_REPLICA) server index. | |
getConnectionInternal ( $i, $groups=[], $domain=false, $flags=0) | |
getConnectionRef ( $i, $groups=[], $domain=false, $flags=0) | |
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 lazy-connecting database handle for a server index. | |
getLocalDomainID () | |
Get the local (and default) database domain ID of connection handles. | |
getMaintenanceConnectionRef ( $i, $groups=[], $domain=false, $flags=0) | |
Get a DB handle, suitable for migrations and schema changes, for a server index. | |
getMaxLag ( $domain=false) | |
Get the name and lag time of the most-lagged replica server. | |
getPrimaryPos () | |
Get the current primary replication position. | |
getReaderIndex ( $group=false, $domain=false) | |
Get the specific server index of the reader connection for a given group. | |
getReadOnlyReason ( $domain=false) | |
getReplicaResumePos () | |
Get the highest DB replication position for chronology control purposes. | |
getServerAttributes ( $i) | |
Get basic attributes of the server with the specified index without connecting. | |
getServerConnection ( $i, $domain, $flags=0) | |
Get a DB handle for a specific server index. | |
getServerCount () | |
Get the number of servers defined in configuration. | |
getServerInfo ( $i) | |
Return the server configuration map for the server with the specified index. | |
getServerName ( $i) | |
Get the readable name of the server with the specified index. | |
getServerType ( $i) | |
Get the RDBMS type of the server with the specified index (e.g. | |
getTransactionRoundStage () | |
getWriterIndex () | |
Get the specific server index of the primary server. | |
hasOrMadeRecentPrimaryChanges ( $age=null) | |
Check if this load balancer object had any recent or still pending writes issued against it by this PHP thread. | |
hasPrimaryChanges () | |
Whether there are pending changes or callbacks in a transaction by this thread. | |
hasPrimaryConnection () | |
hasReplicaServers () | |
Whether there are any replica servers configured. | |
hasStreamingReplicaServers () | |
Whether any replica servers use streaming replication from the primary server. | |
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: | |
lastPrimaryChangeTimestamp () | |
Get the timestamp of the latest write query done by this thread. | |
pendingPrimaryChangeCallers () | |
Get the list of callers that have pending primary changes. | |
pingAll () | |
reconfigure (array $params) | |
Apply updated configuration. | |
redefineLocalDomain ( $domain) | |
Close all connection and redefine the local domain for testing or schema creation. | |
resolveDomainID ( $domain) | |
reuseConnection (IDatabase $conn) | |
reuseConnectionInternal (IDatabase $conn) | |
rollbackPrimaryChanges ( $fname=__METHOD__) | |
Issue ROLLBACK only on primary, only if queries were done on connection. | |
runPrimaryTransactionIdleCallbacks ( $fname=__METHOD__) | |
Consume and run all pending post-COMMIT/ROLLBACK callbacks and commit dangling transactions. | |
runPrimaryTransactionListenerCallbacks ( $fname=__METHOD__) | |
Run all recurring post-COMMIT/ROLLBACK listener callbacks. | |
setDomainAliases (array $aliases) | |
Convert certain database domains to alternative ones. | |
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. | |
setTempTablesOnlyMode ( $value, $domain) | |
Indicate whether the tables on this domain are only temporary tables for testing. | |
setTransactionListener ( $name, callable $callback=null) | |
Set a callback via IDatabase::setTransactionListener() on all current and future primary connections of this load balancer. | |
waitFor ( $pos) | |
Set the primary position to reach before the next generic group DB query. | |
waitForAll ( $pos, $timeout=null) | |
Set the primary wait position and wait for ALL replica DBs to catch up to it. | |
waitForPrimaryPos (IDatabase $conn, $pos=false, $timeout=null) | |
Wait for a replica DB to reach a specified primary position. | |
Public Attributes | |
const | MAX_LAG_DEFAULT = 6 |
Default 'maxLag' when unspecified. | |
Public Attributes inherited from Wikimedia\Rdbms\ILoadBalancerForOwner | |
const | STAGE_POSTCOMMIT_CALLBACKS = 'stage-postcommit-callbacks' |
Manager of ILoadBalancer instances is running post-commit callbacks. | |
const | STAGE_POSTROLLBACK_CALLBACKS = 'stage-postrollback-callbacks' |
Manager of ILoadBalancer instances is running post-rollback callbacks. | |
Public Attributes inherited from Wikimedia\Rdbms\ILoadBalancer | |
const | CONN_INTENT_WRITABLE = 4 |
Caller is requesting the primary DB server for possibly writes. | |
const | CONN_REFRESH_READ_ONLY = 8 |
Bypass and update any server-side read-only mode state cache. | |
const | CONN_SILENCE_ERRORS = 2 |
Return null on connection failure instead of throwing an exception. | |
const | CONN_TRX_AUTOCOMMIT = 1 |
DB handle should have DBO_TRX disabled and the caller will leave it as such. | |
const | DB_MASTER = self::DB_PRIMARY |
Request a primary, write-enabled DB connection. | |
const | DB_PRIMARY = -2 |
Request a primary, write-enabled DB connection. | |
const | DB_REPLICA = -1 |
Request a replica DB connection. | |
const | DOMAIN_ANY = '' |
Domain specifier when no specific database needs to be selected. | |
const | GROUP_GENERIC = '' |
The generic query group. | |
Protected Member Functions | |
configure (array $params) | |
getConnLogContext (IDatabase $conn, array $extras=[]) | |
Create a log context to pass to PSR-3 logger functions. | |
getExistingReaderIndex ( $group) | |
Get the server index chosen by the load balancer for use with the given query group. | |
reallyOpenConnection ( $i, DatabaseDomain $domain, array $lbInfo) | |
Open a new network connection to a server (uncached) | |
resolveDomainInstance ( $domain) | |
Definition at line 42 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::__construct | ( | array | $params | ) |
array | $params | Parameter map with keys:
|
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Reimplemented in Wikimedia\Rdbms\LoadBalancerSingle.
Definition at line 191 of file LoadBalancer.php.
References Wikimedia\Rdbms\LoadBalancer\configure().
Wikimedia\Rdbms\LoadBalancer::approvePrimaryChanges | ( | array | $options, |
$fname = __METHOD__ ) |
Perform all pre-commit checks for things like replication safety.
Use this only for multi-database commits
array | $options | Includes:
|
string | $fname | Caller name |
DBTransactionError |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 1720 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::beginPrimaryChanges | ( | $fname = __METHOD__ | ) |
Flush any primary 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 |
DBExpectedError |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 1776 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::closeAll | ( | $fname = __METHOD__ | ) |
Close all open connections.
string | $fname | Caller name |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 1639 of file LoadBalancer.php.
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 1650 of file LoadBalancer.php.
References $type, Wikimedia\Rdbms\IDatabase\close(), Wikimedia\Rdbms\IDatabase\getDomainID(), and Wikimedia\Rdbms\IDatabase\getLBInfo().
Wikimedia\Rdbms\LoadBalancer::commitAll | ( | $fname = __METHOD__ | ) |
Commit transactions on all open connections.
string | $fname | Caller name |
DBExpectedError |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 1688 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::commitPrimaryChanges | ( | $fname = __METHOD__ | ) |
Issue COMMIT on all open primary connections to flush changes and view snapshots.
string | $fname | Caller name |
DBExpectedError |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 1802 of file LoadBalancer.php.
|
protected |
array | $params | A database configuration array, see $wgLBFactoryConf. |
Definition at line 202 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadBalancer\__construct().
Wikimedia\Rdbms\LoadBalancer::disable | ( | $fname = __METHOD__ | ) |
Close all connections and disable this load balancer.
Any attempt to open a new connection will result in a DBAccessError.
string | $fname | Caller name |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 1634 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::explicitTrxActive | ( | ) |
Determine whether an explicit transaction is active on any open primary connection.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 2079 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::finalizePrimaryChanges | ( | $fname = __METHOD__ | ) |
Run pre-commit callbacks and defer execution of post-commit callbacks.
Use this only for multi-database commits
string | $fname | Caller name |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 1694 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::flushPrimarySessions | ( | $fname = __METHOD__ | ) |
Release/destroy session-level named locks, table locks, and temp tables.
Only call this function right after calling rollbackPrimaryChanges()
string | $fname | Caller name |
DBExpectedError |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 1945 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::flushPrimarySnapshots | ( | $fname = __METHOD__ | ) |
Commit all primary DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
An error will be thrown if a connection has pending writes or callbacks
string | $fname | Caller name |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 2026 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::flushReplicaSnapshots | ( | $fname = __METHOD__ | ) |
Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
string | $fname | Caller name |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 2020 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::forEachOpenConnection | ( | $callback, | |
array | $params = [] ) |
Call a function with each open connection object.
callable | $callback | |
array | $params |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 2226 of file LoadBalancer.php.
References wfDeprecated().
Wikimedia\Rdbms\LoadBalancer::forEachOpenPrimaryConnection | ( | $callback, | |
array | $params = [] ) |
Call a function with each open connection object to a primary.
callable | $callback | |
array | $params |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 2233 of file LoadBalancer.php.
References wfDeprecated().
Wikimedia\Rdbms\LoadBalancer::getAnyOpenConnection | ( | $i, | |
$flags = 0 ) |
Get an existing DB handle to the given server index (on any domain)
Use the CONN_TRX_AUTOCOMMIT flag to only look for connections opened with that flag.
Avoid the use of begin()/commit() and startAtomic()/endAtomic() on any handle returned. This method is intended for internal RDBMS callers that issue queries that do not affect any current transaction.
int | $i | Specific or virtual (DB_PRIMARY/DB_REPLICA) server index |
int | $flags | Bitfield of CONN_* class constants |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 783 of file LoadBalancer.php.
References $type, and DB_PRIMARY.
Wikimedia\Rdbms\LoadBalancer::getClusterName | ( | ) |
Get the logical name of the database cluster.
This is useful for identifying a cluster or replicated dataset, even when:
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 290 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getConnection | ( | $i, | |
$groups = [], | |||
$domain = false, | |||
$flags = 0 ) |
Get a lazy-connecting database handle for a specific or virtual (DB_PRIMARY/DB_REPLICA) server index.
The server index, $i, can be one of the following:
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_PRIMARY 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.
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 | Specific (overrides $groups) or virtual (DB_PRIMARY/DB_REPLICA) server index |
string[] | string | $groups | Query group(s) in preference order; [] for the default group |
string | false | $domain | DB domain ID or false for the local domain |
int | $flags | Bitfield of CONN_* class constants |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 930 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getConnectionInternal | ( | $i, | |
$groups = [], | |||
$domain = false, | |||
$flags = 0 ) |
int | $i | Specific (overrides $groups) or virtual (DB_PRIMARY/DB_REPLICA) server index |
string[] | string | $groups | Query group(s) in preference order; [] for the default group |
string | false | $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 934 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getConnectionRef | ( | $i, | |
$groups = [], | |||
$domain = false, | |||
$flags = 0 ) |
int | $i | Specific or virtual (DB_PRIMARY/DB_REPLICA) server index |
string[] | string | $groups | Query group(s) in preference order; [] for the default group |
string | false | $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 1074 of file LoadBalancer.php.
|
protected |
Create a log context to pass to PSR-3 logger functions.
IDatabase | $conn | |
array | $extras | Additional data to add to context |
Definition at line 2514 of file LoadBalancer.php.
References Wikimedia\Rdbms\IDatabase\getDomainID(), and Wikimedia\Rdbms\IDatabase\getServerName().
|
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 598 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getLaggedReplicaMode | ( | $domain = false | ) |
string | false | $domain | DB domain ID or false for the local domain |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 2088 of file LoadBalancer.php.
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 | false | $domain |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 2322 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getLazyConnectionRef | ( | $i, | |
$groups = [], | |||
$domain = false, | |||
$flags = 0 ) |
Get a lazy-connecting database handle for a 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 | Specific or virtual (DB_PRIMARY/DB_REPLICA) server index |
string[] | string | $groups | Query group(s) in preference order; [] for the default group |
string | false | $domain | DB domain ID or false for the local domain |
int | $flags | Bitfield of CONN_* class constants |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1087 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getLocalDomainID | ( | ) |
Get the local (and default) database domain ID of connection handles.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 301 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getMaintenanceConnectionRef | ( | $i, | |
$groups = [], | |||
$domain = false, | |||
$flags = 0 ) |
Get a DB handle, suitable for migrations and schema changes, for a server index.
The DBConnRef methods simply proxy an underlying IDatabase object 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 | Specific or virtual (DB_PRIMARY/DB_REPLICA) server index |
string[] | string | $groups | Query group(s) in preference order; [] for the default group |
string | false | $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 1092 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getMaxLag | ( | $domain = false | ) |
Get the name 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.
string | false | $domain | Domain ID or false for the default database |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 2301 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getPrimaryPos | ( | ) |
Get the current primary replication position.
DBError |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1557 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getReaderIndex | ( | $group = false, | |
$domain = false ) |
Get the specific 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 (usually 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 | false | $group | Query group or false for the generic group |
string | false | $domain | DB domain ID or false for the local domain |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 536 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getReadOnlyReason | ( | $domain = false | ) |
string | false | $domain | DB domain ID or false for the local domain |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 2108 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getReplicaResumePos | ( | ) |
Get the highest DB replication position for chronology control purposes.
If there is only a primary 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 across multiple HTTP requests or CLI script instances.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1578 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getServerAttributes | ( | $i | ) |
Get basic attributes of the server with the specified index without connecting.
int | $i | Specific server index |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1293 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getServerConnection | ( | $i, | |
$domain, | |||
$flags = 0 ) |
Get a DB handle for a specific server index.
This is an internal utility method for methods like LoadBalancer::getConnectionInternal() and DBConnRef to create the underlying connection to a concrete server.
The following is the responsibility of the caller:
int | $i | Specific server index |
string | $domain | Resolved DB domain |
int | $flags | Bitfield of class CONN_* constants |
DBError | If no DB handle could be obtained and CONN_SILENCE_ERRORS is not set |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 962 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getServerCount | ( | ) |
Get the number of servers defined in configuration.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1517 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getServerInfo | ( | $i | ) |
Return the server configuration map for the server with the specified index.
int | $i | Specific server index |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1549 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getServerName | ( | $i | ) |
Get the readable name of the server with the specified index.
int | $i | Specific server index |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1543 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getServerType | ( | $i | ) |
Get the RDBMS type of the server with the specified index (e.g.
"mysql", "sqlite")
int | $i | Specific server index |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1553 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::getTransactionRoundStage | ( | ) |
Wikimedia\Rdbms\LoadBalancer::getWriterIndex | ( | ) |
Get the specific server index of the primary server.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1491 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::hasOrMadeRecentPrimaryChanges | ( | $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 2063 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::hasPrimaryChanges | ( | ) |
Whether there are pending changes or callbacks in a transaction by this thread.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 2044 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::hasPrimaryConnection | ( | ) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 2040 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::hasReplicaServers | ( | ) |
Whether there are any replica servers configured.
This counts both servers using streaming replication from the primary server and servers that just have a clone of the static dataset found on the primary server
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1521 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::hasStreamingReplicaServers | ( | ) |
Whether any replica servers use streaming replication from the primary 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 false, 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 1539 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::haveIndex | ( | $i | ) |
Returns true if the specified index is a valid server index.
int | $i |
Definition at line 1502 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::isNonZeroLoad | ( | $i | ) |
Returns true if the specified index is valid and has non-zero load.
int | $i |
Definition at line 1513 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::laggedReplicaUsed | ( | ) |
Checks whether the database for generic connections this request was both:
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 2104 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::lastPrimaryChangeTimestamp | ( | ) |
Get the timestamp of the latest write query done by this thread.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 2054 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::pendingPrimaryChangeCallers | ( | ) |
Get the list of callers that have pending primary changes.
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 2070 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::pingAll | ( | ) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 2215 of file LoadBalancer.php.
References $success.
|
protected |
Open a new network connection to a server (uncached)
Returns a Database object whether or not the connection was successful.
int | $i | Specific server index |
DatabaseDomain | $domain | Domain the connection is for, possibly unspecified |
array | $lbInfo | Additional information for setLBInfo() |
DBAccessError | |
InvalidArgumentException |
Reimplemented in Wikimedia\Rdbms\LoadBalancerSingle.
Definition at line 1322 of file LoadBalancer.php.
References Wikimedia\Rdbms\DatabaseDomain\getDatabase(), Wikimedia\Rdbms\DatabaseDomain\getId(), Wikimedia\Rdbms\DatabaseDomain\getSchema(), and Wikimedia\Rdbms\DatabaseDomain\getTablePrefix().
Wikimedia\Rdbms\LoadBalancer::reconfigure | ( | array | $params | ) |
Apply updated configuration.
This invalidates any open connections. However, existing connections may continue to be used while they are in an active transaction. In that case, the old connection will be discarded on the first operation after the transaction is complete. The next operation will use a new connection based on the new configuration.
array | $params | A database configuration array, see $wgLBFactoryConf. |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 1620 of file LoadBalancer.php.
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 2445 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::resolveDomainID | ( | $domain | ) |
DatabaseDomain | string | false | $domain | Database domain |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 305 of file LoadBalancer.php.
|
finalprotected |
DatabaseDomain | string | false | $domain |
Definition at line 313 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::reuseConnection | ( | IDatabase | $conn | ) |
IDatabase | $conn |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1018 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::reuseConnectionInternal | ( | IDatabase | $conn | ) |
IDatabase | $conn |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1022 of file LoadBalancer.php.
References Wikimedia\Rdbms\IDatabase\getDomainID(), and Wikimedia\Rdbms\IDatabase\getLBInfo().
Wikimedia\Rdbms\LoadBalancer::rollbackPrimaryChanges | ( | $fname = __METHOD__ | ) |
Issue ROLLBACK only on primary, only if queries were done on connection.
string | $fname | Caller name |
DBExpectedError |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 1926 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::runPrimaryTransactionIdleCallbacks | ( | $fname = __METHOD__ | ) |
Consume and run all pending post-COMMIT/ROLLBACK callbacks and commit dangling transactions.
string | $fname | Caller name |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 1837 of file LoadBalancer.php.
References $type.
Wikimedia\Rdbms\LoadBalancer::runPrimaryTransactionListenerCallbacks | ( | $fname = __METHOD__ | ) |
Run all recurring post-COMMIT/ROLLBACK listener callbacks.
string | $fname | Caller name |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 1902 of file LoadBalancer.php.
References $type.
Wikimedia\Rdbms\LoadBalancer::setDomainAliases | ( | array | $aliases | ) |
Convert certain database domains to alternative ones.
This can be used for backwards compatibility logic.
DatabaseDomain[] | string[] | $aliases | Map of (domain alias => domain) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 2409 of file LoadBalancer.php.
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 2405 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::setLocalDomainPrefix | ( | $prefix | ) |
Set a new table prefix for the existing local domain ID for testing.
string | $prefix |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 2413 of file LoadBalancer.php.
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 2401 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 2451 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::setTransactionListener | ( | $name, | |
callable | $callback = null ) |
Set a callback via IDatabase::setTransactionListener() on all current and future primary connections of this load balancer.
string | $name | Callback name |
callable | null | $callback |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 2390 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::waitFor | ( | $pos | ) |
Set the primary position to reach before the next generic group DB 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. This is useful for discouraging clients from taking further actions if session consistency could not be maintained with respect to their last actions.
DBPrimaryPos | false | $pos | Primary position or false |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 712 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::waitForAll | ( | $pos, | |
$timeout = null ) |
Set the primary wait position and wait for ALL replica DBs to catch up to it.
This method is only intended for use a throttling mechanism for high-volume updates. Unlike waitFor(), failure does not effect getLaggedReplicaMode()/laggedReplicaUsed().
DBPrimaryPos | false | $pos | Primary position or false |
int | null | $timeout | Max seconds to wait; default is mWaitTimeout |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 730 of file LoadBalancer.php.
Wikimedia\Rdbms\LoadBalancer::waitForPrimaryPos | ( | IDatabase | $conn, |
$pos = false, | |||
$timeout = null ) |
Wait for a replica DB to reach a specified primary 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 primary server to get an accurate position.
IDatabase | $conn | Replica DB |
DBPrimaryPos | false | $pos | Primary position; default: current position |
int | $timeout | Timeout in seconds [optional] |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 2342 of file LoadBalancer.php.
References Wikimedia\Rdbms\IDatabase\getLBInfo(), and Wikimedia\Rdbms\IDatabase\primaryPosWait().
const Wikimedia\Rdbms\LoadBalancer::MAX_LAG_DEFAULT = 6 |
Default 'maxLag' when unspecified.
Definition at line 155 of file LoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadMonitor\__construct().