}
public function getLag() {
+ if ( $this->getLBInfo( 'master' ) ) {
+ return 0; // this is the master
+ } elseif ( $this->getLBInfo( 'is static' ) ) {
+ return 0; // static dataset
+ }
+
+ return $this->doGetLag();
+ }
+
+ protected function doGetLag() {
return 0;
}
return strlen( $name ) && $name[0] == '`' && substr( $name, -1, 1 ) == '`';
}
- public function getLag() {
+ protected function doGetLag() {
if ( $this->getLagDetectionMethod() === 'pt-heartbeat' ) {
return $this->getLagFromPtHeartbeat();
} else {
*/
public function getLagTimes( $domain = false );
- /**
- * 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.
- *
- * @param IDatabase $conn
- * @return int|bool Returns false on error
- */
- public function safeGetLag( IDatabase $conn );
-
/**
* Wait for a replica DB to reach a specified master position
*
return $this->getLoadMonitor()->getLagTimes( $indexesWithLag, $domain ) + $knownLagTimes;
}
+ /**
+ * 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.
+ *
+ * @param IDatabase $conn
+ * @return int|bool Returns false on error
+ * @deprecated Since 1.34 Use IDatabase::getLag() instead
+ */
public function safeGetLag( IDatabase $conn ) {
if ( $this->getServerCount() <= 1 ) {
return 0;
if ( $masterConn ) {
$pos = $masterConn->getMasterPos();
} else {
- $masterConn = $this->getConnection( $index, [], self::DOMAIN_ANY, self::CONN_SILENCE_ERRORS );
+ $flags = self::CONN_SILENCE_ERRORS;
+ $masterConn = $this->getConnection( $index, [], self::DOMAIN_ANY, $flags );
if ( !$masterConn ) {
throw new DBReplicationWaitError(
null,
continue;
}
- if ( $conn->getLBInfo( 'is static' ) ) {
- $lagTimes[$i] = 0;
- } else {
- $lagTimes[$i] = $conn->getLag();
- if ( $lagTimes[$i] === false ) {
- $this->replLogger->error(
- __METHOD__ . ": host {db_server} is not replicating?",
- [ 'db_server' => $host ]
- );
- } elseif ( $lagTimes[$i] > $this->lagWarnThreshold ) {
- $this->replLogger->warning(
- "Server {host} has {lag} seconds of lag (>= {maxlag})",
- [
- 'host' => $host,
- 'lag' => $lagTimes[$i],
- 'maxlag' => $this->lagWarnThreshold
- ]
- );
- }
+ $lagTimes[$i] = $conn->getLag();
+ if ( $lagTimes[$i] === false ) {
+ $this->replLogger->error(
+ __METHOD__ . ": host {db_server} is not replicating?",
+ [ 'db_server' => $host ]
+ );
+ } elseif ( $lagTimes[$i] > $this->lagWarnThreshold ) {
+ $this->replLogger->warning(
+ "Server {host} has {lag} seconds of lag (>= {maxlag})",
+ [
+ 'host' => $host,
+ 'lag' => $lagTimes[$i],
+ 'maxlag' => $this->lagWarnThreshold
+ ]
+ );
}
if ( $close ) {