Merge "Revert "Show a "(blocked)" hint on Special:ListUsers/ActiveUsers""
[lhc/web/wiklou.git] / includes / db / LoadBalancer.php
index c40ac0c..46d24fc 100644 (file)
@@ -41,6 +41,7 @@ class LoadBalancer {
         *    servers           Required. Array of server info structures.
         *    masterWaitTimeout Replication lag wait timeout
         *    loadMonitor       Name of a class used to fetch server lag and load.
+        * @throws MWException
         */
        function __construct( $params ) {
                if ( !isset( $params['servers'] ) ) {
@@ -197,6 +198,7 @@ class LoadBalancer {
         * Side effect: opens connections to databases
         * @param $group bool
         * @param $wiki bool
+        * @throws MWException
         * @return bool|int|string
         */
        function getReaderIndex( $group = false, $wiki = false ) {
@@ -452,8 +454,9 @@ class LoadBalancer {
         *
         * @param $i Integer: server index
         * @param $groups Array: query groups
-        * @param $wiki String: wiki ID
+        * @param bool|string $wiki Wiki ID
         *
+        * @throws MWException
         * @return DatabaseBase
         */
        public function &getConnection( $i, $groups = array(), $wiki = false ) {
@@ -497,8 +500,8 @@ class LoadBalancer {
                        # Couldn't find a working server in getReaderIndex()?
                        if ( $i === false ) {
                                $this->mLastError = 'No working slave server: ' . $this->mLastError;
-                               $this->reportConnectionError( $this->mErrorConnection );
                                wfProfileOut( __METHOD__ );
+                               $this->reportConnectionError( $this->mErrorConnection );
                                return false;
                        }
                }
@@ -506,6 +509,7 @@ class LoadBalancer {
                # Now we have an explicit index into the servers array
                $conn = $this->openConnection( $i, $wiki );
                if ( !$conn ) {
+                       wfProfileOut( __METHOD__ );
                        $this->reportConnectionError( $this->mErrorConnection );
                }
 
@@ -519,6 +523,7 @@ class LoadBalancer {
         * the same number of times as getConnection() to work.
         *
         * @param DatabaseBase $conn
+        * @throws MWException
         */
        public function reuseConnection( $conn ) {
                $serverIndex = $conn->getLBInfo('serverIndex');
@@ -585,6 +590,7 @@ class LoadBalancer {
                        $server['serverIndex'] = $i;
                        $conn = $this->reallyOpenConnection( $server, false );
                        if ( $conn->isOpen() ) {
+                               wfDebug( "Connected to database $i at {$this->mServers[$i]['host']}\n" );
                                $this->mConns['local'][$i][0] = $conn;
                        } else {
                                wfDebug( "Failed to connect to database $i at {$this->mServers[$i]['host']}\n" );
@@ -690,6 +696,7 @@ class LoadBalancer {
         *
         * @param $server
         * @param $dbNameOverride bool
+        * @throws MWException
         * @return DatabaseBase
         */
        function reallyOpenConnection( $server, $dbNameOverride = false ) {
@@ -706,7 +713,6 @@ class LoadBalancer {
                }
 
                # Create object
-               wfDebug( "Connecting to $host $dbname...\n" );
                try {
                        $db = DatabaseBase::factory( $server['type'], $server );
                } catch ( DBConnectionError $e ) {
@@ -715,11 +721,6 @@ class LoadBalancer {
                        $db = $e->db;
                }
 
-               if ( $db->isOpen() ) {
-                       wfDebug( "Connected to $host $dbname.\n" );
-               } else {
-                       wfDebug( "Connection failed to $host $dbname.\n" );
-               }
                $db->setLBInfo( $server );
                if ( isset( $server['fakeSlaveLag'] ) ) {
                        $db->setFakeSlaveLag( $server['fakeSlaveLag'] );
@@ -735,8 +736,6 @@ class LoadBalancer {
         * @throws DBConnectionError
         */
        function reportConnectionError( &$conn ) {
-               wfProfileIn( __METHOD__ );
-
                if ( !is_object( $conn ) ) {
                        // No last connection, probably due to all servers being too busy
                        wfLogDBError( "LB failure with no last connection. Connection error: {$this->mLastError}\n" );
@@ -748,7 +747,6 @@ class LoadBalancer {
                        wfLogDBError( "Connection error: {$this->mLastError} ({$server})\n" );
                        $conn->reportConnectionError( "{$this->mLastError} ({$server})" );
                }
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -909,7 +907,9 @@ class LoadBalancer {
                foreach ( $this->mConns as $conns2 ) {
                        foreach ( $conns2 as $conns3 ) {
                                foreach ( $conns3 as $conn ) {
-                                       $conn->commit( __METHOD__ );
+                                       if ( $conn->trxLevel() ) {
+                                               $conn->commit( __METHOD__, 'flush' );
+                                       }
                                }
                        }
                }
@@ -926,8 +926,8 @@ class LoadBalancer {
                                continue;
                        }
                        foreach ( $conns2[$masterIndex] as $conn ) {
-                               if ( $conn->doneWrites() ) {
-                                       $conn->commit( __METHOD__ );
+                               if ( $conn->trxLevel() && $conn->doneWrites() ) {
+                                       $conn->commit( __METHOD__, 'flush' );
                                }
                        }
                }