MediaWiki REL1_38
|
Database cluster connection, tracking, load balancing, and transaction manager interface. More...
Public Member Functions | |
__construct (array $params) | |
Construct a manager of IDatabase connection objects. | |
approvePrimaryChanges (array $options, $fname=__METHOD__, $owner=null) | |
Perform all pre-commit checks for things like replication safety. | |
beginPrimaryChanges ( $fname=__METHOD__, $owner=null) | |
Flush any primary transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set) | |
closeAll ( $fname=__METHOD__, $owner=null) | |
Close all open connections. | |
closeConnection (IDatabase $conn) | |
Close a connection. | |
commitAll ( $fname=__METHOD__, $owner=null) | |
Commit transactions on all open connections. | |
commitPrimaryChanges ( $fname=__METHOD__, $owner=null) | |
Issue COMMIT on all open primary connections to flush changes and view snapshots. | |
disable ( $fname=__METHOD__, $owner=null) | |
Close all connections and disable this load balancer. | |
finalizePrimaryChanges ( $fname=__METHOD__, $owner=null) | |
Run pre-commit callbacks and defer execution of post-commit callbacks. | |
flushPrimarySnapshots ( $fname=__METHOD__, $owner=null) | |
Commit all primary DB transactions so as to flush any REPEATABLE-READ or SSI snapshots. | |
flushReplicaSnapshots ( $fname=__METHOD__, $owner=null) | |
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 live 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 live handle for a specific or virtual (DB_PRIMARY/DB_REPLICA) server index. | |
getConnectionRef ( $i, $groups=[], $domain=false, $flags=0) | |
Get a live database handle reference for a server index. | |
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 reference 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 live database 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 live 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. | |
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. | |
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 () | |
redefineLocalDomain ( $domain) | |
Close all connection and redefine the local domain for testing or schema creation. | |
resolveDomainID ( $domain) | |
reuseConnection (IDatabase $conn) | |
Mark a live handle as being available for reuse under a different database domain. | |
rollbackPrimaryChanges ( $fname=__METHOD__, $owner=null) | |
Issue ROLLBACK only on primary, only if queries were done on connection. | |
runPrimaryTransactionIdleCallbacks ( $fname=__METHOD__, $owner=null) | |
Consume and run all pending post-COMMIT/ROLLBACK callbacks and commit dangling transactions. | |
runPrimaryTransactionListenerCallbacks ( $fname=__METHOD__, $owner=null) | |
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 handle 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=10) | |
Wait for a replica DB to reach a specified primary position. | |
Public Attributes | |
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. | |
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. | |
Database cluster connection, tracking, load balancing, and transaction manager interface.
A "cluster" is considered to be one primary database and zero or more replica databases. Typically, the replica DBs replicate from the primary asynchronously. The first node in the "servers" configuration array is always considered the "primary". However, this class can still be used when all or some of the "replica" DBs are multi-primary peers of the primary or even when all the DBs are non-replicating clones of each other holding read-only data. Thus, the role of "primary" 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 primary 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 81 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::approvePrimaryChanges | ( | array | $options, |
$fname = __METHOD__ , |
|||
$owner = null |
|||
) |
Perform all pre-commit checks for things like replication safety.
Use this only for multi-database commits
array | $options | Includes:
|
string | $fname | Caller name |
int | null | $owner | ID of the calling instance (e.g. the LBFactory ID) |
DBTransactionError |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::beginPrimaryChanges | ( | $fname = __METHOD__ , |
|
$owner = null |
|||
) |
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 |
int | null | $owner | ID of the calling instance (e.g. the LBFactory ID) |
DBExpectedError |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\initLoadBalancer().
Wikimedia\Rdbms\ILoadBalancer::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) |
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__ , |
|
$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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::commitPrimaryChanges | ( | $fname = __METHOD__ , |
|
$owner = null |
|||
) |
Issue COMMIT on all open primary 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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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) |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::finalizePrimaryChanges | ( | $fname = __METHOD__ , |
|
$owner = null |
|||
) |
Run pre-commit callbacks and defer execution of post-commit callbacks.
Use this only for multi-database commits
string | $fname | Caller name |
int | null | $owner | ID of the calling instance (e.g. the LBFactory ID) |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\commitPrimaryChanges().
Wikimedia\Rdbms\ILoadBalancer::flushPrimarySnapshots | ( | $fname = __METHOD__ , |
|
$owner = null |
|||
) |
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 |
int | null | $owner | ID of the calling instance (e.g. the LBFactory ID) |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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) |
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::forEachOpenPrimaryConnection | ( | $callback, | |
array | $params = [] |
||
) |
Call a function with each open connection object to a primary.
callable | $callback | |
array | $params |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::getAnyOpenConnection | ( | $i, | |
$flags = 0 |
|||
) |
Get an existing live 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 largely intended for internal by 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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::getClusterName | ( | ) |
Get the logical name of the database cluster.
This is useful for identifying a cluster or replicated dataset, even when:
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\ChronologyProtector\applySessionReplicationPosition(), Wikimedia\Rdbms\ChronologyProtector\getTouched(), and Wikimedia\Rdbms\ChronologyProtector\stageSessionReplicationPosition().
Wikimedia\Rdbms\ILoadBalancer::getConnection | ( | $i, | |
$groups = [] , |
|||
$domain = false , |
|||
$flags = 0 |
|||
) |
Get a live handle for a specific or virtual (DB_PRIMARY/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_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.
Callers of this function that use a non-local $domain must call reuseConnection() after their last query on this handle executed. This lets the load balancer share the 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 | 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 | bool | $domain | DB domain ID or false for the local domain |
int | $flags | Bitfield of CONN_* class constants |
DBError | If no live handle could be obtained and CONN_SILENCE_ERRORS is not set |
DBAccessError | If disable() was previously called |
InvalidArgumentException |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::getConnectionRef | ( | $i, | |
$groups = [] , |
|||
$domain = false , |
|||
$flags = 0 |
|||
) |
Get a live database handle reference 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. The getServerAttributes() method 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 | bool | $domain | DB domain ID or false for the local domain |
int | $flags | Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT) |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by ApiTag\__construct(), SpecialDoubleRedirects\__construct(), BlockListPager\__construct(), DeletedContribsPager\__construct(), ProtectedPagesPager\__construct(), ImageListPager\__construct(), NewFilesPager\__construct(), UsersPager\__construct(), AllMessagesTablePager\__construct(), CategoryPager\__construct(), SearchDatabase\__construct(), SpecialRandomRootPage\__construct(), MergeHistory\__construct(), MergeHistoryPager\__construct(), NewPagesPager\__construct(), and ProtectedTitlesPager\__construct().
Wikimedia\Rdbms\ILoadBalancer::getLaggedReplicaMode | ( | $domain = false | ) |
string | bool | $domain | DB domain ID or false for the local 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 lazy-connecting database handle reference for a 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 | Specific or virtual (DB_PRIMARY/DB_REPLICA) server index |
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 could be obtained |
DBAccessError | If disable() was previously called |
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 live database handle, suitable for migrations and schema changes, for a 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 | Specific or virtual (DB_PRIMARY/DB_REPLICA) server index |
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) |
DBError | If no live handle could be obtained |
DBAccessError | If disable() was previously called |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by SqlBagOStuff\getConnectionViaLoadBalancer().
Wikimedia\Rdbms\ILoadBalancer::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.
bool | string | $domain | Domain ID or false for the default database |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::getPrimaryPos | ( | ) |
Get the current primary replication position.
DBError |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by SqlBagOStuff\waitForReplication().
Wikimedia\Rdbms\ILoadBalancer::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 | bool | $group | Query group or false for the generic group |
string | bool | $domain | DB domain ID or false for the local domain |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::getReadOnlyReason | ( | $domain = false | ) |
string | bool | $domain | DB domain ID or false for the local domain |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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.
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\ChronologyProtector\stageSessionReplicationPosition().
Wikimedia\Rdbms\ILoadBalancer::getServerAttributes | ( | $i | ) |
Get basic attributes of the server with the specified index without connecting.
int | $i | Specific server index |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::getServerConnection | ( | $i, | |
$domain, | |||
$flags = 0 |
|||
) |
Get a live handle for a specific server index.
This is a simpler version of getConnection() that does not accept virtual server indexes (e.g. DB_PRIMARY/DB_REPLICA), does not assure that primary DB handles have read-only mode when there is high replication lag, and can only trigger attempts to connect to a single server (the one with the specified server index).
int | $i | Specific server index |
string | $domain | Resolved DB domain |
int | $flags | Bitfield of class CONN_* constants |
DBError | If no live handle could be obtained and CONN_SILENCE_ERRORS is not set |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::getServerCount | ( | ) |
Get the number of servers defined in configuration.
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::getServerInfo | ( | $i | ) |
Return the server configuration map for the server with the specified index.
int | $i | Specific server index |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::getServerName | ( | $i | ) |
Get the readable name of the server with the specified index.
int | $i | Specific server index |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\ChronologyProtector\applySessionReplicationPosition(), Wikimedia\Rdbms\LBFactory\logIfMultiDbTransaction(), Wikimedia\Rdbms\LBFactory\shutdownChronologyProtector(), and Wikimedia\Rdbms\ChronologyProtector\stageSessionReplicationPosition().
Wikimedia\Rdbms\ILoadBalancer::getServerType | ( | $i | ) |
Get the RDBMS type of the server with the specified index (e.g.
"mysql", "sqlite")
int | $i | Specific server index |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::getWriterIndex | ( | ) |
Get the specific server index of the primary server.
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\ChronologyProtector\applySessionReplicationPosition(), Wikimedia\Rdbms\LBFactory\logIfMultiDbTransaction(), Wikimedia\Rdbms\LBFactory\shutdownChronologyProtector(), and Wikimedia\Rdbms\ChronologyProtector\stageSessionReplicationPosition().
Wikimedia\Rdbms\ILoadBalancer::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] |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\hasOrMadeRecentPrimaryChanges(), and Wikimedia\Rdbms\ChronologyProtector\stageSessionReplicationPosition().
Wikimedia\Rdbms\ILoadBalancer::hasPrimaryChanges | ( | ) |
Whether there are pending changes or callbacks in a transaction by this thread.
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\hasPrimaryChanges().
Wikimedia\Rdbms\ILoadBalancer::hasPrimaryConnection | ( | ) |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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.
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\appendShutdownCPIndexAsQuery(), and Wikimedia\Rdbms\ChronologyProtector\stageSessionReplicationPosition().
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::lastPrimaryChangeTimestamp | ( | ) |
Get the timestamp of the latest write query done by this thread.
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::pendingPrimaryChangeCallers | ( | ) |
Get the list of callers that have pending primary 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 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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::rollbackPrimaryChanges | ( | $fname = __METHOD__ , |
|
$owner = null |
|||
) |
Issue ROLLBACK only on primary, 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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::runPrimaryTransactionIdleCallbacks | ( | $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) |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\executePostTransactionCallbacks().
Wikimedia\Rdbms\ILoadBalancer::runPrimaryTransactionListenerCallbacks | ( | $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) |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\LBFactory\executePostTransactionCallbacks().
Wikimedia\Rdbms\ILoadBalancer::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) |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by CloneDatabase\changePrefix(), and Wikimedia\Rdbms\LBFactory\initLoadBalancer().
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::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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::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 |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Wikimedia\Rdbms\ILoadBalancer::waitFor | ( | $pos | ) |
Set the primary 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. This is useful for discouraging clients from taking further actions if session consistency could not be maintained with respect to their last actions.
DBPrimaryPos | bool | $pos | Primary position or false |
Implemented in Wikimedia\Rdbms\LoadBalancer.
Referenced by Wikimedia\Rdbms\ChronologyProtector\applySessionReplicationPosition().
Wikimedia\Rdbms\ILoadBalancer::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 | bool | $pos | Primary 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::waitForPrimaryPos | ( | IDatabase | $conn, |
$pos = false , |
|||
$timeout = 10 |
|||
) |
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 | bool | $pos | Primary position; default: current position |
int | $timeout | Timeout in seconds [optional] |
Implemented in Wikimedia\Rdbms\LoadBalancer.
const Wikimedia\Rdbms\ILoadBalancer::CONN_INTENT_WRITABLE = 4 |
Caller is requesting the primary DB server for possibly writes.
Definition at line 108 of file ILoadBalancer.php.
const Wikimedia\Rdbms\ILoadBalancer::CONN_REFRESH_READ_ONLY = 8 |
Bypass and update any server-side read-only mode state cache.
Definition at line 110 of file ILoadBalancer.php.
const Wikimedia\Rdbms\ILoadBalancer::CONN_SILENCE_ERRORS = 2 |
Return null on connection failure instead of throwing an exception.
Definition at line 106 of file ILoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadMonitor\computeServerStates().
const Wikimedia\Rdbms\ILoadBalancer::CONN_TRX_AUTOCOMMIT = 1 |
DB handle should have DBO_TRX disabled and the caller will leave it as such.
Definition at line 104 of file ILoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadMonitor\computeServerStates().
const Wikimedia\Rdbms\ILoadBalancer::DB_MASTER = self::DB_PRIMARY |
Request a primary, write-enabled DB connection.
Definition at line 95 of file ILoadBalancer.php.
const Wikimedia\Rdbms\ILoadBalancer::DB_PRIMARY = -2 |
Request a primary, write-enabled DB connection.
Definition at line 88 of file ILoadBalancer.php.
Referenced by Wikimedia\Rdbms\DBConnRef\getType(), and Wikimedia\Rdbms\DBConnRef\query().
const Wikimedia\Rdbms\ILoadBalancer::DB_REPLICA = -1 |
Request a replica DB connection.
Definition at line 83 of file ILoadBalancer.php.
const Wikimedia\Rdbms\ILoadBalancer::DOMAIN_ANY = '' |
Domain specifier when no specific database needs to be selected.
Definition at line 99 of file ILoadBalancer.php.
Referenced by Wikimedia\Rdbms\LoadMonitor\computeServerStates().
const Wikimedia\Rdbms\ILoadBalancer::GROUP_GENERIC = '' |
The generic query group.
Definition at line 101 of file ILoadBalancer.php.
Referenced by Wikimedia\Rdbms\LBFactoryMulti\__construct(), and Wikimedia\Rdbms\LoadBalancer\__construct().
const Wikimedia\Rdbms\ILoadBalancer::STAGE_POSTCOMMIT_CALLBACKS = 'stage-postcommit-callbacks' |
Manager of ILoadBalancer instances is running post-commit callbacks.
Definition at line 113 of file ILoadBalancer.php.
Referenced by Wikimedia\Rdbms\LBFactory\baseLoadBalancerParams().
const Wikimedia\Rdbms\ILoadBalancer::STAGE_POSTROLLBACK_CALLBACKS = 'stage-postrollback-callbacks' |
Manager of ILoadBalancer instances is running post-rollback callbacks.
Definition at line 115 of file ILoadBalancer.php.
Referenced by Wikimedia\Rdbms\LBFactory\baseLoadBalancerParams().