2008-03-30 09:48:15 +00:00
|
|
|
<?php
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
/**
|
2012-04-26 08:47:10 +00:00
|
|
|
* Advanced generator of database load balancing objects for wiki farms.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-08 11:55:47 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
|
|
|
|
* @ingroup Database
|
|
|
|
|
*/
|
|
|
|
|
|
2008-03-30 09:48:15 +00:00
|
|
|
/**
|
|
|
|
|
* A multi-wiki, multi-master factory for Wikimedia and similar installations.
|
|
|
|
|
* Ignores the old configuration globals
|
|
|
|
|
*
|
2008-04-14 07:45:50 +00:00
|
|
|
* Configuration:
|
2013-12-26 22:47:37 +00:00
|
|
|
* sectionsByDB A map of database names to section names.
|
2008-03-30 09:48:15 +00:00
|
|
|
*
|
2013-11-20 10:13:51 +00:00
|
|
|
* 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
|
|
|
|
|
* )
|
|
|
|
|
* )
|
|
|
|
|
* )
|
2008-03-30 09:48:15 +00:00
|
|
|
*
|
|
|
|
|
* groupLoadsByDB A 3-d map giving server load ratios by DB name.
|
|
|
|
|
*
|
|
|
|
|
* hostsByName A map of hostname to IP address.
|
|
|
|
|
*
|
2013-12-26 22:47:37 +00:00
|
|
|
* externalLoads A map of external storage cluster name to server load map.
|
2008-03-30 09:48:15 +00:00
|
|
|
*
|
2013-11-20 10:13:51 +00:00
|
|
|
* externalTemplateOverrides A set of server info keys overriding serverTemplate for external
|
2013-12-26 22:47:37 +00:00
|
|
|
* storage.
|
2008-03-30 09:48:15 +00:00
|
|
|
*
|
2013-11-20 10:13:51 +00:00
|
|
|
* templateOverridesByServer A 2-d map overriding serverTemplate and
|
|
|
|
|
* externalTemplateOverrides on a server-by-server basis. Applies
|
|
|
|
|
* to both core and external storage.
|
2008-03-30 09:48:15 +00:00
|
|
|
*
|
2013-12-26 22:47:37 +00:00
|
|
|
* templateOverridesByCluster A 2-d map overriding the server info by external storage cluster.
|
2008-03-30 09:48:15 +00:00
|
|
|
*
|
2008-04-05 18:11:23 +00:00
|
|
|
* masterTemplateOverrides An override array for all master servers.
|
2008-03-30 09:48:15 +00:00
|
|
|
*
|
2013-11-20 10:13:51 +00:00
|
|
|
* readOnlyBySection A map of section name to read-only message.
|
|
|
|
|
* Missing or false for read/write.
|
2008-10-12 14:29:55 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Database
|
2008-03-30 09:48:15 +00:00
|
|
|
*/
|
2013-11-27 10:17:06 +00:00
|
|
|
class LBFactoryMulti extends LBFactory {
|
2008-03-30 09:48:15 +00:00
|
|
|
// Required settings
|
2013-12-26 22:47:37 +00:00
|
|
|
|
|
|
|
|
/** @var array A map of database names to section names */
|
|
|
|
|
protected $sectionsByDB;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var array A 2-d map. For each section, gives a map of server names to
|
|
|
|
|
* load ratios
|
|
|
|
|
*/
|
|
|
|
|
protected $sectionLoads;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var array A server info associative array as documented for
|
|
|
|
|
* $wgDBservers. The host, hostName and load entries will be
|
|
|
|
|
* overridden
|
|
|
|
|
*/
|
|
|
|
|
protected $serverTemplate;
|
|
|
|
|
|
2008-03-30 09:48:15 +00:00
|
|
|
// Optional settings
|
2013-12-26 22:47:37 +00:00
|
|
|
|
|
|
|
|
/** @var array A 3-d map giving server load ratios for each section and group */
|
|
|
|
|
protected $groupLoadsBySection = array();
|
|
|
|
|
|
|
|
|
|
/** @var array A 3-d map giving server load ratios by DB name */
|
|
|
|
|
protected $groupLoadsByDB = array();
|
|
|
|
|
|
|
|
|
|
/** @var array A map of hostname to IP address */
|
|
|
|
|
protected $hostsByName = array();
|
|
|
|
|
|
|
|
|
|
/** @var array A map of external storage cluster name to server load map */
|
|
|
|
|
protected $externalLoads = array();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var array A set of server info keys overriding serverTemplate for
|
|
|
|
|
* external storage
|
|
|
|
|
*/
|
|
|
|
|
protected $externalTemplateOverrides;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var array A 2-d map overriding serverTemplate and
|
|
|
|
|
* externalTemplateOverrides on a server-by-server basis. Applies to both
|
|
|
|
|
* core and external storage
|
|
|
|
|
*/
|
|
|
|
|
protected $templateOverridesByServer;
|
|
|
|
|
|
|
|
|
|
/** @var array A 2-d map overriding the server info by external storage cluster */
|
|
|
|
|
protected $templateOverridesByCluster;
|
|
|
|
|
|
|
|
|
|
/** @var array An override array for all master servers */
|
|
|
|
|
protected $masterTemplateOverrides;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var array|bool A map of section name to read-only message. Missing or
|
|
|
|
|
* false for read/write
|
|
|
|
|
*/
|
|
|
|
|
protected $readOnlyBySection = array();
|
|
|
|
|
|
2008-03-30 09:48:15 +00:00
|
|
|
// Other stuff
|
2013-12-26 22:47:37 +00:00
|
|
|
|
|
|
|
|
/** @var array Load balancer factory configuration */
|
|
|
|
|
protected $conf;
|
|
|
|
|
|
|
|
|
|
/** @var LoadBalancer[] */
|
|
|
|
|
protected $mainLBs = array();
|
|
|
|
|
|
|
|
|
|
/** @var LoadBalancer[] */
|
|
|
|
|
protected $extLBs = array();
|
|
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
|
protected $lastWiki;
|
|
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
|
protected $lastSection;
|
2008-03-30 09:48:15 +00:00
|
|
|
|
2011-11-29 21:04:20 +00:00
|
|
|
/**
|
2013-12-27 01:54:51 +00:00
|
|
|
* @param array $conf
|
2012-10-07 23:35:26 +00:00
|
|
|
* @throws MWException
|
2011-11-29 21:04:20 +00:00
|
|
|
*/
|
2008-03-30 09:48:15 +00:00
|
|
|
function __construct( $conf ) {
|
|
|
|
|
$this->chronProt = new ChronologyProtector;
|
|
|
|
|
$this->conf = $conf;
|
2008-04-05 18:11:23 +00:00
|
|
|
$required = array( 'sectionsByDB', 'sectionLoads', 'serverTemplate' );
|
2008-04-14 07:45:50 +00:00
|
|
|
$optional = array( 'groupLoadsBySection', 'groupLoadsByDB', 'hostsByName',
|
2008-04-05 18:11:23 +00:00
|
|
|
'externalLoads', 'externalTemplateOverrides', 'templateOverridesByServer',
|
2011-09-16 17:58:50 +00:00
|
|
|
'templateOverridesByCluster', 'masterTemplateOverrides',
|
2008-10-12 14:29:55 +00:00
|
|
|
'readOnlyBySection' );
|
2008-03-30 09:48:15 +00:00
|
|
|
|
|
|
|
|
foreach ( $required as $key ) {
|
|
|
|
|
if ( !isset( $conf[$key] ) ) {
|
2013-02-03 18:47:42 +00:00
|
|
|
throw new MWException( __CLASS__ . ": $key is required in configuration" );
|
2008-03-30 09:48:15 +00:00
|
|
|
}
|
|
|
|
|
$this->$key = $conf[$key];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $optional as $key ) {
|
|
|
|
|
if ( isset( $conf[$key] ) ) {
|
|
|
|
|
$this->$key = $conf[$key];
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-10-12 14:29:55 +00:00
|
|
|
|
|
|
|
|
// Check for read-only mode
|
|
|
|
|
$section = $this->getSectionForWiki();
|
|
|
|
|
if ( !empty( $this->readOnlyBySection[$section] ) ) {
|
|
|
|
|
global $wgReadOnly;
|
|
|
|
|
$wgReadOnly = $this->readOnlyBySection[$section];
|
|
|
|
|
}
|
2008-03-30 09:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-16 17:58:50 +00:00
|
|
|
/**
|
2013-12-27 01:54:51 +00:00
|
|
|
* @param bool|string $wiki
|
2011-09-16 17:58:50 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2008-07-08 10:41:08 +00:00
|
|
|
function getSectionForWiki( $wiki = false ) {
|
|
|
|
|
if ( $this->lastWiki === $wiki ) {
|
|
|
|
|
return $this->lastSection;
|
|
|
|
|
}
|
2010-11-28 16:13:13 +00:00
|
|
|
list( $dbName, ) = $this->getDBNameAndPrefix( $wiki );
|
2008-03-30 09:48:15 +00:00
|
|
|
if ( isset( $this->sectionsByDB[$dbName] ) ) {
|
2008-07-08 10:41:08 +00:00
|
|
|
$section = $this->sectionsByDB[$dbName];
|
2008-03-30 09:48:15 +00:00
|
|
|
} else {
|
2008-07-08 10:41:08 +00:00
|
|
|
$section = 'DEFAULT';
|
2008-03-30 09:48:15 +00:00
|
|
|
}
|
2008-07-08 10:41:08 +00:00
|
|
|
$this->lastSection = $section;
|
|
|
|
|
$this->lastWiki = $wiki;
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2008-07-08 10:41:08 +00:00
|
|
|
return $section;
|
2008-03-30 09:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-25 18:41:31 +00:00
|
|
|
/**
|
2013-12-27 01:54:51 +00:00
|
|
|
* @param bool|string $wiki
|
2011-05-25 18:41:31 +00:00
|
|
|
* @return LoadBalancer
|
|
|
|
|
*/
|
2008-07-08 10:41:08 +00:00
|
|
|
function newMainLB( $wiki = false ) {
|
2010-11-30 18:44:50 +00:00
|
|
|
list( $dbName, ) = $this->getDBNameAndPrefix( $wiki );
|
2008-07-08 10:41:08 +00:00
|
|
|
$section = $this->getSectionForWiki( $wiki );
|
|
|
|
|
$groupLoads = array();
|
|
|
|
|
if ( isset( $this->groupLoadsByDB[$dbName] ) ) {
|
|
|
|
|
$groupLoads = $this->groupLoadsByDB[$dbName];
|
2008-03-30 09:48:15 +00:00
|
|
|
}
|
2013-11-20 10:13:51 +00:00
|
|
|
|
2008-07-08 10:41:08 +00:00
|
|
|
if ( isset( $this->groupLoadsBySection[$section] ) ) {
|
|
|
|
|
$groupLoads = array_merge_recursive( $groupLoads, $this->groupLoadsBySection[$section] );
|
|
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2013-11-20 10:13:51 +00:00
|
|
|
return $this->newLoadBalancer(
|
|
|
|
|
$this->serverTemplate,
|
|
|
|
|
$this->sectionLoads[$section],
|
|
|
|
|
$groupLoads
|
|
|
|
|
);
|
2008-07-08 10:41:08 +00:00
|
|
|
}
|
2008-03-30 09:48:15 +00:00
|
|
|
|
2011-05-25 18:41:31 +00:00
|
|
|
/**
|
2013-12-27 01:54:51 +00:00
|
|
|
* @param bool|string $wiki
|
2011-05-25 18:41:31 +00:00
|
|
|
* @return LoadBalancer
|
|
|
|
|
*/
|
2008-07-08 10:41:08 +00:00
|
|
|
function getMainLB( $wiki = false ) {
|
|
|
|
|
$section = $this->getSectionForWiki( $wiki );
|
2008-03-30 09:48:15 +00:00
|
|
|
if ( !isset( $this->mainLBs[$section] ) ) {
|
2008-07-08 10:41:08 +00:00
|
|
|
$lb = $this->newMainLB( $wiki, $section );
|
|
|
|
|
$lb->parentInfo( array( 'id' => "main-$section" ) );
|
2013-04-11 13:22:40 +00:00
|
|
|
$this->chronProt->initLB( $lb );
|
2008-07-08 10:41:08 +00:00
|
|
|
$this->mainLBs[$section] = $lb;
|
2008-03-30 09:48:15 +00:00
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2008-03-30 09:48:15 +00:00
|
|
|
return $this->mainLBs[$section];
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-25 18:41:31 +00:00
|
|
|
/**
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $cluster
|
2013-12-27 01:54:51 +00:00
|
|
|
* @param bool|string $wiki
|
2012-10-07 23:35:26 +00:00
|
|
|
* @throws MWException
|
2011-05-25 18:41:31 +00:00
|
|
|
* @return LoadBalancer
|
|
|
|
|
*/
|
2008-07-08 10:41:08 +00:00
|
|
|
function newExternalLB( $cluster, $wiki = false ) {
|
|
|
|
|
if ( !isset( $this->externalLoads[$cluster] ) ) {
|
2013-02-03 18:47:42 +00:00
|
|
|
throw new MWException( __METHOD__ . ": Unknown cluster \"$cluster\"" );
|
2008-07-08 10:41:08 +00:00
|
|
|
}
|
|
|
|
|
$template = $this->serverTemplate;
|
|
|
|
|
if ( isset( $this->externalTemplateOverrides ) ) {
|
|
|
|
|
$template = $this->externalTemplateOverrides + $template;
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $this->templateOverridesByCluster[$cluster] ) ) {
|
|
|
|
|
$template = $this->templateOverridesByCluster[$cluster] + $template;
|
|
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2008-07-08 10:41:08 +00:00
|
|
|
return $this->newLoadBalancer( $template, $this->externalLoads[$cluster], array() );
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-25 18:41:31 +00:00
|
|
|
/**
|
2013-12-27 01:54:51 +00:00
|
|
|
* @param string $cluster external storage cluster, or false for core
|
|
|
|
|
* @param bool|string $wiki Wiki ID, or false for the current wiki
|
2011-05-25 18:41:31 +00:00
|
|
|
* @return LoadBalancer
|
|
|
|
|
*/
|
2008-03-30 15:16:50 +00:00
|
|
|
function &getExternalLB( $cluster, $wiki = false ) {
|
2008-03-30 09:48:15 +00:00
|
|
|
if ( !isset( $this->extLBs[$cluster] ) ) {
|
2008-07-08 10:41:08 +00:00
|
|
|
$this->extLBs[$cluster] = $this->newExternalLB( $cluster, $wiki );
|
|
|
|
|
$this->extLBs[$cluster]->parentInfo( array( 'id' => "ext-$cluster" ) );
|
2013-04-11 13:22:40 +00:00
|
|
|
$this->chronProt->initLB( $this->extLBs[$cluster] );
|
2008-03-30 09:48:15 +00:00
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2008-03-30 09:48:15 +00:00
|
|
|
return $this->extLBs[$cluster];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Make a new load balancer object based on template and load array
|
2011-05-25 18:41:31 +00:00
|
|
|
*
|
2013-12-27 01:54:51 +00:00
|
|
|
* @param array $template
|
|
|
|
|
* @param array $loads
|
|
|
|
|
* @param array $groupLoads
|
2011-05-25 18:41:31 +00:00
|
|
|
* @return LoadBalancer
|
2008-03-30 09:48:15 +00:00
|
|
|
*/
|
2008-07-08 10:41:08 +00:00
|
|
|
function newLoadBalancer( $template, $loads, $groupLoads ) {
|
2008-03-30 09:48:15 +00:00
|
|
|
$servers = $this->makeServerArray( $template, $loads, $groupLoads );
|
2008-07-07 03:31:00 +00:00
|
|
|
$lb = new LoadBalancer( array(
|
|
|
|
|
'servers' => $servers,
|
2013-11-20 06:58:22 +00:00
|
|
|
) );
|
|
|
|
|
|
2008-03-30 09:48:15 +00:00
|
|
|
return $lb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Make a server array as expected by LoadBalancer::__construct, using a template and load array
|
2011-05-25 18:58:02 +00:00
|
|
|
*
|
2013-12-27 01:54:51 +00:00
|
|
|
* @param array $template
|
|
|
|
|
* @param array $loads
|
|
|
|
|
* @param array $groupLoads
|
2011-05-25 18:58:02 +00:00
|
|
|
* @return array
|
2008-03-30 09:48:15 +00:00
|
|
|
*/
|
|
|
|
|
function makeServerArray( $template, $loads, $groupLoads ) {
|
|
|
|
|
$servers = array();
|
|
|
|
|
$master = true;
|
|
|
|
|
$groupLoadsByServer = $this->reindexGroupLoads( $groupLoads );
|
|
|
|
|
foreach ( $groupLoadsByServer as $server => $stuff ) {
|
|
|
|
|
if ( !isset( $loads[$server] ) ) {
|
|
|
|
|
$loads[$server] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach ( $loads as $serverName => $load ) {
|
|
|
|
|
$serverInfo = $template;
|
|
|
|
|
if ( $master ) {
|
|
|
|
|
$serverInfo['master'] = true;
|
|
|
|
|
if ( isset( $this->masterTemplateOverrides ) ) {
|
|
|
|
|
$serverInfo = $this->masterTemplateOverrides + $serverInfo;
|
|
|
|
|
}
|
|
|
|
|
$master = false;
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $this->templateOverridesByServer[$serverName] ) ) {
|
|
|
|
|
$serverInfo = $this->templateOverridesByServer[$serverName] + $serverInfo;
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $groupLoadsByServer[$serverName] ) ) {
|
|
|
|
|
$serverInfo['groupLoads'] = $groupLoadsByServer[$serverName];
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $this->hostsByName[$serverName] ) ) {
|
|
|
|
|
$serverInfo['host'] = $this->hostsByName[$serverName];
|
|
|
|
|
} else {
|
|
|
|
|
$serverInfo['host'] = $serverName;
|
|
|
|
|
}
|
|
|
|
|
$serverInfo['hostName'] = $serverName;
|
|
|
|
|
$serverInfo['load'] = $load;
|
|
|
|
|
$servers[] = $serverInfo;
|
|
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2008-03-30 09:48:15 +00:00
|
|
|
return $servers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Take a group load array indexed by group then server, and reindex it by server then group
|
2013-12-27 01:54:51 +00:00
|
|
|
* @param array $groupLoads
|
2011-09-16 17:58:50 +00:00
|
|
|
* @return array
|
2008-03-30 09:48:15 +00:00
|
|
|
*/
|
|
|
|
|
function reindexGroupLoads( $groupLoads ) {
|
|
|
|
|
$reindexed = array();
|
|
|
|
|
foreach ( $groupLoads as $group => $loads ) {
|
|
|
|
|
foreach ( $loads as $server => $load ) {
|
|
|
|
|
$reindexed[$server][$group] = $load;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2008-03-30 09:48:15 +00:00
|
|
|
return $reindexed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the database name and prefix based on the wiki ID
|
2013-12-27 01:54:51 +00:00
|
|
|
* @param bool|string $wiki
|
2011-09-16 17:58:50 +00:00
|
|
|
* @return array
|
2008-03-30 09:48:15 +00:00
|
|
|
*/
|
|
|
|
|
function getDBNameAndPrefix( $wiki = false ) {
|
|
|
|
|
if ( $wiki === false ) {
|
|
|
|
|
global $wgDBname, $wgDBprefix;
|
2013-11-20 06:58:22 +00:00
|
|
|
|
2008-03-30 09:48:15 +00:00
|
|
|
return array( $wgDBname, $wgDBprefix );
|
|
|
|
|
} else {
|
|
|
|
|
return wfSplitWikiID( $wiki );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
2013-12-27 01:54:51 +00:00
|
|
|
* @param callable $callback
|
|
|
|
|
* @param array $params
|
2008-03-30 09:48:15 +00:00
|
|
|
*/
|
|
|
|
|
function forEachLB( $callback, $params = array() ) {
|
|
|
|
|
foreach ( $this->mainLBs as $lb ) {
|
|
|
|
|
call_user_func_array( $callback, array_merge( array( $lb ), $params ) );
|
|
|
|
|
}
|
|
|
|
|
foreach ( $this->extLBs as $lb ) {
|
|
|
|
|
call_user_func_array( $callback, array_merge( array( $lb ), $params ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function shutdown() {
|
|
|
|
|
foreach ( $this->mainLBs as $lb ) {
|
|
|
|
|
$this->chronProt->shutdownLB( $lb );
|
|
|
|
|
}
|
2013-04-11 13:22:40 +00:00
|
|
|
foreach ( $this->extLBs as $extLB ) {
|
|
|
|
|
$this->chronProt->shutdownLB( $extLB );
|
|
|
|
|
}
|
2008-03-30 09:48:15 +00:00
|
|
|
$this->chronProt->shutdown();
|
|
|
|
|
$this->commitMasterChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|