r95648 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95647‎ | r95648 | r95649 >
Date:05:04, 29 August 2011
Author:tstarling
Status:ok
Tags:
Comment:
Further updates for r90643/r95647 in core and extensions. Fixed all callers of Database::getLag(), made them call a new function LoadBalancer::safeGetLag() instead, which doesn't cause fatal errors for non-replicated installations. The core updates are tested but the extension updates aren't.
Modified paths:
  • /trunk/extensions/ArchiveLinks/spider.php (modified) (history)
  • /trunk/extensions/CollabWatchlist/includes/SpecialCollabWatchlist.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php (modified) (history)
  • /trunk/extensions/InterwikiIntegration/SpecialInterwikiWatchlist.php (modified) (history)
  • /trunk/extensions/RefreshSpecial/RefreshSpecial.body.php (modified) (history)
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/db/LoadBalancer.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialContributions.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialDeletedContributions.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialWatchlist.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialContributions.php
@@ -167,7 +167,8 @@
168168 $wgOut->addWikiMsg( 'nocontribs', $target );
169169 } else {
170170 # Show a message about slave lag, if applicable
171 - if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
 171+ $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
 172+ if( $lag > 0 )
172173 $wgOut->showLagWarning( $lag );
173174
174175 $wgOut->addHTML(
Index: trunk/phase3/includes/specials/SpecialWatchlist.php
@@ -240,7 +240,7 @@
241241 }
242242
243243 # Show a message about slave lag, if applicable
244 - $lag = $dbr->getLag();
 244+ $lag = wfGetLB()->safeGetLag( $dbr );
245245 if( $lag > 0 ) {
246246 $output->showLagWarning( $lag );
247247 }
Index: trunk/phase3/includes/specials/SpecialDeletedContributions.php
@@ -317,7 +317,8 @@
318318 }
319319
320320 # Show a message about slave lag, if applicable
321 - if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
 321+ $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
 322+ if( $lag > 0 )
322323 $wgOut->showLagWarning( $lag );
323324
324325 $wgOut->addHTML(
Index: trunk/phase3/includes/db/Database.php
@@ -2980,8 +2980,12 @@
29812981 }
29822982
29832983 /**
2984 - * Get slave lag.
2985 - * Currently supported only by MySQL
 2984+ * Get slave lag. Currently supported only by MySQL.
 2985+ *
 2986+ * Note that this function will generate a fatal error on many
 2987+ * installations. Most callers should use LoadBalancer::safeGetLag()
 2988+ * instead.
 2989+ *
29862990 * @return Database replication lag in seconds
29872991 */
29882992 function getLag() {
Index: trunk/phase3/includes/db/LoadBalancer.php
@@ -988,6 +988,25 @@
989989 }
990990
991991 /**
 992+ * Get the lag in seconds for a given connection, or zero if this load
 993+ * balancer does not have replication enabled.
 994+ *
 995+ * This should be used in preference to Database::getLag() in cases where
 996+ * replication may not be in use, since there is no way to determine if
 997+ * replication is in use at the connection level without running
 998+ * potentially restricted queries such as SHOW SLAVE STATUS. Using this
 999+ * function instead of Database::getLag() avoids a fatal error in this
 1000+ * case on many installations.
 1001+ */
 1002+ function safeGetLag( $conn ) {
 1003+ if ( $this->getServerCount() == 1 ) {
 1004+ return 0;
 1005+ } else {
 1006+ return $conn->getLag();
 1007+ }
 1008+ }
 1009+
 1010+ /**
9921011 * Clear the cache for getLagTimes
9931012 */
9941013 function clearLagTimeCache() {
Index: trunk/extensions/CollabWatchlist/includes/SpecialCollabWatchlist.php
@@ -226,7 +226,8 @@
227227 }
228228
229229 # Show a message about slave lag, if applicable
230 - if ( ( $lag = $dbr->getLag() ) > 0 )
 230+ $lag = wfGetLB()->safeGetLag( $dbr );
 231+ if ( $lag > 0 )
231232 $wgOut->showLagWarning( $lag );
232233
233234 # Create output form
Index: trunk/extensions/RefreshSpecial/RefreshSpecial.body.php
@@ -241,7 +241,7 @@
242242
243243 # Wait for the slave to catch up
244244 $slaveDB = wfGetDB( DB_SLAVE, array( 'QueryPage::recache', 'vslow' ) );
245 - while( $slaveDB->getLag() > REFRESHSPECIAL_SLAVE_LAG_LIMIT ) {
 245+ while( wfGetLB()->safeGetLag( $slaveDB ) > REFRESHSPECIAL_SLAVE_LAG_LIMIT ) {
246246 $wgOut->addHTML( wfMsg( 'refreshspecial-slave-lagged' ) . '<br />' );
247247 sleep( REFRESHSPECIAL_SLAVE_LAG_SLEEP );
248248 }
@@ -290,4 +290,4 @@
291291 $link_back = $sk->makeKnownLinkObj( $titleObj, wfMsg( 'refreshspecial-link-back' ) );
292292 $wgOut->addHTML( '<br /><b>' . $link_back . '</b>' );
293293 }
294 -}
\ No newline at end of file
 294+}
Index: trunk/extensions/ArchiveLinks/spider.php
@@ -207,7 +207,7 @@
208208
209209 $this->jobs = array();
210210
211 - $wait_time = $this->db_slave->getLag() * 3;
 211+ $wait_time = wfGetLB()->safeGetLag( $this->db_slave ) * 3;
212212 $pid = (string) microtime() . ' - ' . getmypid();
213213 $time = time();
214214
@@ -371,4 +371,4 @@
372372 }
373373
374374 $maintClass = 'ArchiveLinksSpider';
375 -require_once RUN_MAINTENANCE_IF_MAIN;
\ No newline at end of file
 375+require_once RUN_MAINTENANCE_IF_MAIN;
Index: trunk/extensions/InterwikiIntegration/SpecialInterwikiWatchlist.php
@@ -222,7 +222,8 @@
223223 }
224224
225225 # Show a message about slave lag, if applicable
226 - if( ( $lag = $dbr->getLag() ) > 0 )
 226+ $lag = wfGetLB()->safeGetLag( $dbr );
 227+ if( $lag > 0 )
227228 $wgOut->showLagWarning( $lag );
228229
229230 # Create output form
Index: trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php
@@ -704,7 +704,7 @@
705705 # Update page sync status for tracking purposes.
706706 # NOTE: avoids master hits and doesn't have to be perfect for what it does
707707 if ( $this->article->syncedInTracking() != $synced ) {
708 - if ( wfGetDB( DB_SLAVE )->getLag() <= 5 ) { // avoid write-delay cycles
 708+ if ( wfGetLB()->safeGetLag( wfGetDB( DB_SLAVE ) ) <= 5 ) { // avoid write-delay cycles
709709 $this->article->updateSyncStatus( $synced );
710710 }
711711 }

Follow-up revisions

RevisionCommit summaryAuthorDate
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
r95647* Fix for r90643: in the case where there is only one server, implying no rep...tstarling04:42, 29 August 2011

Status & tagging log