Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
[lhc/web/wiklou.git] / includes / libs / rdbms / loadmonitor / LoadMonitor.php
index 50c878d..01834ee 100644 (file)
@@ -69,12 +69,8 @@ class LoadMonitor implements ILoadMonitor {
                $this->wanCache = $wCache;
                $this->replLogger = new NullLogger();
 
-               $this->movingAveRatio = isset( $options['movingAveRatio'] )
-                       ? $options['movingAveRatio']
-                       : 0.1;
-               $this->lagWarnThreshold = isset( $options['lagWarnThreshold'] )
-                       ? $options['lagWarnThreshold']
-                       : self::LAG_WARN_THRESHOLD;
+               $this->movingAveRatio = $options['movingAveRatio'] ?? 0.1;
+               $this->lagWarnThreshold = $options['lagWarnThreshold'] ?? self::LAG_WARN_THRESHOLD;
        }
 
        public function setLogger( LoggerInterface $logger ) {
@@ -156,17 +152,18 @@ class LoadMonitor implements ILoadMonitor {
                                continue;
                        }
 
-                       $conn = $this->parent->getAnyOpenConnection( $i );
+                       # Handles with open transactions are avoided since they might be subject
+                       # to REPEATABLE-READ snapshots, which could affect the lag estimate query.
+                       $flags = ILoadBalancer::CONN_TRX_AUTOCOMMIT;
+                       $conn = $this->parent->getAnyOpenConnection( $i, $flags );
                        if ( $conn ) {
                                $close = false; // already open
                        } else {
-                               $conn = $this->parent->openConnection( $i, '' );
+                               $conn = $this->parent->openConnection( $i, ILoadBalancer::DOMAIN_ANY, $flags );
                                $close = true; // new connection
                        }
 
-                       $lastWeight = isset( $staleValue['weightScales'][$i] )
-                               ? $staleValue['weightScales'][$i]
-                               : 1.0;
+                       $lastWeight = $staleValue['weightScales'][$i] ?? 1.0;
                        $coefficient = $this->getWeightScale( $i, $conn ?: null );
                        $newWeight = $movAveRatio * $coefficient + ( 1 - $movAveRatio ) * $lastWeight;