Revert r29671, it was based on a misunderstanding of the purpose of the LoggedOut...
[lhc/web/wiklou.git] / includes / LoadBalancer.php
index b9fda22..657bb2c 100644 (file)
@@ -95,7 +95,9 @@ class LoadBalancer {
                # Unset excessively lagged servers
                $lags = $this->getLagTimes();
                foreach ( $lags as $i => $lag ) {
-                       if ( isset( $this->mServers[$i]['max lag'] ) && $lag > $this->mServers[$i]['max lag'] ) {
+                       if ( $i != 0 && isset( $this->mServers[$i]['max lag'] ) && 
+                               ( $lag === false || $lag > $this->mServers[$i]['max lag'] ) ) 
+                       {
                                unset( $loads[$i] );
                        }
                }
@@ -240,53 +242,6 @@ class LoadBalancer {
                return $i;
        }
 
-       /**
-        * Get a connection to a foreign DB. Will use the following types of 
-        * connection in order of precedence:
-        *    * The alternate master, if there is one and DB_MASTER is given
-        *    * The query group
-        *    * The alternate master, if there is one
-        *    * The default writer, if DB_MASTER was specified
-        *    * The default reader. 
-        * 
-        * Connection error will *not* lead to progression down this list. Selection
-        * of a group depends only on configuration.
-        *
-        * @param string $dbName The database name
-        * @param mixed $group The query group, or DB_MASTER for the foreign master
-        * @return Database object with the database selected
-        */
-       function getForeignConnection( $dbName, $group = false ) {
-               global $wgAlternateMaster;
-
-               // Try cache
-               if ( isset( $this->mForeignConnections[$dbName][$group] ) ) {
-                       return $this->mForeignConnections[$dbName][$group];
-               }
-
-               // Try the precedence list described in the function description
-               if ( $group === DB_MASTER && isset( $wgAlternateMaster[$dbName] ) ) {
-                       $index = $this->mServers[$wgAlternateMaster[$dbName]];
-               } if ( $group && $group !== DB_MASTER ) {
-                       $index = $this->getGroupIndex( $group );
-               } elseif ( isset( $wgAlternateMaster[$dbName] ) ) {
-                       $index = $this->mServers[$wgAlternateMaster[$dbName]];
-               } elseif ( $group === DB_MASTER ) {
-                       $index = $this->getWriterIndex();
-               } else {
-                       $index = $this->getReaderIndex();
-               }
-
-               if ( $index === false || !isset( $this->mServers[$index] ) ) {
-                       throw new MWException( "No configured server available for foreign connection to $dbName" );
-               }
-
-               $dbInfo = $this->mServers[$index];
-               $dbc = $this->reallyOpenConnection( $dbInfo, $dbName );
-               $this->mForeignConnections[$dbName][$group] = $dbc;
-               return $dbc;
-       }
-
        /**
         * Set the master wait position
         * If a DB_SLAVE connection has been opened already, waits
@@ -369,13 +324,13 @@ class LoadBalancer {
 
                # Query groups
                if ( !is_array( $groups ) ) {
-                       $groupIndex = $this->getGroupIndex( $groups, $i );
+                       $groupIndex = $this->getGroupIndex( $groups );
                        if ( $groupIndex !== false ) {
                                $i = $groupIndex;
                        }
                } else {
                        foreach ( $groups as $group ) {
-                               $groupIndex = $this->getGroupIndex( $group, $i );
+                               $groupIndex = $this->getGroupIndex( $group );
                                if ( $groupIndex !== false ) {
                                        $i = $groupIndex;
                                        break;
@@ -462,15 +417,12 @@ class LoadBalancer {
         * Really opens a connection
         * @access private
         */
-       function reallyOpenConnection( &$server, $overrideDBname = false ) {
+       function reallyOpenConnection( &$server ) {
                if( !is_array( $server ) ) {
                        throw new MWException( 'You must update your load-balancing configuration. See DefaultSettings.php entry for $wgDBservers.' );
                }
 
                extract( $server );
-               if ( $overrideDBname ) {
-                       $dbname = $overrideDBname;
-               }
                # Get class for this database type
                $class = 'Database' . ucfirst( $type );
 
@@ -600,6 +552,17 @@ class LoadBalancer {
                        }
                }
        }
+       
+       /* Issue COMMIT only on master, only if queries were done on connection */
+       function commitMasterChanges() {
+               // Always 0, but who knows.. :)
+               $i = $this->getWriterIndex();
+               if (array_key_exists($i,$this->mConnections)) {
+                       if ($this->mConnections[$i]->lastQuery() != '') {
+                               $this->mConnections[$i]->immediateCommit();
+                       }
+               }
+       }
 
        function waitTimeout( $value = NULL ) {
                return wfSetVar( $this->mWaitTimeout, $value );
@@ -694,4 +657,4 @@ class LoadBalancer {
        }
 }
 
-?>
+