| Index: trunk/phase3/includes/specials/SpecialContributions.php |
| — | — | @@ -167,7 +167,8 @@ |
| 168 | 168 | $wgOut->addWikiMsg( 'nocontribs', $target ); |
| 169 | 169 | } else { |
| 170 | 170 | # 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 ) |
| 172 | 173 | $wgOut->showLagWarning( $lag ); |
| 173 | 174 | |
| 174 | 175 | $wgOut->addHTML( |
| Index: trunk/phase3/includes/specials/SpecialWatchlist.php |
| — | — | @@ -240,7 +240,7 @@ |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | # Show a message about slave lag, if applicable |
| 244 | | - $lag = $dbr->getLag(); |
| | 244 | + $lag = wfGetLB()->safeGetLag( $dbr ); |
| 245 | 245 | if( $lag > 0 ) { |
| 246 | 246 | $output->showLagWarning( $lag ); |
| 247 | 247 | } |
| Index: trunk/phase3/includes/specials/SpecialDeletedContributions.php |
| — | — | @@ -317,7 +317,8 @@ |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | # 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 ) |
| 322 | 323 | $wgOut->showLagWarning( $lag ); |
| 323 | 324 | |
| 324 | 325 | $wgOut->addHTML( |
| Index: trunk/phase3/includes/db/Database.php |
| — | — | @@ -2980,8 +2980,12 @@ |
| 2981 | 2981 | } |
| 2982 | 2982 | |
| 2983 | 2983 | /** |
| 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 | + * |
| 2986 | 2990 | * @return Database replication lag in seconds |
| 2987 | 2991 | */ |
| 2988 | 2992 | function getLag() { |
| Index: trunk/phase3/includes/db/LoadBalancer.php |
| — | — | @@ -988,6 +988,25 @@ |
| 989 | 989 | } |
| 990 | 990 | |
| 991 | 991 | /** |
| | 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 | + /** |
| 992 | 1011 | * Clear the cache for getLagTimes |
| 993 | 1012 | */ |
| 994 | 1013 | function clearLagTimeCache() { |
| Index: trunk/extensions/CollabWatchlist/includes/SpecialCollabWatchlist.php |
| — | — | @@ -226,7 +226,8 @@ |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | # Show a message about slave lag, if applicable |
| 230 | | - if ( ( $lag = $dbr->getLag() ) > 0 ) |
| | 230 | + $lag = wfGetLB()->safeGetLag( $dbr ); |
| | 231 | + if ( $lag > 0 ) |
| 231 | 232 | $wgOut->showLagWarning( $lag ); |
| 232 | 233 | |
| 233 | 234 | # Create output form |
| Index: trunk/extensions/RefreshSpecial/RefreshSpecial.body.php |
| — | — | @@ -241,7 +241,7 @@ |
| 242 | 242 | |
| 243 | 243 | # Wait for the slave to catch up |
| 244 | 244 | $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 ) { |
| 246 | 246 | $wgOut->addHTML( wfMsg( 'refreshspecial-slave-lagged' ) . '<br />' ); |
| 247 | 247 | sleep( REFRESHSPECIAL_SLAVE_LAG_SLEEP ); |
| 248 | 248 | } |
| — | — | @@ -290,4 +290,4 @@ |
| 291 | 291 | $link_back = $sk->makeKnownLinkObj( $titleObj, wfMsg( 'refreshspecial-link-back' ) ); |
| 292 | 292 | $wgOut->addHTML( '<br /><b>' . $link_back . '</b>' ); |
| 293 | 293 | } |
| 294 | | -} |
| \ No newline at end of file |
| | 294 | +} |
| Index: trunk/extensions/ArchiveLinks/spider.php |
| — | — | @@ -207,7 +207,7 @@ |
| 208 | 208 | |
| 209 | 209 | $this->jobs = array(); |
| 210 | 210 | |
| 211 | | - $wait_time = $this->db_slave->getLag() * 3; |
| | 211 | + $wait_time = wfGetLB()->safeGetLag( $this->db_slave ) * 3; |
| 212 | 212 | $pid = (string) microtime() . ' - ' . getmypid(); |
| 213 | 213 | $time = time(); |
| 214 | 214 | |
| — | — | @@ -371,4 +371,4 @@ |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | $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 @@ |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | # Show a message about slave lag, if applicable |
| 226 | | - if( ( $lag = $dbr->getLag() ) > 0 ) |
| | 226 | + $lag = wfGetLB()->safeGetLag( $dbr ); |
| | 227 | + if( $lag > 0 ) |
| 227 | 228 | $wgOut->showLagWarning( $lag ); |
| 228 | 229 | |
| 229 | 230 | # Create output form |
| Index: trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php |
| — | — | @@ -704,7 +704,7 @@ |
| 705 | 705 | # Update page sync status for tracking purposes. |
| 706 | 706 | # NOTE: avoids master hits and doesn't have to be perfect for what it does |
| 707 | 707 | 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 |
| 709 | 709 | $this->article->updateSyncStatus( $synced ); |
| 710 | 710 | } |
| 711 | 711 | } |