From: Tim Starling Date: Mon, 29 Aug 2011 04:42:26 +0000 (+0000) Subject: * Fix for r90643: in the case where there is only one server, implying no replication... X-Git-Tag: 1.31.0-rc.0~28031 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22suivi_revisions%22%29%20.%20%22?a=commitdiff_plain;h=a3bf5ecb4a775cc319f0f26ab39a3dec350af846;p=lhc%2Fweb%2Fwiklou.git * Fix for r90643: in the case where there is only one server, implying no replication, make LoadBalancer::getLagTimes(), LoadMonitor_MySQL::getLagTimes() and LoadBalancer::getMaxLag() quickly report zero lag without attempting to do a SHOW SLAVE STATUS query. * Updated the documentation to make it clear that REPLICATION CLIENT is required in a replicated setup. * Reverted r90773. --- diff --git a/RELEASE-NOTES-1.18 b/RELEASE-NOTES-1.18 index c53d9b8d86..b1845f7fa2 100644 --- a/RELEASE-NOTES-1.18 +++ b/RELEASE-NOTES-1.18 @@ -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 diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php index 53adea11e0..314b6edd8b 100644 --- a/includes/db/DatabaseMysql.php +++ b/includes/db/DatabaseMysql.php @@ -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(); } } diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php index 506ceb98bb..55a6cee772 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -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; } diff --git a/includes/db/LoadMonitor.php b/includes/db/LoadMonitor.php index 226036ad9a..a6370c9e03 100644 --- a/includes/db/LoadMonitor.php +++ b/includes/db/LoadMonitor.php @@ -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;