}
/**
- * Get slave lag.
- * Currently supported only by MySQL
+ * Get slave lag. Currently supported only by MySQL.
+ *
+ * Note that this function will generate a fatal error on many
+ * installations. Most callers should use LoadBalancer::safeGetLag()
+ * instead.
+ *
* @return Database replication lag in seconds
*/
function getLag() {
return $this->mLagTimes;
}
+ /**
+ * Get the lag in seconds for a given connection, or zero if this load
+ * balancer does not have replication enabled.
+ *
+ * This should be used in preference to Database::getLag() in cases where
+ * replication may not be in use, since there is no way to determine if
+ * replication is in use at the connection level without running
+ * potentially restricted queries such as SHOW SLAVE STATUS. Using this
+ * function instead of Database::getLag() avoids a fatal error in this
+ * case on many installations.
+ */
+ function safeGetLag( $conn ) {
+ if ( $this->getServerCount() == 1 ) {
+ return 0;
+ } else {
+ return $conn->getLag();
+ }
+ }
+
/**
* Clear the cache for getLagTimes
*/
$wgOut->addWikiMsg( 'nocontribs', $target );
} else {
# Show a message about slave lag, if applicable
- if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
+ $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
+ if( $lag > 0 )
$wgOut->showLagWarning( $lag );
$wgOut->addHTML(
}
# Show a message about slave lag, if applicable
- if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
+ $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
+ if( $lag > 0 )
$wgOut->showLagWarning( $lag );
$wgOut->addHTML(
}
# Show a message about slave lag, if applicable
- $lag = $dbr->getLag();
+ $lag = wfGetLB()->safeGetLag( $dbr );
if( $lag > 0 ) {
$output->showLagWarning( $lag );
}