From: Aaron Schulz Date: Wed, 19 Jun 2019 16:05:16 +0000 (+0100) Subject: rdbms: deprecate unused ILoadBalancer::safeGetLag method X-Git-Tag: 1.34.0-rc.0~1343 X-Git-Url: http://git.cyclocoop.org/%22.%20generer_url_ecrire%28%22sites_tous%22%2C%22%22%29.%20%22?a=commitdiff_plain;h=b9a67d4710b117504f4c65d2c2071791909d6c5e;p=lhc%2Fweb%2Fwiklou.git rdbms: deprecate unused ILoadBalancer::safeGetLag method Change-Id: Ib3bc2862548271613da30ad1be836d28a82e6cc9 --- diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index 5451476042..bc8883c3ac 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -4245,6 +4245,16 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } 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; } diff --git a/includes/libs/rdbms/database/DatabaseMysqlBase.php b/includes/libs/rdbms/database/DatabaseMysqlBase.php index b5f83dae0d..ef28f33ac6 100644 --- a/includes/libs/rdbms/database/DatabaseMysqlBase.php +++ b/includes/libs/rdbms/database/DatabaseMysqlBase.php @@ -744,7 +744,7 @@ abstract class DatabaseMysqlBase extends Database { return strlen( $name ) && $name[0] == '`' && substr( $name, -1, 1 ) == '`'; } - public function getLag() { + protected function doGetLag() { if ( $this->getLagDetectionMethod() === 'pt-heartbeat' ) { return $this->getLagFromPtHeartbeat(); } else { diff --git a/includes/libs/rdbms/loadbalancer/ILoadBalancer.php b/includes/libs/rdbms/loadbalancer/ILoadBalancer.php index a2202b6a09..22281c17ed 100644 --- a/includes/libs/rdbms/loadbalancer/ILoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/ILoadBalancer.php @@ -604,22 +604,6 @@ interface ILoadBalancer { */ 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 * diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php b/includes/libs/rdbms/loadbalancer/LoadBalancer.php index 62f45823b7..f0e4b4f47d 100644 --- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php @@ -1959,6 +1959,21 @@ class LoadBalancer implements ILoadBalancer { 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; @@ -1981,7 +1996,8 @@ class LoadBalancer implements ILoadBalancer { 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, diff --git a/includes/libs/rdbms/loadmonitor/LoadMonitor.php b/includes/libs/rdbms/loadmonitor/LoadMonitor.php index aa1e9b24b1..1666c275c7 100644 --- a/includes/libs/rdbms/loadmonitor/LoadMonitor.php +++ b/includes/libs/rdbms/loadmonitor/LoadMonitor.php @@ -181,25 +181,21 @@ class LoadMonitor implements ILoadMonitor { 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 ) {