From: jenkins-bot Date: Fri, 21 Jun 2019 20:23:21 +0000 (+0000) Subject: Merge "rdbms: add replica server counting methods to ILoadBalancer" X-Git-Tag: 1.34.0-rc.0~1311 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/rappels.php?a=commitdiff_plain;h=291a9237dcd761bc250bfad9a9bf0cd04be071a2;p=lhc%2Fweb%2Fwiklou.git Merge "rdbms: add replica server counting methods to ILoadBalancer" --- 291a9237dcd761bc250bfad9a9bf0cd04be071a2 diff --cc includes/libs/rdbms/loadbalancer/LoadBalancer.php index f0e4b4f47d,d075c49c5d..3936271531 --- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php @@@ -1959,27 -1969,14 +1969,29 @@@ class LoadBalancer implements ILoadBala 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; - } else { - return $conn->getLag(); + if ( $conn->getLBInfo( 'is static' ) ) { + return 0; // static dataset + } elseif ( $conn->getLBInfo( 'serverIndex' ) == $this->getWriterIndex() ) { + return 0; // this is the master } + + return $conn->getLag(); } public function safeWaitForMasterPos( IDatabase $conn, $pos = false, $timeout = null ) {