Merge "deferred: make DeferredUpdates::attemptUpdate() use callback owners for $fname...
[lhc/web/wiklou.git] / includes / libs / rdbms / loadbalancer / LoadBalancer.php
index 1ef1d09..d088aa9 100644 (file)
@@ -177,11 +177,10 @@ class LoadBalancer implements ILoadBalancer {
                                $server['replica'] = true;
                        }
                        $this->servers[$i] = $server;
-                       $serverGroupLoads = [ self::GROUP_GENERIC => $server['load'] ];
-                       $serverGroupLoads += ( $server['groupLoads'] ?? [] );
-                       foreach ( $serverGroupLoads as $group => $ratio ) {
+                       foreach ( ( $server['groupLoads'] ?? [] ) as $group => $ratio ) {
                                $this->groupLoads[$group][$i] = $ratio;
                        }
+                       $this->groupLoads[self::GROUP_GENERIC][$i] = $server['load'];
                }
 
                $localDomain = isset( $params['localDomain'] )
@@ -593,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
@@ -656,7 +654,7 @@ class LoadBalancer implements ILoadBalancer {
                                $ok = true; // no applicable loads
                        }
                } finally {
-                       # Restore the old position, as this is not used for lag-protection but for throttling
+                       // Restore the old position; this is used for throttling, not lag-protection
                        $this->waitForPos = $oldPos;
                }
 
@@ -673,7 +671,7 @@ class LoadBalancer implements ILoadBalancer {
 
                        $ok = true;
                        for ( $i = 1; $i < $serverCount; $i++ ) {
-                               if ( $this->groupLoads[self::GROUP_GENERIC][$i] > 0 ) {
+                               if ( $this->serverHasLoadInAnyGroup( $i ) ) {
                                        $start = microtime( true );
                                        $ok = $this->doWait( $i, true, $timeout ) && $ok;
                                        $timeout -= intval( microtime( true ) - $start );
@@ -683,13 +681,27 @@ class LoadBalancer implements ILoadBalancer {
                                }
                        }
                } finally {
-                       # Restore the old position, as this is not used for lag-protection but for throttling
+                       // Restore the old position; this is used for throttling, not lag-protection
                        $this->waitForPos = $oldPos;
                }
 
                return $ok;
        }
 
+       /**
+        * @param int $i Specific server index
+        * @return bool
+        */
+       private function serverHasLoadInAnyGroup( $i ) {
+               foreach ( $this->groupLoads as $loadsByIndex ) {
+                       if ( ( $loadsByIndex[$i] ?? 0 ) > 0 ) {
+                               return true;
+                       }
+               }
+
+               return false;
+       }
+
        /**
         * @param DBMasterPos|bool $pos
         */
@@ -1906,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;
@@ -1922,15 +1929,6 @@ class LoadBalancer implements ILoadBalancer {
                return $this->laggedReplicaMode;
        }
 
-       /**
-        * @return bool
-        * @since 1.27
-        * @deprecated Since 1.28; use laggedReplicaUsed()
-        */
-       public function laggedSlaveUsed() {
-               return $this->laggedReplicaUsed();
-       }
-
        public function getReadOnlyReason( $domain = false, IDatabase $conn = null ) {
                if ( $this->readOnlyReason !== false ) {
                        return $this->readOnlyReason;
@@ -2203,14 +2201,6 @@ class LoadBalancer implements ILoadBalancer {
                $this->indexAliases = $aliases;
        }
 
-       /**
-        * @param string $prefix
-        * @deprecated Since 1.33
-        */
-       public function setDomainPrefix( $prefix ) {
-               $this->setLocalDomainPrefix( $prefix );
-       }
-
        public function setLocalDomainPrefix( $prefix ) {
                // Find connections to explicit foreign domains still marked as in-use...
                $domainsInUse = [];