<?php
/**
- * Advanced generator of database load balancing objects for wiki farms
+ * 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
*
* @file
* @ingroup Database
var $conf, $mainLBs = array(), $extLBs = array();
var $lastWiki, $lastSection;
+ /**
+ * @param $conf array
+ */
function __construct( $conf ) {
$this->chronProt = new ChronologyProtector;
$this->conf = $conf;
$required = array( 'sectionsByDB', 'sectionLoads', 'serverTemplate' );
$optional = array( 'groupLoadsBySection', 'groupLoadsByDB', 'hostsByName',
'externalLoads', 'externalTemplateOverrides', 'templateOverridesByServer',
- 'templateOverridesByCluster', 'masterTemplateOverrides',
+ 'templateOverridesByCluster', 'masterTemplateOverrides',
'readOnlyBySection' );
foreach ( $required as $key ) {
}
}
+ /**
+ * @param $wiki bool|string
+ * @return string
+ */
function getSectionForWiki( $wiki = false ) {
if ( $this->lastWiki === $wiki ) {
return $this->lastSection;
return $section;
}
+ /**
+ * @param $wiki bool|string
+ * @return LoadBalancer
+ */
function newMainLB( $wiki = false ) {
list( $dbName, ) = $this->getDBNameAndPrefix( $wiki );
$section = $this->getSectionForWiki( $wiki );
return $this->newLoadBalancer( $this->serverTemplate, $this->sectionLoads[$section], $groupLoads );
}
+ /**
+ * @param $wiki bool|string
+ * @return LoadBalancer
+ */
function getMainLB( $wiki = false ) {
$section = $this->getSectionForWiki( $wiki );
if ( !isset( $this->mainLBs[$section] ) ) {
return $this->mainLBs[$section];
}
+ /**
+ * @param $cluster
+ * @param $wiki
+ * @return LoadBalancer
+ */
function newExternalLB( $cluster, $wiki = false ) {
if ( !isset( $this->externalLoads[$cluster] ) ) {
throw new MWException( __METHOD__.": Unknown cluster \"$cluster\"" );
return $this->newLoadBalancer( $template, $this->externalLoads[$cluster], array() );
}
+ /**
+ * @param $cluster
+ * @param $wiki
+ * @return LoadBalancer
+ */
function &getExternalLB( $cluster, $wiki = false ) {
if ( !isset( $this->extLBs[$cluster] ) ) {
$this->extLBs[$cluster] = $this->newExternalLB( $cluster, $wiki );
/**
* Make a new load balancer object based on template and load array
+ *
+ * @param $template
+ * @param $loads array
+ * @param $groupLoads
+ * @return LoadBalancer
*/
function newLoadBalancer( $template, $loads, $groupLoads ) {
global $wgMasterWaitTimeout;
$servers = $this->makeServerArray( $template, $loads, $groupLoads );
$lb = new LoadBalancer( array(
'servers' => $servers,
- 'masterWaitTimeout' => $wgMasterWaitTimeout
+ 'masterWaitTimeout' => $wgMasterWaitTimeout
));
return $lb;
}
/**
* Make a server array as expected by LoadBalancer::__construct, using a template and load array
+ *
+ * @param $template
+ * @param $loads array
+ * @param $groupLoads
+ * @return array
*/
function makeServerArray( $template, $loads, $groupLoads ) {
$servers = array();
/**
* Take a group load array indexed by group then server, and reindex it by server then group
+ * @param $groupLoads
+ * @return array
*/
function reindexGroupLoads( $groupLoads ) {
$reindexed = array();
/**
* Get the database name and prefix based on the wiki ID
+ * @param $wiki bool
+ * @return array
*/
function getDBNameAndPrefix( $wiki = false ) {
if ( $wiki === false ) {
* 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.
+ * @param $callback
+ * @param $params array
*/
function forEachLB( $callback, $params = array() ) {
foreach ( $this->mainLBs as $lb ) {