MediaWiki
master
|
An interface for generating database load balancers. More...
Public Member Functions | |
__construct (array $conf) | |
Construct a factory based on a configuration array (typically from $wgLBFactoryConf) More... | |
closeAll () | |
Close all open database connections on all open load balancers. More... | |
commitAll ($fname=__METHOD__, array $options=[]) | |
Commit on all connections. 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... | |
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... | |
& | getExternalLB ($cluster, $wiki=false) |
Get a cached (tracked) load balancer for external storage. More... | |
getMainLB ($wiki=false) | |
Get a cached (tracked) load balancer object. More... | |
hasMasterChanges () | |
Determine if any master connection has pending changes. More... | |
hasOrMadeRecentMasterChanges () | |
Determine if any master connection has pending/written changes from this request. More... | |
laggedSlaveUsed () | |
Detemine if any lagged slave connection was used. More... | |
newMainLB ($wiki=false) | |
Create a new load balancer object. More... | |
rollbackMasterChanges ($fname=__METHOD__) | |
Rollback changes on all master connections. More... | |
shutdown ($flags=0) | |
Prepare all tracked load balancers for shutdown. More... | |
waitForReplication (array $opts=[]) | |
Waits for the slave DBs to catch up to the current master position. More... | |
Static Public Member Functions | |
static | destroyInstance () |
Shut down, close connections and destroy the cached instance. More... | |
static | disableBackend () |
Disables all access to the load balancer, will cause all database access to throw a DBAccessError. More... | |
static | getLBFactoryClass (array $config) |
Returns the LBFactory class to use and the load balancer configuration. More... | |
static | singleton () |
Get an LBFactory instance. More... | |
Public Attributes | |
const | SHUTDOWN_NO_CHRONPROT = 1 |
Protected Member Functions | |
newChronologyProtector () | |
newExternalLB ($cluster, $wiki=false) | |
Create a new load balancer for external storage. More... | |
shutdownChronologyProtector (ChronologyProtector $cp) | |
Protected Attributes | |
ChronologyProtector | $chronProt |
LoggerInterface | $logger |
string bool | $readOnlyReason = false |
Reason all LBs are read-only or false if not. More... | |
TransactionProfiler | $trxProfiler |
Private Member Functions | |
forEachLBCallMethod ($methodName, array $args=[]) | |
Call a method of each tracked load balancer. More... | |
logIfMultiDbTransaction () | |
Log query info if multi DB transactions are going to be committed now. More... | |
An interface for generating database load balancers.
Definition at line 33 of file LBFactory.php.
LBFactory::__construct | ( | array | $conf | ) |
Construct a factory based on a configuration array (typically from $wgLBFactoryConf)
array | $conf |
Definition at line 53 of file LBFactory.php.
References Profiler\instance(), and newChronologyProtector().
LBFactory::closeAll | ( | ) |
Close all open database connections on all open load balancers.
Definition at line 453 of file LBFactory.php.
References forEachLBCallMethod().
LBFactory::commitAll | ( | $fname = __METHOD__ , |
|
array | $options = [] |
||
) |
Commit on all connections.
Done for two reasons:
string | $fname | Caller name |
array | $options | Options map:
|
Definition at line 210 of file LBFactory.php.
References $fname, $options, commitMasterChanges(), and forEachLBCallMethod().
LBFactory::commitMasterChanges | ( | $fname = __METHOD__ , |
|
array | $options = [] |
||
) |
Commit changes on all master connections.
string | $fname | Caller name |
array | $options | Options map:
|
Definition at line 221 of file LBFactory.php.
References $fname, $options, forEachLBCallMethod(), and logIfMultiDbTransaction().
Referenced by commitAll(), LBFactorySimple\shutdown(), and LBFactoryMulti\shutdown().
LBFactory::destroy | ( | ) |
Disables all load balancers.
All connections are closed, and any attempt to open a new connection will result in a DBAccessError.
Implements MediaWiki\Services\DestructibleService.
Definition at line 68 of file LBFactory.php.
References forEachLBCallMethod(), and shutdown().
|
static |
Shut down, close connections and destroy the cached instance.
Definition at line 128 of file LBFactory.php.
Referenced by Maintenance\finalSetup().
|
static |
Disables all access to the load balancer, will cause all database access to throw a DBAccessError.
Definition at line 77 of file LBFactory.php.
LBFactory::disableChronologyProtection | ( | ) |
Disable the ChronologyProtector for all load balancers.
This can be called at the start of special API entry points
Definition at line 400 of file LBFactory.php.
|
abstract |
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 |
Referenced by forEachLBCallMethod(), hasMasterChanges(), hasOrMadeRecentMasterChanges(), laggedSlaveUsed(), logIfMultiDbTransaction(), shutdownChronologyProtector(), and waitForReplication().
|
private |
Call a method of each tracked load balancer.
string | $methodName | |
array | $args |
Definition at line 193 of file LBFactory.php.
References $args, array(), and forEachLB().
Referenced by closeAll(), commitAll(), commitMasterChanges(), destroy(), and rollbackMasterChanges().
|
abstract |
Get a cached (tracked) load balancer for external storage.
string | $cluster | External storage cluster, or false for core |
bool | string | $wiki | Wiki ID, or false for the current wiki |
Referenced by waitForReplication().
|
static |
Returns the LBFactory class to use and the load balancer configuration.
array | $config | (e.g. $wgLBFactoryConf) |
Definition at line 100 of file LBFactory.php.
References wfDeprecated().
Referenced by LBFactoryTest\testGetLBFactoryClass().
|
abstract |
Get a cached (tracked) load balancer object.
bool | string | $wiki | Wiki ID, or false for the current wiki |
Referenced by waitForReplication().
LBFactory::hasMasterChanges | ( | ) |
Determine if any master connection has pending changes.
Definition at line 273 of file LBFactory.php.
References $ret, forEachLB(), LoadBalancer\hasMasterChanges(), and use.
LBFactory::hasOrMadeRecentMasterChanges | ( | ) |
Determine if any master connection has pending/written changes from this request.
Definition at line 301 of file LBFactory.php.
References $ret, forEachLB(), LoadBalancer\hasOrMadeRecentMasterChanges(), and use.
LBFactory::laggedSlaveUsed | ( | ) |
Detemine if any lagged slave connection was used.
Definition at line 287 of file LBFactory.php.
References $ret, forEachLB(), LoadBalancer\laggedSlaveUsed(), and use.
|
private |
Log query info if multi DB transactions are going to be committed now.
Definition at line 248 of file LBFactory.php.
References as, forEachLB(), LoadBalancer\getServerName(), LoadBalancer\getWriterIndex(), LoadBalancer\pendingMasterChangeCallers(), and use.
Referenced by commitMasterChanges().
|
protected |
Definition at line 407 of file LBFactory.php.
References $chronProt, $request, RequestContext\getMain(), ObjectCache\getMainStashInstance(), ChronologyProtector\setEnabled(), and ChronologyProtector\setWaitEnabled().
Referenced by __construct().
|
abstractprotected |
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.
string | $cluster | External storage cluster, or false for core |
bool | string | $wiki | Wiki ID, or false for the current wiki |
|
abstract |
Create a new load balancer object.
The resulting object will be untracked, not chronology-protected, and the caller is responsible for cleaning it up.
bool | string | $wiki | Wiki ID, or false for the current wiki |
LBFactory::rollbackMasterChanges | ( | $fname = __METHOD__ | ) |
Rollback changes on all master connections.
string | $fname | Caller name |
Definition at line 241 of file LBFactory.php.
References $fname, and forEachLBCallMethod().
LBFactory::shutdown | ( | $flags = 0 | ) |
Prepare all tracked load balancers for shutdown.
integer | $flags | Supports SHUTDOWN_* flags STUB |
Definition at line 184 of file LBFactory.php.
Referenced by destroy().
|
protected |
ChronologyProtector | $cp |
Definition at line 430 of file LBFactory.php.
References forEachLB(), LoadBalancer\getServerName(), LoadBalancer\getWriterIndex(), ChronologyProtector\shutdown(), ChronologyProtector\shutdownLB(), use, and LoadBalancer\waitForAll().
Referenced by LBFactorySimple\shutdown(), and LBFactoryMulti\shutdown().
|
static |
Get an LBFactory instance.
Definition at line 88 of file LBFactory.php.
LBFactory::waitForReplication | ( | array | $opts = [] | ) |
Waits for the slave 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 slaves.
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 wiki, use the 'wiki' 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 |
Definition at line 333 of file LBFactory.php.
References as, forEachLB(), getExternalLB(), getMainLB(), and use.
|
protected |
Definition at line 36 of file LBFactory.php.
Referenced by newChronologyProtector().
|
protected |
Definition at line 42 of file LBFactory.php.
Reason all LBs are read-only or false if not.
Definition at line 45 of file LBFactory.php.
Referenced by LBFactoryMulti\newLoadBalancer(), and LBFactoryMulti\newMainLB().
|
protected |
Definition at line 39 of file LBFactory.php.
const LBFactory::SHUTDOWN_NO_CHRONPROT = 1 |
Definition at line 47 of file LBFactory.php.
Referenced by MediaWiki\restInPeace().