MediaWiki
1.30.0
|
An interface for generating database load balancers. More...
Public Member Functions | |
__construct (array $conf) | |
Construct a manager of ILoadBalancer objects. More... | |
appendPreShutdownTimeAsQuery ( $url, $time) | |
Append ?cpPosTime parameter to a URL for ChronologyProtector purposes if needed. More... | |
beginMasterChanges ( $fname=__METHOD__) | |
Flush any master transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set) More... | |
closeAll () | |
Close all open database connections on all open load balancers. More... | |
commitAll ( $fname=__METHOD__, array $options=[]) | |
Commit open transactions on all connections. More... | |
commitAndWaitForReplication ( $fname, $ticket, array $opts=[]) | |
Convenience method for safely running commitMasterChanges()/waitForReplication() More... | |
commitMasterChanges ( $fname=__METHOD__, array $options=[]) | |
Commit changes on all master connections. More... | |
destroy () | |
Disables all load balancers. More... | |
disableChronologyProtection () | |
Disable the ChronologyProtector for all load balancers. More... | |
flushReplicaSnapshots ( $fname=__METHOD__) | |
Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshot. More... | |
forEachLB ( $callback, array $params=[]) | |
Execute a function for each tracked load balancer The callback is called with the load balancer as the first parameter, and $params passed as the subsequent parameters. More... | |
getAllExternalLBs () | |
Get cached (tracked) load balancers for all external database clusters. More... | |
getAllMainLBs () | |
Get cached (tracked) load balancers for all main database clusters. More... | |
getChronologyProtectorTouched ( $dbName) | |
getEmptyTransactionTicket ( $fname) | |
Get a token asserting that no transaction writes are active. More... | |
getExternalLB ( $cluster) | |
Get a cached (tracked) load balancer for external storage. More... | |
getMainLB ( $domain=false) | |
Get a cached (tracked) load balancer object. More... | |
hasMasterChanges () | |
Determine if any master connection has pending changes. More... | |
hasOrMadeRecentMasterChanges ( $age=null) | |
Determine if any master connection has pending/written changes from this request. More... | |
hasTransactionRound () | |
Check if a transaction round is active. More... | |
laggedReplicaUsed () | |
Detemine if any lagged replica DB connection was used. More... | |
newExternalLB ( $cluster) | |
Create a new load balancer for external storage. More... | |
newMainLB ( $domain=false) | |
Create a new load balancer object. More... | |
rollbackMasterChanges ( $fname=__METHOD__) | |
Rollback changes on all master connections. More... | |
setAgentName ( $agent) | |
setDomainPrefix ( $prefix) | |
Set a new table prefix for the existing local domain ID for testing. More... | |
setRequestInfo (array $info) | |
setWaitForReplicationListener ( $name, callable $callback=null) | |
Add a callback to be run in every call to waitForReplication() before waiting. More... | |
shutdown ( $mode=self::SHUTDOWN_CHRONPROT_SYNC, callable $workCallback=null) | |
Prepare all tracked load balancers for shutdown. More... | |
waitForReplication (array $opts=[]) | |
Waits for the replica DBs to catch up to the current master position. More... | |
Public Attributes | |
const | SHUTDOWN_CHRONPROT_ASYNC = 1 |
const | SHUTDOWN_CHRONPROT_SYNC = 2 |
const | SHUTDOWN_NO_CHRONPROT = 0 |
An interface for generating database load balancers.
Definition at line 33 of file ILBFactory.php.
Wikimedia\Rdbms\ILBFactory::__construct | ( | array | $conf | ) |
Construct a manager of ILoadBalancer objects.
Sub-classes will extend the required keys in $conf with additional parameters
array | $conf | Array with keys:
|
InvalidArgumentException |
Implemented in Wikimedia\Rdbms\LBFactoryMulti, Wikimedia\Rdbms\LBFactory, Wikimedia\Rdbms\LBFactorySimple, and Wikimedia\Rdbms\LBFactorySingle.
Wikimedia\Rdbms\ILBFactory::appendPreShutdownTimeAsQuery | ( | $url, | |
$time | |||
) |
Append ?cpPosTime parameter to a URL for ChronologyProtector purposes if needed.
Note that unlike cookies, this works accross domains
string | $url | |
float | $time | UNIX timestamp just before shutdown() was called |
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::beginMasterChanges | ( | $fname = __METHOD__ | ) |
Flush any master transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set)
The DBO_TRX setting will be reverted to the default in each of these methods:
This allows for custom transaction rounds from any outer transaction scope.
string | $fname |
DBTransactionError |
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::closeAll | ( | ) |
Close all open database connections on all open load balancers.
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::commitAll | ( | $fname = __METHOD__ , |
|
array | $options = [] |
||
) |
Commit open transactions on all connections.
This is useful for two main cases:
string | $fname | Caller name |
array | $options | Options map: |
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::commitAndWaitForReplication | ( | $fname, | |
$ticket, | |||
array | $opts = [] |
||
) |
Convenience method for safely running commitMasterChanges()/waitForReplication()
This will commit and wait unless $ticket indicates it is unsafe to do so
string | $fname | Caller name (e.g. METHOD) |
mixed | $ticket | Result of getEmptyTransactionTicket() |
array | $opts | Options to waitForReplication() |
DBReplicationWaitError |
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::commitMasterChanges | ( | $fname = __METHOD__ , |
|
array | $options = [] |
||
) |
Commit changes on all master connections.
string | $fname | Caller name |
array | $options | Options map:
|
DBTransactionError |
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::destroy | ( | ) |
Disables all load balancers.
All connections are closed, and any attempt to open a new connection will result in a DBAccessError.
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::disableChronologyProtection | ( | ) |
Disable the ChronologyProtector for all load balancers.
This can be called at the start of special API entry points
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::flushReplicaSnapshots | ( | $fname = __METHOD__ | ) |
Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshot.
string | $fname | Caller name |
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::forEachLB | ( | $callback, | |
array | $params = [] |
||
) |
Execute a function for each tracked load balancer The callback is called with the load balancer as the first parameter, and $params passed as the subsequent parameters.
callable | $callback | |
array | $params |
Implemented in Wikimedia\Rdbms\LBFactoryMulti, Wikimedia\Rdbms\LBFactorySimple, and Wikimedia\Rdbms\LBFactorySingle.
Referenced by Wikimedia\Rdbms\LBFactory\appendPreShutdownTimeAsQuery(), Wikimedia\Rdbms\LBFactory\commitMasterChanges(), Wikimedia\Rdbms\LBFactory\forEachLBCallMethod(), Wikimedia\Rdbms\LBFactory\hasMasterChanges(), Wikimedia\Rdbms\LBFactory\hasOrMadeRecentMasterChanges(), Wikimedia\Rdbms\LBFactory\laggedReplicaUsed(), Wikimedia\Rdbms\LBFactory\logIfMultiDbTransaction(), Wikimedia\Rdbms\LBFactory\rollbackMasterChanges(), Wikimedia\Rdbms\LBFactory\setDomainPrefix(), Wikimedia\Rdbms\LBFactory\shutdownChronologyProtector(), and Wikimedia\Rdbms\LBFactory\waitForReplication().
Wikimedia\Rdbms\ILBFactory::getAllExternalLBs | ( | ) |
Get cached (tracked) load balancers for all external database clusters.
Implemented in Wikimedia\Rdbms\LBFactoryMulti, Wikimedia\Rdbms\LBFactorySimple, and Wikimedia\Rdbms\LBFactorySingle.
Wikimedia\Rdbms\ILBFactory::getAllMainLBs | ( | ) |
Get cached (tracked) load balancers for all main database clusters.
Implemented in Wikimedia\Rdbms\LBFactoryMulti, Wikimedia\Rdbms\LBFactorySimple, and Wikimedia\Rdbms\LBFactorySingle.
Wikimedia\Rdbms\ILBFactory::getChronologyProtectorTouched | ( | $dbName | ) |
string | $dbName | DB master name (e.g. "db1052") |
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::getEmptyTransactionTicket | ( | $fname | ) |
Get a token asserting that no transaction writes are active.
string | $fname | Caller name (e.g. METHOD) |
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::getExternalLB | ( | $cluster | ) |
Get a cached (tracked) load balancer for external storage.
string | $cluster | External storage cluster name |
Implemented in Wikimedia\Rdbms\LBFactoryMulti, Wikimedia\Rdbms\LBFactory, Wikimedia\Rdbms\LBFactorySimple, and Wikimedia\Rdbms\LBFactorySingle.
Wikimedia\Rdbms\ILBFactory::getMainLB | ( | $domain = false | ) |
Get a cached (tracked) load balancer object.
bool | string | $domain | Domain ID, or false for the current domain |
Implemented in Wikimedia\Rdbms\LBFactoryMulti, Wikimedia\Rdbms\LBFactory, Wikimedia\Rdbms\LBFactorySimple, and Wikimedia\Rdbms\LBFactorySingle.
Wikimedia\Rdbms\ILBFactory::hasMasterChanges | ( | ) |
Determine if any master connection has pending changes.
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::hasOrMadeRecentMasterChanges | ( | $age = null | ) |
Determine if any master connection has pending/written changes from this request.
float | $age | How many seconds ago is "recent" [defaults to LB lag wait timeout] |
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::hasTransactionRound | ( | ) |
Check if a transaction round is active.
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::laggedReplicaUsed | ( | ) |
Detemine if any lagged replica DB connection was used.
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::newExternalLB | ( | $cluster | ) |
Create a new load balancer for external storage.
The resulting object will be untracked, not chronology-protected, and the caller is responsible for cleaning it up.
This method is for only advanced usage and callers should almost always use getExternalLB() instead. This method can be useful when a table is used as a key/value store. In that cases, one might want to query it in autocommit mode (DBO_TRX off) but still use DBO_TRX transaction rounds on other tables.
string | $cluster | External storage cluster name |
Implemented in Wikimedia\Rdbms\LBFactoryMulti, Wikimedia\Rdbms\LBFactory, Wikimedia\Rdbms\LBFactorySimple, and Wikimedia\Rdbms\LBFactorySingle.
Wikimedia\Rdbms\ILBFactory::newMainLB | ( | $domain = false | ) |
Create a new load balancer object.
The resulting object will be untracked, not chronology-protected, and the caller is responsible for cleaning it up.
This method is for only advanced usage and callers should almost always use getMainLB() instead. This method can be useful when a table is used as a key/value store. In that cases, one might want to query it in autocommit mode (DBO_TRX off) but still use DBO_TRX transaction rounds on other tables.
bool | string | $domain | Domain ID, or false for the current domain |
Implemented in Wikimedia\Rdbms\LBFactoryMulti, Wikimedia\Rdbms\LBFactory, Wikimedia\Rdbms\LBFactorySimple, and Wikimedia\Rdbms\LBFactorySingle.
Wikimedia\Rdbms\ILBFactory::rollbackMasterChanges | ( | $fname = __METHOD__ | ) |
Rollback changes on all master connections.
string | $fname | Caller name |
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::setAgentName | ( | $agent | ) |
string | $agent | Agent name for query profiling |
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::setDomainPrefix | ( | $prefix | ) |
Set a new table prefix for the existing local domain ID for testing.
string | $prefix |
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::setRequestInfo | ( | array | $info | ) |
array | $info | Map of fields, including:
|
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::setWaitForReplicationListener | ( | $name, | |
callable | $callback = null |
||
) |
Add a callback to be run in every call to waitForReplication() before waiting.
Callbacks must clear any transactions that they start
string | $name | Callback name |
callable | null | $callback | Use null to unset a callback |
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::shutdown | ( | $mode = self::SHUTDOWN_CHRONPROT_SYNC , |
|
callable | $workCallback = null |
||
) |
Prepare all tracked load balancers for shutdown.
int | $mode | One of the class SHUTDOWN_* constants |
callable | null | $workCallback | Work to mask ChronologyProtector writes |
Implemented in Wikimedia\Rdbms\LBFactory.
Wikimedia\Rdbms\ILBFactory::waitForReplication | ( | array | $opts = [] | ) |
Waits for the replica DBs to catch up to the current master position.
Use this when updating very large numbers of rows, as in maintenance scripts, to avoid causing too much lag. Of course, this is a no-op if there are no replica DBs.
By default this waits on all DB clusters actually used in this request. This makes sense when lag being waiting on is caused by the code that does this check. In that case, setting "ifWritesSince" can avoid the overhead of waiting for clusters that were not changed since the last wait check. To forcefully wait on a specific cluster for a given domain, use the 'domain' parameter. To forcefully wait on an "external" cluster, use the "cluster" parameter.
Never call this function after a large DB write that is still in a transaction. It only makes sense to call this after the possible lag inducing changes were committed.
array | $opts | Optional fields that include:
|
DBReplicationWaitError | If a timeout or error occurred waiting on a DB cluster |
Implemented in Wikimedia\Rdbms\LBFactory.
const Wikimedia\Rdbms\ILBFactory::SHUTDOWN_CHRONPROT_ASYNC = 1 |
Definition at line 35 of file ILBFactory.php.
const Wikimedia\Rdbms\ILBFactory::SHUTDOWN_CHRONPROT_SYNC = 2 |
Definition at line 36 of file ILBFactory.php.
const Wikimedia\Rdbms\ILBFactory::SHUTDOWN_NO_CHRONPROT = 0 |
Definition at line 34 of file ILBFactory.php.
Referenced by MediaWiki\restInPeace().