Merge "Apparently for certain (API) requests $this->getTitle() doesn't return a valid...
[lhc/web/wiklou.git] / includes / db / LoadBalancer.php
index de4c2f5..ee35c13 100644 (file)
@@ -45,7 +45,6 @@ class LoadBalancer {
        /**
         * @param array $params with keys:
         *   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
         */
@@ -54,12 +53,7 @@ class LoadBalancer {
                        throw new MWException( __CLASS__ . ': missing servers parameter' );
                }
                $this->mServers = $params['servers'];
-
-               if ( isset( $params['waitTimeout'] ) ) {
-                       $this->mWaitTimeout = $params['waitTimeout'];
-               } else {
-                       $this->mWaitTimeout = 10;
-               }
+               $this->mWaitTimeout = 10;
 
                $this->mReadIndex = -1;
                $this->mWriteIndex = -1;
@@ -113,7 +107,7 @@ class LoadBalancer {
 
        /**
         * Get or set arbitrary data used by the parent object, usually an LBFactory
-        * @param $x
+        * @param mixed $x
         * @return mixed
         */
        function parentInfo( $x = null ) {
@@ -369,8 +363,8 @@ class LoadBalancer {
 
        /**
         * Wait for a given slave to catch up to the master pos stored in $this
-        * @param $index
-        * @param $open bool
+        * @param int $index
+        * @param bool $open
         * @return bool
         */
        protected function doWait( $index, $open = false ) {
@@ -410,8 +404,8 @@ class LoadBalancer {
         * Get a connection by index
         * This is the main entry point for this class.
         *
-        * @param $i Integer: server index
-        * @param array $groups query groups
+        * @param int $i Server index
+        * @param array $groups Query groups
         * @param bool|string $wiki Wiki ID
         *
         * @throws MWException
@@ -538,7 +532,7 @@ class LoadBalancer {
         *
         * @see LoadBalancer::getConnection() for parameter information
         *
-        * @param integer $db
+        * @param int $db
         * @param mixed $groups
         * @param bool|string $wiki
         * @return DBConnRef
@@ -554,7 +548,7 @@ class LoadBalancer {
         *
         * @see LoadBalancer::getConnection() for parameter information
         *
-        * @param integer $db
+        * @param int $db
         * @param mixed $groups
         * @param bool|string $wiki
         * @return DBConnRef
@@ -571,8 +565,8 @@ class LoadBalancer {
         * On error, returns false, and the connection which caused the
         * error will be available via $this->mErrorConnection.
         *
-        * @param $i Integer server index
-        * @param bool|string $wiki wiki ID to open
+        * @param int $i Server index
+        * @param bool|string $wiki Wiki ID to open
         * @return DatabaseBase
         *
         * @access private
@@ -619,8 +613,8 @@ class LoadBalancer {
         * On error, returns false, and the connection which caused the
         * error will be available via $this->mErrorConnection.
         *
-        * @param $i Integer: server index
-        * @param string $wiki wiki ID to open
+        * @param int $i Server index
+        * @param string $wiki Wiki ID to open
         * @return DatabaseBase
         */
        function openForeignConnection( $i, $wiki ) {
@@ -683,7 +677,7 @@ class LoadBalancer {
        /**
         * Test if the specified index represents an open connection
         *
-        * @param $index Integer: server index
+        * @param int $index Server index
         * @access private
         * @return bool
         */
@@ -700,8 +694,8 @@ class LoadBalancer {
         * Returns a Database object whether or not the connection was successful.
         * @access private
         *
-        * @param $server
-        * @param $dbNameOverride bool
+        * @param array $server
+        * @param bool $dbNameOverride
         * @throws MWException
         * @return DatabaseBase
         */
@@ -744,13 +738,13 @@ class LoadBalancer {
 
                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" );
+                       wfLogDBError( "LB failure with no last connection. Connection error: {$this->mLastError}" );
 
                        // If all servers were busy, mLastError will contain something sensible
                        throw new DBConnectionError( null, $this->mLastError );
                } else {
                        $server = $conn->getProperty( 'mServer' );
-                       wfLogDBError( "Connection error: {$this->mLastError} ({$server})\n" );
+                       wfLogDBError( "Connection error: {$this->mLastError} ({$server})" );
                        $conn->reportConnectionError( "{$this->mLastError} ({$server})" ); // throws DBConnectionError
                }
 
@@ -811,8 +805,8 @@ class LoadBalancer {
 
        /**
         * Return the server info structure for a given index, or false if the index is invalid.
-        * @param $i
-        * @return bool
+        * @param int $i
+        * @return array|bool
         */
        function getServerInfo( $i ) {
                if ( isset( $this->mServers[$i] ) ) {
@@ -825,8 +819,8 @@ class LoadBalancer {
        /**
         * Sets the server info structure for the given index. Entry at index $i
         * is created if it doesn't exist
-        * @param $i
-        * @param $serverInfo
+        * @param int $i
+        * @param array $serverInfo
         */
        function setServerInfo( $i, $serverInfo ) {
                $this->mServers[$i] = $serverInfo;
@@ -881,7 +875,7 @@ class LoadBalancer {
        /**
         * Deprecated function, typo in function name
         *
-        * @deprecated in 1.18
+        * @deprecated since 1.18
         * @param DatabaseBase $conn
         */
        function closeConnecton( $conn ) {
@@ -950,8 +944,51 @@ class LoadBalancer {
        }
 
        /**
-        * @param $value null
-        * @return Mixed
+        * Issue ROLLBACK only on master, only if queries were done on connection
+        * @since 1.23
+        */
+       function rollbackMasterChanges() {
+               // Always 0, but who knows.. :)
+               $masterIndex = $this->getWriterIndex();
+               foreach ( $this->mConns as $conns2 ) {
+                       if ( empty( $conns2[$masterIndex] ) ) {
+                               continue;
+                       }
+                       /** @var DatabaseBase $conn */
+                       foreach ( $conns2[$masterIndex] as $conn ) {
+                               if ( $conn->trxLevel() && $conn->writesOrCallbacksPending() ) {
+                                       $conn->rollback( __METHOD__, 'flush' );
+                               }
+                       }
+               }
+       }
+
+       /**
+        * Determine if there are any pending changes that need to be rolled back
+        * or committed.
+        * @since 1.23
+        * @return bool
+        */
+       function hasMasterChanges() {
+               // Always 0, but who knows.. :)
+               $masterIndex = $this->getWriterIndex();
+               foreach ( $this->mConns as $conns2 ) {
+                       if ( empty( $conns2[$masterIndex] ) ) {
+                               continue;
+                       }
+                       /** @var DatabaseBase $conn */
+                       foreach ( $conns2[$masterIndex] as $conn ) {
+                               if ( $conn->trxLevel() && $conn->writesOrCallbacksPending() ) {
+                                       return true;
+                               }
+                       }
+               }
+               return false;
+       }
+
+       /**
+        * @param mixed $value
+        * @return mixed
         */
        function waitTimeout( $value = null ) {
                return wfSetVar( $this->mWaitTimeout, $value );