X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=includes%2Fdb%2Floadbalancer%2FLBFactoryMulti.php;h=e58aead8e1938ac39e0a684f1df74ef2e42baf7f;hb=1af6474a6ea3b77268f3af097894061286d61f80;hp=92fbccd690193eed426559020bb5d09baae15dbd;hpb=9df8c2ac740393cce26c6f0085f83b28a567e44d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/db/loadbalancer/LBFactoryMulti.php b/includes/db/loadbalancer/LBFactoryMulti.php index 92fbccd690..e58aead8e1 100644 --- a/includes/db/loadbalancer/LBFactoryMulti.php +++ b/includes/db/loadbalancer/LBFactoryMulti.php @@ -68,14 +68,14 @@ * * 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. * * @ingroup Database */ class LBFactoryMulti extends LBFactory { - // Required settings - /** @var array A map of database names to section names */ private $sectionsByDB; @@ -142,6 +142,9 @@ class LBFactoryMulti extends LBFactory { /** @var LoadBalancer[] */ private $extLBs = array(); + /** @var string */ + private $loadMonitorClass; + /** @var string */ private $lastWiki; @@ -153,13 +156,14 @@ class LBFactoryMulti extends LBFactory { * @throws MWException */ public function __construct( array $conf ) { - $this->chronProt = new ChronologyProtector; + parent::__construct( $conf ); + $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] ) ) { @@ -173,13 +177,6 @@ class LBFactoryMulti extends LBFactory { $this->$key = $conf[$key]; } } - - // Check for read-only mode - $section = $this->getSectionForWiki(); - if ( !empty( $this->readOnlyBySection[$section] ) ) { - global $wgReadOnly; - $wgReadOnly = $this->readOnlyBySection[$section]; - } } /** @@ -209,19 +206,27 @@ class LBFactoryMulti extends LBFactory { 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 ); } @@ -259,7 +264,12 @@ class LBFactoryMulti extends LBFactory { $template = $this->templateOverridesByCluster[$cluster] + $template; } - return $this->newLoadBalancer( $template, $this->externalLoads[$cluster], array() ); + return $this->newLoadBalancer( + $template, + $this->externalLoads[$cluster], + array(), + $this->readOnlyReason + ); } /** @@ -283,15 +293,15 @@ class LBFactoryMulti extends LBFactory { * @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; } /** @@ -319,6 +329,8 @@ class LBFactoryMulti extends LBFactory { $serverInfo = $this->masterTemplateOverrides + $serverInfo; } $master = false; + } else { + $serverInfo['slave'] = true; } if ( isset( $this->templateOverridesByServer[$serverName] ) ) { $serverInfo = $this->templateOverridesByServer[$serverName] + $serverInfo; @@ -386,14 +398,10 @@ class LBFactoryMulti extends LBFactory { } } - public function shutdown() { - foreach ( $this->mainLBs as $lb ) { - $this->chronProt->shutdownLB( $lb ); - } - foreach ( $this->extLBs as $extLB ) { - $this->chronProt->shutdownLB( $extLB ); + public function shutdown( $flags = 0 ) { + if ( !( $flags & self::SHUTDOWN_NO_CHRONPROT ) ) { + $this->shutdownChronologyProtector( $this->chronProt ); } - $this->chronProt->shutdown(); - $this->commitMasterChanges(); + $this->commitMasterChanges(); // sanity } }