rdbms: simplify LoadBalancer::getLaggedReplicaMode()
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 8 Aug 2019 22:53:08 +0000 (15:53 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 8 Aug 2019 22:53:08 +0000 (15:53 -0700)
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

includes/libs/rdbms/loadbalancer/ILoadBalancer.php
includes/libs/rdbms/loadbalancer/LoadBalancer.php

index 990705c..1125572 100644 (file)
@@ -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 );
 
index 98607ce..d088aa9 100644 (file)
@@ -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;