$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'] )
$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
$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;
}
$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 );
}
}
} 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
*/
}
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;
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;
$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 = [];