|
MediaWiki master
|
Inherits Wikimedia\Rdbms\ILoadBalancerForOwner.
Inherited by Wikimedia\Rdbms\LoadBalancerDisabled, and Wikimedia\Rdbms\LoadBalancerSingle.

Public Member Functions | |||||||||||||
| __construct (array $params) | |||||||||||||
| approvePrimaryChanges (int $maxWriteDuration, $fname=__METHOD__) | |||||||||||||
Perform all pre-commit checks for things like replication safety.Use this only for multi-database commits
| |||||||||||||
| 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:
| |||||||||||||
| closeAll ( $fname=__METHOD__) | |||||||||||||
Close 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.Any attempt to open a new connection will result in a DBAccessError.
| |||||||||||||
| 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.Use this only for multi-database commits
| |||||||||||||
| flushPrimarySessions ( $fname=__METHOD__) | |||||||||||||
Release/destroy session-level named locks, table locks, and temp tables.Only call this function right after calling rollbackPrimaryChanges()
| |||||||||||||
| 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
| |||||||||||||
| flushReplicaSnapshots ( $fname=__METHOD__) | |||||||||||||
Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
| |||||||||||||
| getAnyOpenConnection ( $i, $flags=0) | |||||||||||||
| getClusterName () | |||||||||||||
| Get the name of the overall cluster of database servers managing the dataset. | |||||||||||||
| getConnection ( $i, $groups=[], string|false $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:
| |||||||||||||
| getConnectionInternal ( $i, $groups=[], $domain=false, $flags=0) | |||||||||||||
| |||||||||||||
| getLagTimes () | |||||||||||||
Get an estimate of replication lag (in seconds) for each server.Results are cached for a short time in memcached/process cacheValues may be "false" if replication is too broken to estimate
| |||||||||||||
| 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.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.
| |||||||||||||
| getMaxLag () | |||||||||||||
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.
| |||||||||||||
| getPrimaryPos () | |||||||||||||
Get the current primary replication position.
| |||||||||||||
| getReaderIndex ( $group=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.
| |||||||||||||
| getReadOnlyReason () | |||||||||||||
| |||||||||||||
| 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.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:
| |||||||||||||
| 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."mysql", "sqlite")
| |||||||||||||
| 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.This scans the list of servers defined in configuration, checking for:
| |||||||||||||
| hasStreamingReplicaServers () | |||||||||||||
Whether any replica servers use streaming replication from the primary server.This scans the list of servers defined in configuration, checking for:
| |||||||||||||
| laggedReplicaUsed () | |||||||||||||
Whether a highly "lagged" replica database connection was queried.
| |||||||||||||
| lastPrimaryChangeTimestamp () | |||||||||||||
Get the last time that a tracked connection was used to commit a write.
| |||||||||||||
| 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 (DatabaseDomain|string|false $domain) | |||||||||||||
| |||||||||||||
| 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.
| |||||||||||||
| setDefaultGroupName (string $defaultGroup) | |||||||||||||
| Set the default group name for all load balancers. | |||||||||||||
| setDomainAliases (array $aliases) | |||||||||||||
| Convert certain database domains to alternative ones. | |||||||||||||
| setLocalDomainPrefix ( $prefix) | |||||||||||||
Set a new table prefix for the existing local domain ID for testing.
| |||||||||||||
| setMockTime (&$time) | |||||||||||||
| 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.In "temporary tables mode", the CONN_TRX_AUTOCOMMIT flag is ignored
| |||||||||||||
| setTransactionListener ( $name, ?callable $callback=null) | |||||||||||||
Set a callback via IDatabase::setTransactionListener() on all current and future primary connections of this load balancer.
| |||||||||||||
| waitForAll (DBPrimaryPos $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 laggedReplicaUsed().
| |||||||||||||
| waitForPrimaryPos (IDatabase $conn) | |||||||||||||
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.
| |||||||||||||
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 for DB_REPLICA connections for the given query group. | |
| reallyOpenConnection ( $i, DatabaseDomain $domain, array $lbInfo) | |
| Open a new network connection to a server (uncached). | |
| resolveDomainInstance (DatabaseDomain|string|false $domain) | |
| sanitizeConnectionFlags ( $flags, $domain) | |
| Sanitize connection flags provided by a call to getConnection(). | |
Additional Inherited Members | |
| 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_SILENCE_ERRORS = 4 |
| Yield null on connection failure instead of throwing an exception. | |
| const | CONN_TRX_AUTOCOMMIT = 1 |
| Yield a tracked autocommit-mode handle (reuse existing ones). | |
| const | CONN_UNTRACKED_GAUGE = 2 |
| Yield an untracked, low-timeout, autocommit-mode handle (to gauge server health). | |
| 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. | |
Definition at line 27 of file LoadBalancer.php.
| Wikimedia\Rdbms\LoadBalancer::__construct | ( | array | $params | ) |
| array | $params | Parameter map with keys:
|
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Reimplemented in Wikimedia\Rdbms\LoadBalancerDisabled, and Wikimedia\Rdbms\LoadBalancerSingle.
Definition at line 140 of file LoadBalancer.php.
References configure().
| Wikimedia\Rdbms\LoadBalancer::approvePrimaryChanges | ( | int | $maxWriteDuration, |
| $fname = __METHOD__ ) |
Perform all pre-commit checks for things like replication safety.Use this only for multi-database commits
| int | $maxWriteDuration | : max write query duration time in seconds |
| string | $fname | Caller name |
| DBTransactionError |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 1366 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 1421 of file LoadBalancer.php.
References flushPrimarySnapshots().
| Wikimedia\Rdbms\LoadBalancer::closeAll | ( | $fname = __METHOD__ | ) |
Close all open connections.
| string | $fname | Caller name |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 1284 of file LoadBalancer.php.
Referenced by disable(), and redefineLocalDomain().
| 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 1448 of file LoadBalancer.php.
|
protected |
| array | $params | A database configuration array, see $wgLBFactoryConf. |
Definition at line 151 of file LoadBalancer.php.
Referenced by __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 1278 of file LoadBalancer.php.
References closeAll().
| Wikimedia\Rdbms\LoadBalancer::explicitTrxActive | ( | ) |
Determine whether an explicit transaction is active on any open primary connection.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1740 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 1339 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 1592 of file LoadBalancer.php.
References hasPrimaryChanges().
| 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 1689 of file LoadBalancer.php.
Referenced by beginPrimaryChanges().
| 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 1675 of file LoadBalancer.php.
References Wikimedia\Rdbms\ServerInfo\WRITER_INDEX.
| Wikimedia\Rdbms\LoadBalancer::getAnyOpenConnection | ( | $i, | |
| $flags = 0 ) |
| int | $i | |
| int | $flags |
Definition at line 619 of file LoadBalancer.php.
References Wikimedia\Rdbms\ServerInfo\WRITER_INDEX.
Referenced by getPrimaryPos(), hasPrimaryConnection(), and waitForPrimaryPos().
| Wikimedia\Rdbms\LoadBalancer::getClusterName | ( | ) |
Get the name of the overall cluster of database servers managing the dataset.
Note that the cluster might contain servers in multiple datacenters. The load balancer instance only needs to be aware of the local replica servers, along with either the sole-primary server or the local co-primary server.
This is useful for identifying a cluster or replicated dataset, even when:
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 234 of file LoadBalancer.php.
References return.
Referenced by runPrimaryTransactionIdleCallbacks().
| Wikimedia\Rdbms\LoadBalancer::getConnection | ( | $i, | |
| $groups = [], | |||
| string|false | $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:
| 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.
Reimplemented in Wikimedia\Rdbms\LoadBalancerDisabled.
Definition at line 755 of file LoadBalancer.php.
References resolveDomainID(), and Wikimedia\Rdbms\ServerInfo\WRITER_INDEX.
| 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.
Reimplemented in Wikimedia\Rdbms\LoadBalancerDisabled.
Definition at line 771 of file LoadBalancer.php.
References resolveDomainID(), sanitizeConnectionFlags(), and Wikimedia\Rdbms\ServerInfo\WRITER_INDEX.
Referenced by getPrimaryPos().
|
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 2027 of file LoadBalancer.php.
References Wikimedia\Rdbms\IReadableDatabase\getDomainID(), and Wikimedia\Rdbms\IReadableDatabase\getServerName().
Referenced by reallyOpenConnection(), runPrimaryTransactionIdleCallbacks(), and waitForPrimaryPos().
|
protected |
Get the server index chosen for DB_REPLICA connections for the given query group.
| string | $group | Query group; use false for the generic group |
Definition at line 498 of file LoadBalancer.php.
Referenced by getReaderIndex().
| Wikimedia\Rdbms\LoadBalancer::getLagTimes | ( | ) |
Get an estimate of replication lag (in seconds) for each server.Results are cached for a short time in memcached/process cacheValues may be "false" if replication is too broken to estimate
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1873 of file LoadBalancer.php.
References getServerConnection(), hasReplicaServers(), and Wikimedia\Rdbms\ServerInfo\WRITER_INDEX.
Referenced by getMaxLag().
| Wikimedia\Rdbms\LoadBalancer::getLocalDomainID | ( | ) |
Get the local (and default) database domain ID of connection handles.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 238 of file LoadBalancer.php.
References return.
| 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.
Reimplemented in Wikimedia\Rdbms\LoadBalancerDisabled.
Definition at line 837 of file LoadBalancer.php.
References Wikimedia\Rdbms\ILoadBalancer\CONN_SILENCE_ERRORS, and if.
| Wikimedia\Rdbms\LoadBalancer::getMaxLag | ( | ) |
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.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1851 of file LoadBalancer.php.
References getLagTimes().
| Wikimedia\Rdbms\LoadBalancer::getPrimaryPos | ( | ) |
Get the current primary replication position.
| DBError |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1200 of file LoadBalancer.php.
References getAnyOpenConnection(), getConnectionInternal(), and Wikimedia\Rdbms\ServerInfo\WRITER_INDEX.
| Wikimedia\Rdbms\LoadBalancer::getReaderIndex | ( | $group = 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 | string[] | $group | Query group or false for the generic group |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 409 of file LoadBalancer.php.
References getExistingReaderIndex(), getServerName(), and Wikimedia\Rdbms\ServerInfo\WRITER_INDEX.
| Wikimedia\Rdbms\LoadBalancer::getReadOnlyReason | ( | ) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1760 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 971 of file LoadBalancer.php.
References getServerType().
Referenced by reallyOpenConnection(), and sanitizeConnectionFlags().
| 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 798 of file LoadBalancer.php.
References Wikimedia\Rdbms\DatabaseDomain\newFromId(), and Wikimedia\Rdbms\ServerInfo\WRITER_INDEX.
Referenced by getLagTimes(), and waitForPrimaryPos().
| Wikimedia\Rdbms\LoadBalancer::getServerCount | ( | ) |
Get the number of servers defined in configuration.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1170 of file LoadBalancer.php.
Referenced by waitForAll().
| 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 1190 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 1185 of file LoadBalancer.php.
References getServerName(), and return.
Referenced by getReaderIndex(), getServerName(), and waitForAll().
| 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 1195 of file LoadBalancer.php.
Referenced by getServerAttributes().
| 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 1722 of file LoadBalancer.php.
References hasPrimaryChanges(), and lastPrimaryChangeTimestamp().
| Wikimedia\Rdbms\LoadBalancer::hasPrimaryChanges | ( | ) |
Whether there are pending changes or callbacks in a transaction by this thread.
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1701 of file LoadBalancer.php.
Referenced by flushPrimarySessions(), and hasOrMadeRecentPrimaryChanges().
| Wikimedia\Rdbms\LoadBalancer::hasPrimaryConnection | ( | ) |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 1696 of file LoadBalancer.php.
References getAnyOpenConnection(), and Wikimedia\Rdbms\ServerInfo\WRITER_INDEX.
| Wikimedia\Rdbms\LoadBalancer::hasReplicaServers | ( | ) |
Whether there are any replica servers configured.This scans the list of servers defined in configuration, checking for:
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1175 of file LoadBalancer.php.
Referenced by getLagTimes().
| Wikimedia\Rdbms\LoadBalancer::hasStreamingReplicaServers | ( | ) |
Whether any replica servers use streaming replication from the primary server.This scans the list of servers defined in configuration, checking for:
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1180 of file LoadBalancer.php.
| Wikimedia\Rdbms\LoadBalancer::laggedReplicaUsed | ( | ) |
Whether a highly "lagged" replica database connection was queried.
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 1755 of file LoadBalancer.php.
| Wikimedia\Rdbms\LoadBalancer::lastPrimaryChangeTimestamp | ( | ) |
Get the last time that a tracked connection was used to commit a write.
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 1712 of file LoadBalancer.php.
Referenced by hasOrMadeRecentPrimaryChanges().
| Wikimedia\Rdbms\LoadBalancer::pendingPrimaryChangeCallers | ( | ) |
Get the list of callers that have pending primary changes.
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 1730 of file LoadBalancer.php.
| Wikimedia\Rdbms\LoadBalancer::pingAll | ( | ) |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1812 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\LoadBalancerDisabled, and Wikimedia\Rdbms\LoadBalancerSingle.
Definition at line 990 of file LoadBalancer.php.
References DBO_DEFAULT, Wikimedia\Rdbms\Database\IDatabaseFlags\DBO_DEFAULT, Wikimedia\Rdbms\Database\IDatabaseFlags\DBO_GAUGE, getConnLogContext(), Wikimedia\Rdbms\DatabaseDomain\getDatabase(), Wikimedia\Rdbms\DatabaseDomain\getId(), Wikimedia\Rdbms\DatabaseDomain\getSchema(), getServerAttributes(), Wikimedia\Rdbms\DatabaseDomain\getTablePrefix(), Wikimedia\Rdbms\IDatabase\ROLE_STATIC_CLONE, Wikimedia\Rdbms\IDatabase\ROLE_STREAMING_MASTER, Wikimedia\Rdbms\IDatabase\ROLE_STREAMING_REPLICA, and Wikimedia\Rdbms\ServerInfo\WRITER_INDEX.
| Wikimedia\Rdbms\LoadBalancer::reconfigure | ( | array | $params | ) |
Apply updated configuration.
This only unregisters servers that were removed in the new configuration. It does not register new servers nor update the group load weights.
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 1243 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\ILoadBalancerForOwner.
Definition at line 1985 of file LoadBalancer.php.
References closeAll(), and Wikimedia\Rdbms\DatabaseDomain\newFromId().
| Wikimedia\Rdbms\LoadBalancer::resolveDomainID | ( | DatabaseDomain|string|false | $domain | ) |
| DatabaseDomain | string | false | $domain | Database domain |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 243 of file LoadBalancer.php.
References resolveDomainInstance(), and return.
Referenced by getConnection(), and getConnectionInternal().
|
finalprotected |
| 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 1575 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 1481 of file LoadBalancer.php.
References getClusterName(), getConnLogContext(), Wikimedia\Rdbms\IDatabase\TRIGGER_COMMIT, and Wikimedia\Rdbms\IDatabase\TRIGGER_ROLLBACK.
| 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 1550 of file LoadBalancer.php.
References Wikimedia\Rdbms\IDatabase\TRIGGER_COMMIT, and Wikimedia\Rdbms\IDatabase\TRIGGER_ROLLBACK.
|
protected |
Sanitize connection flags provided by a call to getConnection().
| int | $flags | Bitfield of class CONN_* constants |
| string | $domain | Database domain |
Reimplemented in Wikimedia\Rdbms\LoadBalancerSingle.
Definition at line 275 of file LoadBalancer.php.
References Wikimedia\Rdbms\ILoadBalancer\CONN_TRX_AUTOCOMMIT, getServerAttributes(), and Wikimedia\Rdbms\ServerInfo\WRITER_INDEX.
Referenced by getConnectionInternal().
| Wikimedia\Rdbms\LoadBalancer::setDefaultGroupName | ( | string | $defaultGroup | ) |
Set the default group name for all load balancers.
| string | $defaultGroup |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 2047 of file LoadBalancer.php.
| 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 1962 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 1967 of file LoadBalancer.php.
| Wikimedia\Rdbms\LoadBalancer::setMockTime | ( | & | $time | ) |
| float | null | &$time | Mock UNIX timestamp for testing |
Definition at line 2039 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 1958 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 CONN_TRX_AUTOCOMMIT flag is ignored
| bool | $value | |
| string | $domain |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1991 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 1947 of file LoadBalancer.php.
| Wikimedia\Rdbms\LoadBalancer::waitForAll | ( | DBPrimaryPos | $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 laggedReplicaUsed().
| DBPrimaryPos | $pos | Primary position |
| int | null | $timeout | Max seconds to wait; default is mWaitTimeout |
Implements Wikimedia\Rdbms\ILoadBalancerForOwner.
Definition at line 573 of file LoadBalancer.php.
References Wikimedia\Rdbms\DBPrimaryPos\__toString(), getServerCount(), and getServerName().
| Wikimedia\Rdbms\LoadBalancer::waitForPrimaryPos | ( | IDatabase | $conn | ) |
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 |
Implements Wikimedia\Rdbms\ILoadBalancer.
Definition at line 1904 of file LoadBalancer.php.
References getAnyOpenConnection(), getConnLogContext(), Wikimedia\Rdbms\IDatabase\getLBInfo(), getServerConnection(), and Wikimedia\Rdbms\ServerInfo\WRITER_INDEX.