From: Aaron Schulz Date: Thu, 8 Aug 2019 22:53:08 +0000 (-0700) Subject: rdbms: simplify LoadBalancer::getLaggedReplicaMode() X-Git-Tag: 1.34.0-rc.0~660^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/gestion/Special:FilePath/Image2.gif?a=commitdiff_plain;h=21fa1cf121f4350870eb305c0545d458474affab;p=lhc%2Fweb%2Fwiklou.git rdbms: simplify LoadBalancer::getLaggedReplicaMode() Remove try/catch since getReaderIndex() is not supposed to throw connection errors anyway. This makes it easier to tell when "lagged replica" mode is actually set. Bug: T216496 Change-Id: Ife974b8da19d3798b2d37424b40c6cadd880e157 --- diff --git a/includes/libs/rdbms/loadbalancer/ILoadBalancer.php b/includes/libs/rdbms/loadbalancer/ILoadBalancer.php index 990705c45f..112557257f 100644 --- a/includes/libs/rdbms/loadbalancer/ILoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/ILoadBalancer.php @@ -167,8 +167,7 @@ interface ILoadBalancer { * * @param string|bool $group Query group or false for the generic group * @param string|bool $domain DB domain ID or false for the local domain - * @throws DBError If no live handle can be obtained - * @return bool|int|string + * @return int|bool Returns false if no live handle can be obtained */ public function getReaderIndex( $group = false, $domain = false ); diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php b/includes/libs/rdbms/loadbalancer/LoadBalancer.php index 98607ce807..d088aa9e54 100644 --- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php @@ -592,8 +592,7 @@ class LoadBalancer implements ILoadBalancer { $this->connLogger->debug( __METHOD__ . ": Using reader #$i: $serverName..." ); // Get a connection to this server without triggering other server connections - $flags = self::CONN_SILENCE_ERRORS; - $conn = $this->getServerConnection( $i, $domain, $flags ); + $conn = $this->getServerConnection( $i, $domain, self::CONN_SILENCE_ERRORS ); if ( !$conn ) { $this->connLogger->warning( __METHOD__ . ": Failed connecting to $i/$domain" ); unset( $currentLoads[$i] ); // avoid this server next iteration @@ -1919,13 +1918,8 @@ class LoadBalancer implements ILoadBalancer { } if ( $this->hasStreamingReplicaServers() ) { - try { - // Set "laggedReplicaMode" - $this->getReaderIndex( self::GROUP_GENERIC, $domain ); - } catch ( DBConnectionError $e ) { - // Sanity: avoid expensive re-connect attempts and failures - $this->laggedReplicaMode = true; - } + // This will set "laggedReplicaMode" as needed + $this->getReaderIndex( self::GROUP_GENERIC, $domain ); } return $this->laggedReplicaMode;