<?php
-# Database load balancing object
-
+/**
+ *
+ * @package MediaWiki
+ */
+
+/**
+ * Depends on the database object
+ */
require_once( 'Database.php' );
# Valid database indexes
define( 'MASTER_WAIT_TIMEOUT', 15 ); # Time to wait for a slave to synchronise
+/**
+ * Database load balancing object
+ *
+ * @todo document
+ * @package MediaWiki
+ */
class LoadBalancer {
/* private */ var $mServers, $mConnections, $mLoads;
/* private */ var $mFailFunction;
}
}
- # Given an array of non-normalised probabilities, this function will select
- # an element and return the appropriate key
+ /**
+ * Given an array of non-normalised probabilities, this function will select
+ * an element and return the appropriate key
+ */
function pickRandom( $weights )
{
if ( !is_array( $weights ) || count( $weights ) == 0 ) {
return $i;
}
- # Set the master wait position
- # If a DB_SLAVE connection has been opened already, waits
- # Otherwise sets a variable telling it to wait if such a connection is opened
+ /**
+ * Set the master wait position
+ * If a DB_SLAVE connection has been opened already, waits
+ * Otherwise sets a variable telling it to wait if such a connection is opened
+ */
function waitFor( $file, $pos ) {
$fname = 'LoadBalancer::waitFor';
wfProfileIn( $fname );
wfProfileOut( $fname );
}
- # Wait for a given slave to catch up to the master pos stored in $this
+ /**
+ * Wait for a given slave to catch up to the master pos stored in $this
+ */
function doWait( $index ) {
global $wgMemc;
return $retVal;
}
- # Get a connection by index
+ /**
+ * Get a connection by index
+ */
function &getConnection( $i, $fail = true )
{
$fname = 'LoadBalancer::getConnection';
return $this->mConnections[$i];
}
- # Open a connection to the server given by the specified index
- # Index must be an actual index into the array
- /* private */ function openConnection( $i, $fail = false ) {
+ /**
+ * Open a connection to the server given by the specified index
+ * Index must be an actual index into the array
+ * @private
+ */
+ function openConnection( $i, $fail = false ) {
$fname = 'LoadBalancer::openConnection';
wfProfileIn( $fname );
wfProfileOut( $fname );
}
- # Test if the specified index represents an open connection
- /* private */ function isOpen( $index ) {
+ /**
+ * Test if the specified index represents an open connection
+ * @private
+ */
+ function isOpen( $index ) {
if( !is_integer( $index ) ) {
return false;
}
}
}
- # Really opens a connection
- /* private */ function reallyOpenConnection( &$server ) {
+ /**
+ * Really opens a connection
+ * @private
+ */
+ function reallyOpenConnection( &$server ) {
extract( $server );
# Get class for this database type
$class = 'Database' . ucfirst( $type );
return array_key_exists( $i, $this->mServers );
}
- # Get the number of defined servers (not the number of open connections)
+ /**
+ * Get the number of defined servers (not the number of open connections)
+ */
function getServerCount() {
return count( $this->mServers );
}
- # Save master pos to the session and to memcached, if the session exists
+ /**
+ * Save master pos to the session and to memcached, if the session exists
+ */
function saveMasterPos() {
global $wgSessionStarted;
if ( $wgSessionStarted && count( $this->mServers ) > 1 ) {
}
}
- # Loads the master pos from the session, waits for it if necessary
+ /**
+ * Loads the master pos from the session, waits for it if necessary
+ */
function loadMasterPos() {
if ( isset( $_SESSION['master_log_file'] ) && isset( $_SESSION['master_pos'] ) ) {
$this->waitFor( $_SESSION['master_log_file'], $_SESSION['master_pos'] );
}
}
- # Close all open connections
+ /**
+ * Close all open connections
+ */
function closeAll() {
foreach( $this->mConnections as $i => $conn ) {
if ( $this->isOpen( $i ) ) {