MediaWiki
1.28.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... | |
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... | |
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 29 of file ILBFactory.php.
ILBFactory::__construct | ( | array | $conf | ) |
Construct a manager of ILoadBalancer objects.
Sub-classes will extend the required keys in $conf with additional parameters
$conf | $params Array with keys:
|
InvalidArgumentException |
Implemented in LBFactoryMulti, LBFactory, LBFactorySimple, and LBFactorySingle.
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 LBFactory.
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 LBFactory.
ILBFactory::closeAll | ( | ) |
Close all open database connections on all open load balancers.
Implemented in LBFactory.
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 LBFactory.
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 LBFactory.
ILBFactory::commitMasterChanges | ( | $fname = __METHOD__ , |
|
array | $options = [] |
||
) |
Commit changes on all master connections.
string | $fname | Caller name |
array | $options | Options map:
|
Exception |
Implemented in LBFactory.
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 LBFactory.
ILBFactory::disableChronologyProtection | ( | ) |
Disable the ChronologyProtector for all load balancers.
This can be called at the start of special API entry points
Implemented in LBFactory.
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 LBFactory.
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 LBFactoryMulti, LBFactorySimple, and LBFactorySingle.
Referenced by LBFactory\appendPreShutdownTimeAsQuery(), LBFactory\commitMasterChanges(), LBFactory\forEachLBCallMethod(), LBFactory\hasMasterChanges(), LBFactory\hasOrMadeRecentMasterChanges(), LBFactory\laggedReplicaUsed(), LBFactory\logIfMultiDbTransaction(), LBFactory\rollbackMasterChanges(), LBFactory\setDomainPrefix(), LBFactory\shutdownChronologyProtector(), and LBFactory\waitForReplication().
ILBFactory::getChronologyProtectorTouched | ( | $dbName | ) |
string | $dbName | DB master name (e.g. "db1052") |
Implemented in LBFactory.
ILBFactory::getEmptyTransactionTicket | ( | $fname | ) |
Get a token asserting that no transaction writes are active.
string | $fname | Caller name (e.g. METHOD) |
Implemented in LBFactory.
ILBFactory::getExternalLB | ( | $cluster | ) |
Get a cached (tracked) load balancer for external storage.
string | $cluster | External storage cluster name |
Implemented in LBFactoryMulti, LBFactory, LBFactorySimple, and LBFactorySingle.
ILBFactory::getMainLB | ( | $domain = false | ) |
Get a cached (tracked) load balancer object.
bool | string | $domain | Domain ID, or false for the current domain |
Implemented in LBFactoryMulti, LBFactory, LBFactorySimple, and LBFactorySingle.
ILBFactory::hasMasterChanges | ( | ) |
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 LBFactory.
ILBFactory::laggedReplicaUsed | ( | ) |
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 LBFactoryMulti, LBFactory, LBFactorySimple, and LBFactorySingle.
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 LBFactoryMulti, LBFactory, LBFactorySimple, and LBFactorySingle.
ILBFactory::rollbackMasterChanges | ( | $fname = __METHOD__ | ) |
Rollback changes on all master connections.
string | $fname | Caller name |
Implemented in LBFactory.
ILBFactory::setAgentName | ( | $agent | ) |
string | $agent | Agent name for query profiling |
Implemented in LBFactory.
ILBFactory::setDomainPrefix | ( | $prefix | ) |
Set a new table prefix for the existing local domain ID for testing.
string | $prefix |
Implemented in LBFactory.
ILBFactory::setRequestInfo | ( | array | $info | ) |
array | $info | Map of fields, including:
|
Implemented in LBFactory.
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 LBFactory.
ILBFactory::shutdown | ( | $mode = self::SHUTDOWN_CHRONPROT_SYNC , |
|
callable | $workCallback = null |
||
) |
Prepare all tracked load balancers for shutdown.
integer | $mode | One of the class SHUTDOWN_* constants |
callable | null | $workCallback | Work to mask ChronologyProtector writes |
Implemented in LBFactory.
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 occured waiting on a DB cluster |
Implemented in LBFactory.
const ILBFactory::SHUTDOWN_CHRONPROT_ASYNC = 1 |
Definition at line 31 of file ILBFactory.php.
const ILBFactory::SHUTDOWN_CHRONPROT_SYNC = 2 |
Definition at line 32 of file ILBFactory.php.
const ILBFactory::SHUTDOWN_NO_CHRONPROT = 0 |
Definition at line 30 of file ILBFactory.php.
Referenced by MediaWiki\restInPeace().