MediaWiki  1.27.2
LBFactoryMulti Class Reference

A multi-wiki, multi-master factory for Wikimedia and similar installations. More...

Inheritance diagram for LBFactoryMulti:
Collaboration diagram for LBFactoryMulti:

Public Member Functions

 __construct (array $conf)
 
 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)
 
 getMainLB ($wiki=false)
 
 newMainLB ($wiki=false)
 
 shutdown ($flags=0)
 
- Public Member Functions inherited from LBFactory
 __construct (array $conf)
 Construct a factory based on a configuration array (typically from $wgLBFactoryConf) More...
 
 commitAll ($fname=__METHOD__)
 Commit on all connections. More...
 
 commitMasterChanges ($fname=__METHOD__, array $options=[])
 Commit changes on all master connections. 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...
 

Protected Member Functions

 newExternalLB ($cluster, $wiki=false)
 
- Protected Member Functions inherited from LBFactory
 newChronologyProtector ()
 
 newExternalLB ($cluster, $wiki=false)
 Create a new load balancer for external storage. More...
 
 shutdownChronologyProtector (ChronologyProtector $cp)
 

Private Member Functions

 getDBNameAndPrefix ($wiki=false)
 Get the database name and prefix based on the wiki ID. More...
 
 getSectionForWiki ($wiki=false)
 
 makeServerArray ($template, $loads, $groupLoads)
 Make a server array as expected by LoadBalancer::__construct, using a template and load array. More...
 
 newLoadBalancer ($template, $loads, $groupLoads, $readOnlyReason)
 Make a new load balancer object based on template and load array. More...
 
 reindexGroupLoads ($groupLoads)
 Take a group load array indexed by group then server, and reindex it by server then group. More...
 

Private Attributes

array $conf
 Load balancer factory configuration. More...
 
array $externalLoads = []
 A map of external storage cluster name to server load map. More...
 
array $externalTemplateOverrides
 A set of server info keys overriding serverTemplate for external storage. More...
 
LoadBalancer[] $extLBs = []
 
array $groupLoadsByDB = []
 A 3-d map giving server load ratios by DB name. More...
 
array $groupLoadsBySection = []
 A 3-d map giving server load ratios for each section and group. More...
 
array $hostsByName = []
 A map of hostname to IP address. More...
 
string $lastSection
 
string $lastWiki
 
string $loadMonitorClass
 
LoadBalancer[] $mainLBs = []
 
array $masterTemplateOverrides
 An override array for all master servers. More...
 
array bool $readOnlyBySection = []
 A map of section name to read-only message. More...
 
array $sectionLoads
 A 2-d map. More...
 
array $sectionsByDB
 A map of database names to section names. More...
 
array $serverTemplate
 A server info associative array as documented for $wgDBservers. More...
 
array $templateOverridesByCluster
 A 2-d map overriding the server info by external storage cluster. More...
 
array $templateOverridesBySection
 A 2-d map overriding the server info by section. More...
 
array $templateOverridesByServer
 A 2-d map overriding serverTemplate and externalTemplateOverrides on a server-by-server basis. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from LBFactory
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 setInstance ($instance)
 Set the instance to be the given object. More...
 
static singleton ()
 Get an LBFactory instance. More...
 
- Public Attributes inherited from LBFactory
const SHUTDOWN_NO_CHRONPROT = 1
 
- Protected Attributes inherited from LBFactory
ChronologyProtector $chronProt
 
LoggerInterface $logger
 
string bool $readOnlyReason = false
 Reason all LBs are read-only or false if not. More...
 
TransactionProfiler $trxProfiler
 

Detailed Description

A multi-wiki, multi-master factory for Wikimedia and similar installations.

Ignores the old configuration globals.

Template override precedence (highest => lowest):

  • templateOverridesByServer
  • masterTemplateOverrides
  • templateOverridesBySection/templateOverridesByCluster
  • externalTemplateOverrides
  • serverTemplate Overrides only work on top level keys (so nested values will not be merged).

Configuration: sectionsByDB A map of database names to section names.

sectionLoads A 2-d map. For each section, gives a map of server names to load ratios. For example: array( 'section1' => array( 'db1' => 100, 'db2' => 100 ) )

serverTemplate A server info associative array as documented for $wgDBservers. The host, hostName and load entries will be overridden.

groupLoadsBySection A 3-d map giving server load ratios for each section and group. For example: array( 'section1' => array( 'group1' => array( 'db1' => 100, 'db2' => 100 ) ) )

groupLoadsByDB A 3-d map giving server load ratios by DB name.

hostsByName A map of hostname to IP address.

externalLoads A map of external storage cluster name to server load map.

externalTemplateOverrides A set of server info keys overriding serverTemplate for external storage.

templateOverridesByServer A 2-d map overriding serverTemplate and externalTemplateOverrides on a server-by-server basis. Applies to both core and external storage. templateOverridesBySection A 2-d map overriding the server info by section. templateOverridesByCluster A 2-d map overriding the server info by external storage cluster.

masterTemplateOverrides An override array for all master servers.

loadMonitorClass Name of the LoadMonitor class to always use.

readOnlyBySection A map of section name to read-only message. Missing or false for read/write.

Definition at line 86 of file LBFactoryMulti.php.

Constructor & Destructor Documentation

LBFactoryMulti::__construct ( array  $conf)
Parameters
array$conf
Exceptions
MWException

Definition at line 169 of file LBFactoryMulti.php.

References $conf, $key, and as.

Member Function Documentation

LBFactoryMulti::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.

Parameters
callable$callback
array$params

Definition at line 409 of file LBFactoryMulti.php.

References $params, and as.

LBFactoryMulti::getDBNameAndPrefix (   $wiki = false)
private

Get the database name and prefix based on the wiki ID.

Parameters
bool | string$wiki
Returns
array

Definition at line 392 of file LBFactoryMulti.php.

References $wgDBname, $wgDBprefix, global, and wfSplitWikiID().

Referenced by getSectionForWiki(), and newMainLB().

& LBFactoryMulti::getExternalLB (   $cluster,
  $wiki = false 
)
Parameters
string$clusterExternal storage cluster, or false for core
bool | string$wikiWiki ID, or false for the current wiki
Returns
LoadBalancer

Definition at line 296 of file LBFactoryMulti.php.

References newExternalLB().

LBFactoryMulti::getMainLB (   $wiki = false)
Parameters
bool | string$wiki
Returns
LoadBalancer

Definition at line 253 of file LBFactoryMulti.php.

References $section, getSectionForWiki(), and newMainLB().

LBFactoryMulti::getSectionForWiki (   $wiki = false)
private
Parameters
bool | string$wiki
Returns
string

Definition at line 197 of file LBFactoryMulti.php.

References $lastSection, $section, getDBNameAndPrefix(), and list.

Referenced by getMainLB(), and newMainLB().

LBFactoryMulti::makeServerArray (   $template,
  $loads,
  $groupLoads 
)
private

Make a server array as expected by LoadBalancer::__construct, using a template and load array.

Parameters
array$template
array$loads
array$groupLoads
Returns
array

Definition at line 332 of file LBFactoryMulti.php.

References $template, as, and reindexGroupLoads().

Referenced by newLoadBalancer().

LBFactoryMulti::newExternalLB (   $cluster,
  $wiki = false 
)
protected
Parameters
string$cluster
bool | string$wiki
Exceptions
MWException
Returns
LoadBalancer

Definition at line 271 of file LBFactoryMulti.php.

References $serverTemplate, $template, and newLoadBalancer().

Referenced by getExternalLB().

LBFactoryMulti::newLoadBalancer (   $template,
  $loads,
  $groupLoads,
  $readOnlyReason 
)
private

Make a new load balancer object based on template and load array.

Parameters
array$template
array$loads
array$groupLoads
string | bool$readOnlyReason
Returns
LoadBalancer

Definition at line 315 of file LBFactoryMulti.php.

References LBFactory\$readOnlyReason, $template, and makeServerArray().

Referenced by newExternalLB(), and newMainLB().

LBFactoryMulti::newMainLB (   $wiki = false)
Parameters
bool | string$wiki
Returns
LoadBalancer

Definition at line 217 of file LBFactoryMulti.php.

References LBFactory\$readOnlyReason, $section, $serverTemplate, $template, getDBNameAndPrefix(), getSectionForWiki(), list, and newLoadBalancer().

Referenced by getMainLB().

LBFactoryMulti::reindexGroupLoads (   $groupLoads)
private

Take a group load array indexed by group then server, and reindex it by server then group.

Parameters
array$groupLoads
Returns
array

Definition at line 376 of file LBFactoryMulti.php.

References as.

Referenced by makeServerArray().

LBFactoryMulti::shutdown (   $flags = 0)

Member Data Documentation

array LBFactoryMulti::$conf
private

Load balancer factory configuration.

Definition at line 148 of file LBFactoryMulti.php.

Referenced by __construct().

array LBFactoryMulti::$externalLoads = []
private

A map of external storage cluster name to server load map.

Definition at line 115 of file LBFactoryMulti.php.

array LBFactoryMulti::$externalTemplateOverrides
private

A set of server info keys overriding serverTemplate for external storage.

Definition at line 121 of file LBFactoryMulti.php.

LoadBalancer [] LBFactoryMulti::$extLBs = []
private

Definition at line 154 of file LBFactoryMulti.php.

array LBFactoryMulti::$groupLoadsByDB = []
private

A 3-d map giving server load ratios by DB name.

Definition at line 109 of file LBFactoryMulti.php.

array LBFactoryMulti::$groupLoadsBySection = []
private

A 3-d map giving server load ratios for each section and group.

Definition at line 106 of file LBFactoryMulti.php.

array LBFactoryMulti::$hostsByName = []
private

A map of hostname to IP address.

Definition at line 112 of file LBFactoryMulti.php.

string LBFactoryMulti::$lastSection
private

Definition at line 163 of file LBFactoryMulti.php.

Referenced by getSectionForWiki().

string LBFactoryMulti::$lastWiki
private

Definition at line 160 of file LBFactoryMulti.php.

string LBFactoryMulti::$loadMonitorClass
private

Definition at line 157 of file LBFactoryMulti.php.

LoadBalancer [] LBFactoryMulti::$mainLBs = []
private

Definition at line 151 of file LBFactoryMulti.php.

array LBFactoryMulti::$masterTemplateOverrides
private

An override array for all master servers.

Definition at line 137 of file LBFactoryMulti.php.

array bool LBFactoryMulti::$readOnlyBySection = []
private

A map of section name to read-only message.

Missing or false for read/write

Definition at line 143 of file LBFactoryMulti.php.

array LBFactoryMulti::$sectionLoads
private

A 2-d map.

For each section, gives a map of server names to load ratios

Definition at line 94 of file LBFactoryMulti.php.

array LBFactoryMulti::$sectionsByDB
private

A map of database names to section names.

Definition at line 88 of file LBFactoryMulti.php.

array LBFactoryMulti::$serverTemplate
private

A server info associative array as documented for $wgDBservers.

The host, hostName and load entries will be overridden

Definition at line 101 of file LBFactoryMulti.php.

Referenced by newExternalLB(), and newMainLB().

array LBFactoryMulti::$templateOverridesByCluster
private

A 2-d map overriding the server info by external storage cluster.

Definition at line 134 of file LBFactoryMulti.php.

array LBFactoryMulti::$templateOverridesBySection
private

A 2-d map overriding the server info by section.

Definition at line 131 of file LBFactoryMulti.php.

array LBFactoryMulti::$templateOverridesByServer
private

A 2-d map overriding serverTemplate and externalTemplateOverrides on a server-by-server basis.

Applies to both core and external storage

Definition at line 128 of file LBFactoryMulti.php.


The documentation for this class was generated from the following file: