Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
[lhc/web/wiklou.git] / includes / libs / rdbms / lbfactory / LBFactorySimple.php
index 1f5f93f..0d7b812 100644 (file)
@@ -23,7 +23,6 @@
 
 namespace Wikimedia\Rdbms;
 
-use LoadBalancer;
 use InvalidArgumentException;
 
 /**
@@ -42,6 +41,11 @@ class LBFactorySimple extends LBFactory {
 
        /** @var string */
        private $loadMonitorClass;
+       /** @var int */
+       private $maxLag;
+
+       /** @var int Default 'maxLag' when unspecified */
+       const MAX_LAG_DEFAULT = 10;
 
        /**
         * @see LBFactory::__construct()
@@ -58,7 +62,7 @@ class LBFactorySimple extends LBFactory {
        public function __construct( array $conf ) {
                parent::__construct( $conf );
 
-               $this->servers = isset( $conf['servers'] ) ? $conf['servers'] : [];
+               $this->servers = $conf['servers'] ?? [];
                foreach ( $this->servers as $i => $server ) {
                        if ( $i == 0 ) {
                                $this->servers[$i]['master'] = true;
@@ -67,12 +71,9 @@ class LBFactorySimple extends LBFactory {
                        }
                }
 
-               $this->externalClusters = isset( $conf['externalClusters'] )
-                       ? $conf['externalClusters']
-                       : [];
-               $this->loadMonitorClass = isset( $conf['loadMonitorClass'] )
-                       ? $conf['loadMonitorClass']
-                       : 'LoadMonitor';
+               $this->externalClusters = $conf['externalClusters'] ?? [];
+               $this->loadMonitorClass = $conf['loadMonitorClass'] ?? 'LoadMonitor';
+               $this->maxLag = $conf['maxLag'] ?? self::MAX_LAG_DEFAULT;
        }
 
        /**
@@ -90,7 +91,6 @@ class LBFactorySimple extends LBFactory {
        public function getMainLB( $domain = false ) {
                if ( !isset( $this->mainLB ) ) {
                        $this->mainLB = $this->newMainLB( $domain );
-                       $this->getChronologyProtector()->initLB( $this->mainLB );
                }
 
                return $this->mainLB;
@@ -107,7 +107,6 @@ class LBFactorySimple 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];
@@ -131,6 +130,7 @@ class LBFactorySimple extends LBFactory {
                        $this->baseLoadBalancerParams(),
                        [
                                'servers' => $servers,
+                               'maxLag' => $this->maxLag,
                                'loadMonitor' => [ 'class' => $this->loadMonitorClass ],
                        ]
                ) );