Index: trunk/phase3/RELEASE-NOTES-1.18 |
— | — | @@ -177,8 +177,11 @@ |
178 | 178 | * (bug 29441) Expose CapitalLinks config in JS to allow modules to properly |
179 | 179 | handle titles on case-sensitive wikis. |
180 | 180 | * (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. |
183 | 186 | * Language codes in $wgDummyLanguageCodes are now excluded on localization |
184 | 187 | statistics (maintenance/language/transstat.php) |
185 | 188 | * (bug 29586) Make the (next 200) links on categories link directly to |
Index: trunk/phase3/includes/db/LoadBalancer.php |
— | — | @@ -929,7 +929,9 @@ |
930 | 930 | /** |
931 | 931 | * Get the hostname and lag time of the most-lagged slave. |
932 | 932 | * 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 | + * |
934 | 936 | * @param $wiki string Wiki ID, or false for the default database |
935 | 937 | * |
936 | 938 | * @return array ( host, max lag, index of max lagged host ) |
— | — | @@ -938,23 +940,25 @@ |
939 | 941 | $maxLag = -1; |
940 | 942 | $host = ''; |
941 | 943 | $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 | + } |
946 | 962 | } |
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 | | - } |
959 | 963 | } |
960 | 964 | return array( $host, $maxLag, $maxIndex ); |
961 | 965 | } |
— | — | @@ -972,8 +976,14 @@ |
973 | 977 | if ( isset( $this->mLagTimes ) ) { |
974 | 978 | return $this->mLagTimes; |
975 | 979 | } |
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 | + } |
978 | 988 | return $this->mLagTimes; |
979 | 989 | } |
980 | 990 | |
Index: trunk/phase3/includes/db/LoadMonitor.php |
— | — | @@ -106,6 +106,11 @@ |
107 | 107 | * @return array |
108 | 108 | */ |
109 | 109 | 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 | + |
110 | 115 | wfProfileIn( __METHOD__ ); |
111 | 116 | $expiry = 5; |
112 | 117 | $requestRate = 10; |
Index: trunk/phase3/includes/db/DatabaseMysql.php |
— | — | @@ -376,9 +376,9 @@ |
377 | 377 | return $this->mFakeSlaveLag; |
378 | 378 | } |
379 | 379 | |
380 | | - /*if ( version_compare( $this->getServerVersion(), '4.1.9', '>=' ) ) { |
| 380 | + if ( version_compare( $this->getServerVersion(), '4.1.9', '>=' ) ) { |
381 | 381 | return $this->getLagFromSlaveStatus(); |
382 | | - } else */{ |
| 382 | + } else { |
383 | 383 | return $this->getLagFromProcesslist(); |
384 | 384 | } |
385 | 385 | } |