<?php
/**
- * Generator of database load balancing objects
+ * Generator of database load balancing objects.
+ *
+ * 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
/**
* Get an LBFactory instance
+ *
+ * @return LBFactory
*/
static function &singleton() {
if ( is_null( self::$instance ) ) {
/**
* Shut down, close connections and destroy the cached instance.
- *
*/
static function destroyInstance() {
if ( self::$instance ) {
/**
* Set the instance to be the given object
+ *
+ * @param $instance LBFactory
*/
static function setInstance( $instance ) {
self::destroyInstance();
/**
* Construct a factory based on a configuration array (typically from $wgLBFactoryConf)
+ * @param $conf
*/
abstract function __construct( $conf );
*
* @param $cluster String: external storage cluster, or false for core
* @param $wiki String: wiki ID, or false for the current wiki
+ *
+ * @return LoadBalancer
*/
abstract function newExternalLB( $cluster, $wiki = false );
*
* @param $cluster String: external storage cluster, or false for core
* @param $wiki String: wiki ID, or false for the current wiki
+ *
+ * @return LoadBalancer
*/
abstract function &getExternalLB( $cluster, $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 string|array
+ * @param array $params
*/
abstract function forEachLB( $callback, $params = array() );
/**
* Call a method of each tracked load balancer
+ * @param $methodName string
+ * @param $args array
*/
function forEachLBCallMethod( $methodName, $args = array() ) {
$this->forEachLB( array( $this, 'callMethod' ), array( $methodName, $args ) );
/**
* Private helper for forEachLBCallMethod
+ * @param $loadBalancer
+ * @param $methodName string
+ * @param $args
*/
function callMethod( $loadBalancer, $methodName, $args ) {
call_user_func_array( array( $loadBalancer, $methodName ), $args );
$this->chronProt = new ChronologyProtector;
}
+ /**
+ * @param $wiki
+ * @return LoadBalancer
+ */
function newMainLB( $wiki = false ) {
global $wgDBservers, $wgMasterWaitTimeout;
if ( $wgDBservers ) {
$servers = $wgDBservers;
} else {
global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype, $wgDebugDumpSql;
+ global $wgDBssl, $wgDBcompress;
+
+ $flags = ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT;
+ if ( $wgDBssl ) {
+ $flags |= DBO_SSL;
+ }
+ if ( $wgDBcompress ) {
+ $flags |= DBO_COMPRESS;
+ }
+
$servers = array(array(
'host' => $wgDBserver,
'user' => $wgDBuser,
'dbname' => $wgDBname,
'type' => $wgDBtype,
'load' => 1,
- 'flags' => ($wgDebugDumpSql ? DBO_DEBUG : 0) | DBO_DEFAULT
+ 'flags' => $flags
));
}
));
}
+ /**
+ * @param $wiki
+ * @return LoadBalancer
+ */
function getMainLB( $wiki = false ) {
if ( !isset( $this->mainLB ) ) {
$this->mainLB = $this->newMainLB( $wiki );
return $this->mainLB;
}
+ /**
+ * @throws MWException
+ * @param $cluster
+ * @param $wiki
+ * @return LoadBalancer
+ */
function newExternalLB( $cluster, $wiki = false ) {
global $wgExternalServers;
if ( !isset( $wgExternalServers[$cluster] ) ) {
- throw new MWException( __METHOD__.": Unknown cluster \"$cluster\"" );
+ throw new MWException( __METHOD__ . ": Unknown cluster \"$cluster\"" );
}
return new LoadBalancer( array(
'servers' => $wgExternalServers[$cluster]
));
}
+ /**
+ * @param $cluster
+ * @param $wiki
+ * @return array
+ */
function &getExternalLB( $cluster, $wiki = false ) {
if ( !isset( $this->extLBs[$cluster] ) ) {
$this->extLBs[$cluster] = $this->newExternalLB( $cluster, $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.
+ * @param $callback
+ * @param $params array
*/
function forEachLB( $callback, $params = array() ) {
if ( isset( $this->mainLB ) ) {
if ( $lb->getServerCount() > 1 && !empty( $this->startupPos[$masterName] ) ) {
$info = $lb->parentInfo();
$pos = $this->startupPos[$masterName];
- wfDebug( __METHOD__.": LB " . $info['id'] . " waiting for master pos $pos\n" );
+ wfDebug( __METHOD__ . ": LB " . $info['id'] . " waiting for master pos $pos\n" );
$lb->waitFor( $this->startupPos[$masterName] );
}
}
$db = $lb->getAnyOpenConnection( 0 );
$info = $lb->parentInfo();
if ( !$db || !$db->doneWrites() ) {
- wfDebug( __METHOD__.": LB {$info['id']}, no writes done\n" );
+ wfDebug( __METHOD__ . ": LB {$info['id']}, no writes done\n" );
return;
}
$pos = $db->getMasterPos();
- wfDebug( __METHOD__.": LB {$info['id']} has master pos $pos\n" );
+ wfDebug( __METHOD__ . ": LB {$info['id']} has master pos $pos\n" );
$this->shutdownPos[$masterName] = $pos;
}
*/
function shutdown() {
if ( session_id() != '' && count( $this->shutdownPos ) ) {
- wfDebug( __METHOD__.": saving master pos for " .
+ wfDebug( __METHOD__ . ": saving master pos for " .
count( $this->shutdownPos ) . " master(s)\n" );
$_SESSION[__CLASS__] = $this->shutdownPos;
}