* Fix for r90643: in the case where there is only one server, implying no replication...
authorTim Starling <tstarling@users.mediawiki.org>
Mon, 29 Aug 2011 04:42:26 +0000 (04:42 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Mon, 29 Aug 2011 04:42:26 +0000 (04:42 +0000)
* Updated the documentation to make it clear that REPLICATION CLIENT is required in a replicated setup.
* Reverted r90773.

RELEASE-NOTES-1.18
includes/db/DatabaseMysql.php
includes/db/LoadBalancer.php
includes/db/LoadMonitor.php

index c53d9b8..b1845f7 100644 (file)
@@ -177,8 +177,11 @@ production.
 * (bug 29441) Expose CapitalLinks config in JS to allow modules to properly
   handle titles on case-sensitive wikis.
 * (bug 29397) Implement mw.Title module in core.
-* In MySQL 4.1.9+ with replication enabled, the slave lag should come from
-  SHOW SLAVE STATUS instead of SHOW PROCESSLIST.
+* In MySQL 4.1.9+ with replication enabled, fetch the slave lag from SHOW SLAVE 
+  STATUS instead of SHOW PROCESSLIST. This ensures that lag is reported 
+  correctly in the case where there are no write events occurring. Note that 
+  the DB user now needs to have the REPLICATION CLIENT privilege if you are 
+  using replication.
 * Language codes in $wgDummyLanguageCodes are now excluded on localization
   statistics (maintenance/language/transstat.php)
 * (bug 29586) Make the (next 200) links on categories link directly to
index 53adea1..314b6ed 100644 (file)
@@ -376,9 +376,9 @@ class DatabaseMysql extends DatabaseBase {
                        return $this->mFakeSlaveLag;
                }
 
-               /*if ( version_compare( $this->getServerVersion(), '4.1.9', '>=' ) ) {
+               if ( version_compare( $this->getServerVersion(), '4.1.9', '>=' ) ) {
                        return $this->getLagFromSlaveStatus();
-               } else */{
+               } else {
                        return $this->getLagFromProcesslist();
                }
        }
index 506ceb9..55a6cee 100644 (file)
@@ -929,7 +929,9 @@ class LoadBalancer {
        /**
         * Get the hostname and lag time of the most-lagged slave.
         * This is useful for maintenance scripts that need to throttle their updates.
-        * May attempt to open connections to slaves on the default DB.
+        * May attempt to open connections to slaves on the default DB. If there is 
+        * no lag, the maximum lag will be reported as -1.
+        *
         * @param $wiki string Wiki ID, or false for the default database
         *
         * @return array ( host, max lag, index of max lagged host )
@@ -938,22 +940,24 @@ class LoadBalancer {
                $maxLag = -1;
                $host = '';
                $maxIndex = 0;
-               foreach ( $this->mServers as $i => $conn ) {
-                       $conn = false;
-                       if ( $wiki === false ) {
-                               $conn = $this->getAnyOpenConnection( $i );
-                       }
-                       if ( !$conn ) {
-                               $conn = $this->openConnection( $i, $wiki );
-                       }
-                       if ( !$conn ) {
-                               continue;
-                       }
-                       $lag = $conn->getLag();
-                       if ( $lag > $maxLag ) {
-                               $maxLag = $lag;
-                               $host = $this->mServers[$i]['host'];
-                               $maxIndex = $i;
+               if ( $this->getServerCount() > 1 ) { // no replication = no lag
+                       foreach ( $this->mServers as $i => $conn ) {
+                               $conn = false;
+                               if ( $wiki === false ) {
+                                       $conn = $this->getAnyOpenConnection( $i );
+                               }
+                               if ( !$conn ) {
+                                       $conn = $this->openConnection( $i, $wiki );
+                               }
+                               if ( !$conn ) {
+                                       continue;
+                               }
+                               $lag = $conn->getLag();
+                               if ( $lag > $maxLag ) {
+                                       $maxLag = $lag;
+                                       $host = $this->mServers[$i]['host'];
+                                       $maxIndex = $i;
+                               }
                        }
                }
                return array( $host, $maxLag, $maxIndex );
@@ -972,8 +976,14 @@ class LoadBalancer {
                if ( isset( $this->mLagTimes ) ) {
                        return $this->mLagTimes;
                }
-               # No, send the request to the load monitor
-               $this->mLagTimes = $this->getLoadMonitor()->getLagTimes( array_keys( $this->mServers ), $wiki );
+               if ( $this->getServerCount() == 1 ) {
+                       # No replication
+                       $this->mLagTimes = array( 0 => 0 );
+               } else {
+                       # Send the request to the load monitor
+                       $this->mLagTimes = $this->getLoadMonitor()->getLagTimes( 
+                               array_keys( $this->mServers ), $wiki );
+               }
                return $this->mLagTimes;
        }
 
index 226036a..a6370c9 100644 (file)
@@ -106,6 +106,11 @@ class LoadMonitor_MySQL implements LoadMonitor {
         * @return array
         */
        function getLagTimes( $serverIndexes, $wiki ) {
+               if ( count( $serverIndexes ) == 1 && reset( $serverIndexes ) == 0 ) {
+                       // Single server only, just return zero without caching
+                       return array( 0 => 0 );
+               }
+
                wfProfileIn( __METHOD__ );
                $expiry = 5;
                $requestRate = 10;