r95647 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95646‎ | r95647 | r95648 >
Date:04:42, 29 August 2011
Author:tstarling
Status:ok (Comments)
Tags:
Comment:
* 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.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.18 (modified) (history)
  • /trunk/phase3/includes/db/DatabaseMysql.php (modified) (history)
  • /trunk/phase3/includes/db/LoadBalancer.php (modified) (history)
  • /trunk/phase3/includes/db/LoadMonitor.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.18
@@ -177,8 +177,11 @@
178178 * (bug 29441) Expose CapitalLinks config in JS to allow modules to properly
179179 handle titles on case-sensitive wikis.
180180 * (bug 29397) Implement mw.Title module in core.
181 -* In MySQL 4.1.9+ with replication enabled, the slave lag should come from
182 - SHOW SLAVE STATUS instead of SHOW PROCESSLIST.
 181+* In MySQL 4.1.9+ with replication enabled, fetch the slave lag from SHOW SLAVE
 182+ STATUS instead of SHOW PROCESSLIST. This ensures that lag is reported
 183+ correctly in the case where there are no write events occurring. Note that
 184+ the DB user now needs to have the REPLICATION CLIENT privilege if you are
 185+ using replication.
183186 * Language codes in $wgDummyLanguageCodes are now excluded on localization
184187 statistics (maintenance/language/transstat.php)
185188 * (bug 29586) Make the (next 200) links on categories link directly to
Index: trunk/phase3/includes/db/LoadBalancer.php
@@ -929,7 +929,9 @@
930930 /**
931931 * Get the hostname and lag time of the most-lagged slave.
932932 * This is useful for maintenance scripts that need to throttle their updates.
933 - * May attempt to open connections to slaves on the default DB.
 933+ * May attempt to open connections to slaves on the default DB. If there is
 934+ * no lag, the maximum lag will be reported as -1.
 935+ *
934936 * @param $wiki string Wiki ID, or false for the default database
935937 *
936938 * @return array ( host, max lag, index of max lagged host )
@@ -938,23 +940,25 @@
939941 $maxLag = -1;
940942 $host = '';
941943 $maxIndex = 0;
942 - foreach ( $this->mServers as $i => $conn ) {
943 - $conn = false;
944 - if ( $wiki === false ) {
945 - $conn = $this->getAnyOpenConnection( $i );
 944+ if ( $this->getServerCount() > 1 ) { // no replication = no lag
 945+ foreach ( $this->mServers as $i => $conn ) {
 946+ $conn = false;
 947+ if ( $wiki === false ) {
 948+ $conn = $this->getAnyOpenConnection( $i );
 949+ }
 950+ if ( !$conn ) {
 951+ $conn = $this->openConnection( $i, $wiki );
 952+ }
 953+ if ( !$conn ) {
 954+ continue;
 955+ }
 956+ $lag = $conn->getLag();
 957+ if ( $lag > $maxLag ) {
 958+ $maxLag = $lag;
 959+ $host = $this->mServers[$i]['host'];
 960+ $maxIndex = $i;
 961+ }
946962 }
947 - if ( !$conn ) {
948 - $conn = $this->openConnection( $i, $wiki );
949 - }
950 - if ( !$conn ) {
951 - continue;
952 - }
953 - $lag = $conn->getLag();
954 - if ( $lag > $maxLag ) {
955 - $maxLag = $lag;
956 - $host = $this->mServers[$i]['host'];
957 - $maxIndex = $i;
958 - }
959963 }
960964 return array( $host, $maxLag, $maxIndex );
961965 }
@@ -972,8 +976,14 @@
973977 if ( isset( $this->mLagTimes ) ) {
974978 return $this->mLagTimes;
975979 }
976 - # No, send the request to the load monitor
977 - $this->mLagTimes = $this->getLoadMonitor()->getLagTimes( array_keys( $this->mServers ), $wiki );
 980+ if ( $this->getServerCount() == 1 ) {
 981+ # No replication
 982+ $this->mLagTimes = array( 0 => 0 );
 983+ } else {
 984+ # Send the request to the load monitor
 985+ $this->mLagTimes = $this->getLoadMonitor()->getLagTimes(
 986+ array_keys( $this->mServers ), $wiki );
 987+ }
978988 return $this->mLagTimes;
979989 }
980990
Index: trunk/phase3/includes/db/LoadMonitor.php
@@ -106,6 +106,11 @@
107107 * @return array
108108 */
109109 function getLagTimes( $serverIndexes, $wiki ) {
 110+ if ( count( $serverIndexes ) == 1 && reset( $serverIndexes ) == 0 ) {
 111+ // Single server only, just return zero without caching
 112+ return array( 0 => 0 );
 113+ }
 114+
110115 wfProfileIn( __METHOD__ );
111116 $expiry = 5;
112117 $requestRate = 10;
Index: trunk/phase3/includes/db/DatabaseMysql.php
@@ -376,9 +376,9 @@
377377 return $this->mFakeSlaveLag;
378378 }
379379
380 - /*if ( version_compare( $this->getServerVersion(), '4.1.9', '>=' ) ) {
 380+ if ( version_compare( $this->getServerVersion(), '4.1.9', '>=' ) ) {
381381 return $this->getLagFromSlaveStatus();
382 - } else */{
 382+ } else {
383383 return $this->getLagFromProcesslist();
384384 }
385385 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r95648Further updates for r90643/r95647 in core and extensions. Fixed all callers o...tstarling05:04, 29 August 2011
r965081.18: MFT r95562, r95570, r95597, r95608, r95647, r95648, r95674, r95790, r95...catrope21:56, 7 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r90643General database-related code cleanup:...tstarling03:14, 23 June 2011
r90773Hack followup to r90643...reedy16:30, 25 June 2011

Comments

#Comment by Tim Starling (talk | contribs)   05:07, 29 August 2011

This has to either be backported to 1.18 (with r95648), or the release notes have to be fixed for r90773.

Status & tagging log