doc fix
[lhc/web/wiklou.git] / includes / LoadBalancer.php
index 83c0299..f985a7b 100644 (file)
@@ -32,23 +32,11 @@ define( 'AVG_STATUS_POLL', 2000 );
  * @package MediaWiki
  */
 class LoadBalancer {
-
-       private
-               $mAllowLagged,
-               $mConnections,
-               $mErrorConnection,
-               $mFailFunction,
-               $mForce,
-               $mGroupLoads,
-               $mLaggedSlaveMode,
-               $mLastError = 'Unknown error',
-               $mLastIndex,
-               $mLoads,
-               $mReadIndex,
-               $mServers,
-               $mWaitForFile,
-               $mWaitForPos,
-               $mWaitTimeout ;
+       /* private */ var $mServers, $mConnections, $mLoads, $mGroupLoads;
+       /* private */ var $mFailFunction, $mErrorConnection;
+       /* private */ var $mForce, $mReadIndex, $mLastIndex, $mAllowLagged;
+       /* private */ var $mWaitForFile, $mWaitForPos, $mWaitTimeout;
+       /* private */ var $mLaggedSlaveMode, $mLastError = 'Unknown error';
 
        function LoadBalancer()
        {
@@ -198,11 +186,11 @@ class LoadBalancer {
                                        }
                                        $serverIndex = $i;
                                        if ( $i !== false ) {
-                                               wfDebugLog( 'connect', "Using reader #$i: {$this->mServers[$i]['host']}...\n" );
+                                               wfDebugLog( 'connect', "$fname: Using reader #$i: {$this->mServers[$i]['host']}...\n" );
                                                $this->openConnection( $i );
 
                                                if ( !$this->isOpen( $i ) ) {
-                                                       wfDebug( "Failed\n" );
+                                                       wfDebug( "$fname: Failed\n" );
                                                        unset( $loads[$i] );
                                                        $sleepTime = 0;
                                                } else {
@@ -448,7 +436,7 @@ class LoadBalancer {
         */
        function reallyOpenConnection( &$server ) {
                if( !is_array( $server ) ) {
-                       wfDebugDieBacktrace( 'You must update your load-balancing configuration. See DefaultSettings.php entry for $wgDBservers.' );
+                       throw new MWException( 'You must update your load-balancing configuration. See DefaultSettings.php entry for $wgDBservers.' );
                }
 
                extract( $server );
@@ -481,7 +469,7 @@ class LoadBalancer {
                                        $conn->reportConnectionError( $this->mLastError );
                                } else {
                                        // If all servers were busy, mLastError will contain something sensible
-                                       wfEmergencyAbort( $conn, $this->mLastError );
+                                       throw new DBConnectionError( $conn, $this->mLastError );
                                }
                        } else {
                                if ( $this->mFailFunction ) {
@@ -489,28 +477,42 @@ class LoadBalancer {
                                } else {
                                        $conn->failFunction( false );
                                }
-                               $conn->reportConnectionError( "{$this->mLastError} ({$conn->mServer})" );
+                               $server = $conn->getProperty( 'mServer' );
+                               $conn->reportConnectionError( "{$this->mLastError} ({$server})" );
                        }
                        $reporting = false;
                }
                wfProfileOut( $fname );
        }
 
-       function getWriterIndex()
-       {
+       function getWriterIndex() {
                return 0;
        }
 
-       function force( $i )
-       {
+       /**
+        * Force subsequent calls to getConnection(DB_SLAVE) to return the 
+        * given index. Set to -1 to restore the original load balancing
+        * behaviour. I thought this was a good idea when I originally 
+        * wrote this class, but it has never been used.
+        */
+       function force( $i ) {
                $this->mForce = $i;
        }
 
-       function haveIndex( $i )
-       {
+       /**
+        * Returns true if the specified index is a valid server index
+        */
+       function haveIndex( $i ) {
                return array_key_exists( $i, $this->mServers );
        }
 
+       /**
+        * Returns true if the specified index is valid and has non-zero load
+        */
+       function isNonZeroLoad( $i ) {
+               return array_key_exists( $i, $this->mServers ) && $this->mLoads[$i] != 0;
+       }
+
        /**
         * Get the number of defined servers (not the number of open connections)
         */