* @ingroup Database
*/
+namespace Wikimedia\Rdbms;
+
+use InvalidArgumentException;
+
/**
* A multi-database, multi-master factory for Wikimedia and similar installations.
* Ignores the old configuration globals.
private $extLBs = [];
/** @var string */
- private $loadMonitorClass;
+ private $loadMonitorClass = 'LoadMonitor';
/** @var string */
private $lastDomain;
public function getMainLB( $domain = false ) {
$section = $this->getSectionForDomain( $domain );
if ( !isset( $this->mainLBs[$section] ) ) {
- $lb = $this->newMainLB( $domain );
- $this->getChronologyProtector()->initLB( $lb );
- $this->mainLBs[$section] = $lb;
+ $this->mainLBs[$section] = $this->newMainLB( $domain );
}
return $this->mainLBs[$section];
}
- /**
- * @param string $cluster
- * @param DatabaseDomain|string|bool $domain Domain ID, or false for the current domain
- * @throws InvalidArgumentException
- * @return LoadBalancer
- */
- public function newExternalLB( $cluster, $domain = false ) {
+ public function newExternalLB( $cluster ) {
if ( !isset( $this->externalLoads[$cluster] ) ) {
throw new InvalidArgumentException( __METHOD__ . ": Unknown cluster \"$cluster\"" );
}
$template = $this->serverTemplate;
- if ( isset( $this->externalTemplateOverrides ) ) {
+ if ( $this->externalTemplateOverrides ) {
$template = $this->externalTemplateOverrides + $template;
}
if ( isset( $this->templateOverridesByCluster[$cluster] ) ) {
);
}
- /**
- * @param string $cluster External storage cluster, or false for core
- * @param DatabaseDomain|string|bool $domain Domain ID, or false for the current domain
- * @return LoadBalancer
- */
- public function getExternalLB( $cluster, $domain = false ) {
+ public function getExternalLB( $cluster ) {
if ( !isset( $this->extLBs[$cluster] ) ) {
- $this->extLBs[$cluster] = $this->newExternalLB( $cluster, $domain );
- $this->getChronologyProtector()->initLB( $this->extLBs[$cluster] );
+ $this->extLBs[$cluster] = $this->newExternalLB( $cluster );
}
return $this->extLBs[$cluster];
}
+ public function getAllMainLBs() {
+ $lbs = [];
+ foreach ( $this->sectionsByDB as $db => $section ) {
+ if ( !isset( $lbs[$section] ) ) {
+ $lbs[$section] = $this->getMainLB( $db );
+ }
+ }
+
+ return $lbs;
+ }
+
+ public function getAllExternalLBs() {
+ $lbs = [];
+ foreach ( $this->externalLoads as $cluster => $unused ) {
+ $lbs[$cluster] = $this->getExternalLB( $cluster );
+ }
+
+ return $lbs;
+ }
+
/**
* Make a new load balancer object based on template and load array
*
$serverInfo = $template;
if ( $master ) {
$serverInfo['master'] = true;
- if ( isset( $this->masterTemplateOverrides ) ) {
+ if ( $this->masterTemplateOverrides ) {
$serverInfo = $this->masterTemplateOverrides + $serverInfo;
}
$master = false;