Merge "Port categories dump header fix"
[lhc/web/wiklou.git] / includes / libs / rdbms / lbfactory / LBFactoryMulti.php
index bb6e445..cfa2647 100644 (file)
@@ -23,8 +23,6 @@
 
 namespace Wikimedia\Rdbms;
 
-use LoadBalancer;
-use IDatabase;
 use InvalidArgumentException;
 
 /**
@@ -109,6 +107,12 @@ class LBFactoryMulti extends LBFactory {
        /** @var string */
        private $lastSection;
 
+       /** @var int */
+       private $maxLag = self::MAX_LAG_DEFAULT;
+
+       /** @var int Default 'maxLag' when unspecified */
+       const MAX_LAG_DEFAULT = 10;
+
        /**
         * @see LBFactory::__construct()
         *
@@ -162,6 +166,7 @@ class LBFactoryMulti extends LBFactory {
         *                                 storage cluster.
         *   - masterTemplateOverrides     Server configuration map overrides for all master servers.
         *   - loadMonitorClass            Name of the LoadMonitor class to always use.
+        *   - maxLag                      Avoid replica DBs with more lag than this many seconds.
         *   - readOnlyBySection           A map of section name to read-only message.
         *                                 Missing or false for read/write.
         */
@@ -173,7 +178,7 @@ class LBFactoryMulti extends LBFactory {
                $optional = [ 'groupLoadsBySection', 'groupLoadsByDB', 'hostsByName',
                        'externalLoads', 'externalTemplateOverrides', 'templateOverridesByServer',
                        'templateOverridesByCluster', 'templateOverridesBySection', 'masterTemplateOverrides',
-                       'readOnlyBySection', 'loadMonitorClass' ];
+                       'readOnlyBySection', 'maxLag', 'loadMonitorClass' ];
 
                foreach ( $required as $key ) {
                        if ( !isset( $conf[$key] ) ) {
@@ -253,9 +258,7 @@ class LBFactoryMulti extends LBFactory {
        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];
@@ -284,7 +287,6 @@ class LBFactoryMulti extends LBFactory {
        public function getExternalLB( $cluster ) {
                if ( !isset( $this->extLBs[$cluster] ) ) {
                        $this->extLBs[$cluster] = $this->newExternalLB( $cluster );
-                       $this->getChronologyProtector()->initLB( $this->extLBs[$cluster] );
                }
 
                return $this->extLBs[$cluster];
@@ -324,6 +326,7 @@ class LBFactoryMulti extends LBFactory {
                        $this->baseLoadBalancerParams(),
                        [
                                'servers' => $this->makeServerArray( $template, $loads, $groupLoads ),
+                               'maxLag' => $this->maxLag,
                                'loadMonitor' => [ 'class' => $this->loadMonitorClass ],
                                'readOnlyReason' => $readOnlyReason
                        ]