Merge "Revert "Show a "(blocked)" hint on Special:ListUsers/ActiveUsers""
[lhc/web/wiklou.git] / includes / db / LoadBalancer.php
index d635645..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');
@@ -691,6 +696,7 @@ class LoadBalancer {
         *
         * @param $server
         * @param $dbNameOverride bool
+        * @throws MWException
         * @return DatabaseBase
         */
        function reallyOpenConnection( $server, $dbNameOverride = false ) {
@@ -730,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" );
@@ -743,7 +747,6 @@ class LoadBalancer {
                        wfLogDBError( "Connection error: {$this->mLastError} ({$server})\n" );
                        $conn->reportConnectionError( "{$this->mLastError} ({$server})" );
                }
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -904,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' );
+                                       }
                                }
                        }
                }
@@ -922,7 +927,7 @@ class LoadBalancer {
                        }
                        foreach ( $conns2[$masterIndex] as $conn ) {
                                if ( $conn->trxLevel() && $conn->doneWrites() ) {
-                                       $conn->commit( __METHOD__ );
+                                       $conn->commit( __METHOD__, 'flush' );
                                }
                        }
                }