*
* masterTemplateOverrides An override array for all master servers.
*
+ * loadMonitorClass Name of the LoadMonitor class to always use.
+ *
* readOnlyBySection A map of section name to read-only message.
* Missing or false for read/write.
*
/** @var LoadBalancer[] */
private $extLBs = array();
+ /** @var string */
+ private $loadMonitorClass;
+
/** @var string */
private $lastWiki;
* @throws MWException
*/
public function __construct( array $conf ) {
+ parent::__construct( $conf );
+
$this->chronProt = new ChronologyProtector;
$this->conf = $conf;
$required = array( 'sectionsByDB', 'sectionLoads', 'serverTemplate' );
$optional = array( 'groupLoadsBySection', 'groupLoadsByDB', 'hostsByName',
'externalLoads', 'externalTemplateOverrides', 'templateOverridesByServer',
'templateOverridesByCluster', 'masterTemplateOverrides',
- 'readOnlyBySection' );
+ 'readOnlyBySection', 'loadMonitorClass' );
foreach ( $required as $key ) {
if ( !isset( $conf[$key] ) ) {
$this->$key = $conf[$key];
}
}
-
- // Check for read-only mode
- $section = $this->getSectionForWiki();
- if ( !empty( $this->readOnlyBySection[$section] ) ) {
- global $wgReadOnly;
- $wgReadOnly = $this->readOnlyBySection[$section];
- }
}
/**
public function newMainLB( $wiki = false ) {
list( $dbName, ) = $this->getDBNameAndPrefix( $wiki );
$section = $this->getSectionForWiki( $wiki );
- $groupLoads = array();
if ( isset( $this->groupLoadsByDB[$dbName] ) ) {
$groupLoads = $this->groupLoadsByDB[$dbName];
+ } else {
+ $groupLoads = array();
}
if ( isset( $this->groupLoadsBySection[$section] ) ) {
$groupLoads = array_merge_recursive( $groupLoads, $this->groupLoadsBySection[$section] );
}
+ $readOnlyReason = $this->readOnlyReason;
+ // Use the LB-specific read-only reason if everything isn't already read-only
+ if ( $readOnlyReason === false && isset( $this->readOnlyBySection[$section] ) ) {
+ $readOnlyReason = $this->readOnlyBySection[$section];
+ }
+
return $this->newLoadBalancer(
$this->serverTemplate,
$this->sectionLoads[$section],
- $groupLoads
+ $groupLoads,
+ $readOnlyReason
);
}
$template = $this->templateOverridesByCluster[$cluster] + $template;
}
- return $this->newLoadBalancer( $template, $this->externalLoads[$cluster], array() );
+ return $this->newLoadBalancer(
+ $template,
+ $this->externalLoads[$cluster],
+ array(),
+ $this->readOnlyReason
+ );
}
/**
* @param array $template
* @param array $loads
* @param array $groupLoads
+ * @param string|bool $readOnlyReason
* @return LoadBalancer
*/
- private function newLoadBalancer( $template, $loads, $groupLoads ) {
- $servers = $this->makeServerArray( $template, $loads, $groupLoads );
- $lb = new LoadBalancer( array(
- 'servers' => $servers,
+ private function newLoadBalancer( $template, $loads, $groupLoads, $readOnlyReason ) {
+ return new LoadBalancer( array(
+ 'servers' => $this->makeServerArray( $template, $loads, $groupLoads ),
+ 'loadMonitor' => $this->loadMonitorClass,
+ 'readOnlyReason' => $readOnlyReason
) );
-
- return $lb;
}
/**
$serverInfo = $this->masterTemplateOverrides + $serverInfo;
}
$master = false;
+ } else {
+ $serverInfo['slave'] = true;
}
if ( isset( $this->templateOverridesByServer[$serverName] ) ) {
$serverInfo = $this->templateOverridesByServer[$serverName] + $serverInfo;