Merge "Avoid repeat of class name when appending in Linker"
[lhc/web/wiklou.git] / includes / db / LoadBalancer.php
index 011c083..9967cc0 100644 (file)
@@ -101,6 +101,7 @@ class LoadBalancer {
                        $class = $this->mLoadMonitorClass;
                        $this->mLoadMonitor = new $class( $this );
                }
+
                return $this->mLoadMonitor;
        }
 
@@ -212,6 +213,7 @@ class LoadBalancer {
                                # No loads for this group, return false and the caller can use some other group
                                wfDebug( __METHOD__ . ": no loads for group $group\n" );
                                wfProfileOut( __METHOD__ );
+
                                return false;
                        }
                } else {
@@ -255,6 +257,7 @@ class LoadBalancer {
                                        # wants us to return false.
                                        wfDebugLog( 'connect', __METHOD__ . ": pickRandom() returned false\n" );
                                        wfProfileOut( __METHOD__ );
+
                                        return false;
                                }
 
@@ -329,6 +332,7 @@ class LoadBalancer {
                        }
                }
                wfProfileOut( __METHOD__ );
+
                return $i;
        }
 
@@ -342,6 +346,7 @@ class LoadBalancer {
                wfDebug( __METHOD__ . ": waiting $t us\n" );
                usleep( $t );
                wfProfileOut( __METHOD__ );
+
                return $t;
        }
 
@@ -372,7 +377,8 @@ class LoadBalancer {
        public function waitForAll( $pos ) {
                wfProfileIn( __METHOD__ );
                $this->mWaitForPos = $pos;
-               for ( $i = 1; $i < count( $this->mServers ); $i++ ) {
+               $serverCount = count( $this->mServers );
+               for ( $i = 1; $i < $serverCount; $i++ ) {
                        if ( $this->mLoads[$i] > 0 ) {
                                $this->doWait( $i, true );
                        }
@@ -393,6 +399,7 @@ class LoadBalancer {
                                return reset( $conns[$i] );
                        }
                }
+
                return false;
        }
 
@@ -408,11 +415,13 @@ class LoadBalancer {
                if ( !$conn ) {
                        if ( !$open ) {
                                wfDebug( __METHOD__ . ": no connection open\n" );
+
                                return false;
                        } else {
                                $conn = $this->openConnection( $index, '' );
                                if ( !$conn ) {
                                        wfDebug( __METHOD__ . ": failed to open connection\n" );
+
                                        return false;
                                }
                        }
@@ -424,9 +433,11 @@ class LoadBalancer {
                if ( $result == -1 || is_null( $result ) ) {
                        # Timed out waiting for slave, use master instead
                        wfDebug( __METHOD__ . ": Timed out waiting for slave #$index pos {$this->mWaitForPos}\n" );
+
                        return false;
                } else {
                        wfDebug( __METHOD__ . ": Done\n" );
+
                        return true;
                }
        }
@@ -447,10 +458,12 @@ class LoadBalancer {
 
                if ( $i == DB_LAST ) {
                        wfProfileOut( __METHOD__ );
-                       throw new MWException( 'Attempt to call ' . __METHOD__ . ' with deprecated server index DB_LAST' );
+                       throw new MWException( 'Attempt to call ' . __METHOD__ .
+                               ' with deprecated server index DB_LAST' );
                } elseif ( $i === null || $i === false ) {
                        wfProfileOut( __METHOD__ );
-                       throw new MWException( 'Attempt to call ' . __METHOD__ . ' with invalid server index' );
+                       throw new MWException( 'Attempt to call ' . __METHOD__ .
+                               ' with invalid server index' );
                }
 
                if ( $wiki === wfWikiID() ) {
@@ -487,6 +500,7 @@ class LoadBalancer {
                        if ( $i === false ) {
                                $this->mLastError = 'No working slave server: ' . $this->mLastError;
                                wfProfileOut( __METHOD__ );
+
                                return $this->reportConnectionError();
                        }
                }
@@ -495,10 +509,12 @@ class LoadBalancer {
                $conn = $this->openConnection( $i, $wiki );
                if ( !$conn ) {
                        wfProfileOut( __METHOD__ );
+
                        return $this->reportConnectionError();
                }
 
                wfProfileOut( __METHOD__ );
+
                return $conn;
        }
 
@@ -522,6 +538,7 @@ class LoadBalancer {
                }
                if ( $serverIndex === null || $refCount === null ) {
                        wfDebug( __METHOD__ . ": this connection was not opened as a foreign connection\n" );
+
                        /**
                         * This can happen in code like:
                         *   foreach ( $dbs as $db ) {
@@ -532,10 +549,12 @@ class LoadBalancer {
                         * When a connection to the local DB is opened in this way, reuseConnection()
                         * should be ignored
                         */
+
                        return;
                }
                if ( $this->mConns['foreignUsed'][$serverIndex][$wiki] !== $conn ) {
-                       throw new MWException( __METHOD__ . ": connection not found, has the connection been freed already?" );
+                       throw new MWException( __METHOD__ . ": connection not found, has " .
+                               "the connection been freed already?" );
                }
                $conn->setLBInfo( 'foreignPoolRefCount', --$refCount );
                if ( $refCount <= 0 ) {
@@ -598,6 +617,7 @@ class LoadBalancer {
                if ( $wiki !== false ) {
                        $conn = $this->openForeignConnection( $i, $wiki );
                        wfProfileOut( __METHOD__ );
+
                        return $conn;
                }
                if ( isset( $this->mConns['local'][$i][0] ) ) {
@@ -616,6 +636,7 @@ class LoadBalancer {
                        }
                }
                wfProfileOut( __METHOD__ );
+
                return $conn;
        }
 
@@ -690,6 +711,7 @@ class LoadBalancer {
                        $conn->setLBInfo( 'foreignPoolRefCount', $refCount + 1 );
                }
                wfProfileOut( __METHOD__ );
+
                return $conn;
        }
 
@@ -704,6 +726,7 @@ class LoadBalancer {
                if ( !is_integer( $index ) ) {
                        return false;
                }
+
                return (bool)$this->getAnyOpenConnection( $index );
        }
 
@@ -743,6 +766,7 @@ class LoadBalancer {
                if ( isset( $server['fakeMaster'] ) ) {
                        $db->setFakeMaster( true );
                }
+
                return $db;
        }
 
@@ -764,6 +788,7 @@ class LoadBalancer {
                        wfLogDBError( "Connection error: {$this->mLastError} ({$server})\n" );
                        $conn->reportConnectionError( "{$this->mLastError} ({$server})" ); // throws DBConnectionError
                }
+
                return false; /* not reached */
        }
 
@@ -833,7 +858,8 @@ class LoadBalancer {
        }
 
        /**
-        * Sets the server info structure for the given index. Entry at index $i is created if it doesn't exist
+        * Sets the server info structure for the given index. Entry at index $i
+        * is created if it doesn't exist
         * @param $i
         * @param $serverInfo
         */
@@ -850,17 +876,21 @@ class LoadBalancer {
                # master (however unlikely that may be), then we can fetch the position from the slave.
                $masterConn = $this->getAnyOpenConnection( 0 );
                if ( !$masterConn ) {
-                       for ( $i = 1; $i < count( $this->mServers ); $i++ ) {
+                       $serverCount = count( $this->mServers );
+                       for ( $i = 1; $i < $serverCount; $i++ ) {
                                $conn = $this->getAnyOpenConnection( $i );
                                if ( $conn ) {
                                        wfDebug( "Master pos fetched from slave\n" );
+
                                        return $conn->getSlavePos();
                                }
                        }
                } else {
                        wfDebug( "Master pos fetched from master\n" );
+
                        return $masterConn->getMasterPos();
                }
+
                return false;
        }
 
@@ -976,6 +1006,7 @@ class LoadBalancer {
                        return $this->mAllowLagged;
                }
                $this->mAllowLagged = $mode;
+
                return $this->mAllowLagged;
        }
 
@@ -993,6 +1024,7 @@ class LoadBalancer {
                                }
                        }
                }
+
                return $success;
        }
 
@@ -1046,6 +1078,7 @@ class LoadBalancer {
                                }
                        }
                }
+
                return array( $host, $maxLag, $maxIndex );
        }
 
@@ -1070,6 +1103,7 @@ class LoadBalancer {
                        $this->mLagTimes = $this->getLoadMonitor()->getLagTimes(
                                array_keys( $this->mServers ), $wiki );
                }
+
                return $this->mLagTimes;
        }
 
@@ -1137,6 +1171,7 @@ class DBConnRef implements IDatabase {
                        list( $db, $groups, $wiki ) = $this->params;
                        $this->conn = $this->lb->getConnection( $db, $groups, $wiki );
                }
+
                return call_user_func_array( array( $this->conn, $name ), $arguments );
        }