From: Aaron Schulz Date: Sun, 21 Jul 2019 23:50:50 +0000 (-0700) Subject: rdbms: make LoadBalancer::waitForAll() include servers with load in any group X-Git-Tag: 1.34.0-rc.0~868^2 X-Git-Url: https://git.cyclocoop.org/admin/%7B%24admin_url%7Dmembres/import.php?a=commitdiff_plain;h=f0433cc2d6dae7fd01a2f6e65a756c855600edcd;p=lhc%2Fweb%2Fwiklou.git rdbms: make LoadBalancer::waitForAll() include servers with load in any group This avoids needing the hack of a server needing a generic load of 1 in configuration just to force lag checks to include it. Change-Id: I3de41efae427acb05beddb85dd5b5943b39f1b22 --- diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php b/includes/libs/rdbms/loadbalancer/LoadBalancer.php index 1ef1d09b5f..69bd51f744 100644 --- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php @@ -656,7 +656,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 +673,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 +683,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 */