Provide a default "max lag" value for LoadBalancer
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 8 Oct 2015 03:44:54 +0000 (20:44 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 8 Oct 2015 08:17:09 +0000 (08:17 +0000)
* No MediaWiki site can tolerate unbounded slave lag
  without editing and account creation and such being
  broken and unusable
* Also fix a few trivial __construct() IDEA errors

Change-Id: I95b8b73be2df3b5a87e7adbf53988cfbeb85c260

includes/db/loadbalancer/LBFactory.php
includes/db/loadbalancer/LBFactoryMulti.php
includes/db/loadbalancer/LBFactorySimple.php
includes/db/loadbalancer/LoadBalancer.php

index a06d826..bad04f9 100644 (file)
@@ -29,6 +29,13 @@ abstract class LBFactory {
        /** @var LBFactory */
        private static $instance;
 
+       /**
+        * Construct a factory based on a configuration array (typically from $wgLBFactoryConf)
+        * @param array $conf
+        */
+       public function __construct( array $conf ) {
+       }
+
        /**
         * Disables all access to the load balancer, will cause all database access
         * to throw a DBAccessError
@@ -105,12 +112,6 @@ abstract class LBFactory {
                self::$instance = $instance;
        }
 
-       /**
-        * Construct a factory based on a configuration array (typically from $wgLBFactoryConf)
-        * @param array $conf
-        */
-       abstract public function __construct( array $conf );
-
        /**
         * Create a new load balancer object. The resulting object will be untracked,
         * not chronology-protected, and the caller is responsible for cleaning it up.
index 6397bca..2655659 100644 (file)
@@ -158,6 +158,8 @@ class LBFactoryMulti extends LBFactory {
         * @throws MWException
         */
        public function __construct( array $conf ) {
+               parent::__construct( $conf );
+
                $this->chronProt = new ChronologyProtector;
                $this->conf = $conf;
                $required = array( 'sectionsByDB', 'sectionLoads', 'serverTemplate' );
index 90c33b0..e328727 100644 (file)
@@ -36,6 +36,8 @@ class LBFactorySimple extends LBFactory {
        private $loadMonitorClass;
 
        public function __construct( array $conf ) {
+               parent::__construct( $conf );
+
                $this->chronProt = new ChronologyProtector;
                $this->loadMonitorClass = isset( $conf['loadMonitorClass'] )
                        ? $conf['loadMonitorClass']
index 3350d19..fbc8c8c 100644 (file)
@@ -63,6 +63,8 @@ class LoadBalancer {
 
        /** @var integer Warn when this many connection are held */
        const CONN_HELD_WARN_THRESHOLD = 10;
+       /** @var integer Default 'max lag' when unspecified */
+       const MAX_LAG = 30;
 
        /**
         * @param array $params Array with keys:
@@ -155,7 +157,7 @@ class LoadBalancer {
         * @param float $maxLag Restrict the maximum allowed lag to this many seconds
         * @return bool|int|string
         */
-       private function getRandomNonLagged( array $loads, $wiki = false, $maxLag = INF ) {
+       private function getRandomNonLagged( array $loads, $wiki = false, $maxLag = self::MAX_LAG ) {
                $lags = $this->getLagTimes( $wiki );
 
                # Unset excessively lagged servers