Merge "Chinese Conversion Table Update 2017-5"
[lhc/web/wiklou.git] / includes / libs / rdbms / loadbalancer / LoadBalancer.php
index 1be8926..a9eaa99 100644 (file)
@@ -18,7 +18,6 @@
  * http://www.gnu.org/copyleft/gpl.html
  *
  * @file
- * @ingroup Database
  */
 namespace Wikimedia\Rdbms;
 
@@ -115,11 +114,13 @@ class LoadBalancer implements ILoadBalancer {
        private $disabled = false;
        /** @var bool */
        private $chronProtInitialized = false;
+       /** @var int */
+       private $maxLag = self::MAX_LAG_DEFAULT;
 
        /** @var int Warn when this many connection are held */
        const CONN_HELD_WARN_THRESHOLD = 10;
 
-       /** @var int Default 'max lag' when unspecified */
+       /** @var int Default 'maxLag' when unspecified */
        const MAX_LAG_DEFAULT = 10;
        /** @var int Seconds to cache master server read-only status */
        const TTL_CACHE_READONLY = 5;
@@ -178,11 +179,16 @@ class LoadBalancer implements ILoadBalancer {
                        $this->readOnlyReason = $params['readOnlyReason'];
                }
 
+               if ( isset( $params['maxLag'] ) ) {
+                       $this->maxLag = $params['maxLag'];
+               }
+
                if ( isset( $params['loadMonitor'] ) ) {
                        $this->loadMonitorConfig = $params['loadMonitor'];
                } else {
                        $this->loadMonitorConfig = [ 'class' => 'LoadMonitorNull' ];
                }
+               $this->loadMonitorConfig += [ 'lagWarnThreshold' => $this->maxLag ];
 
                foreach ( $params['servers'] as $i => $server ) {
                        $this->mLoads[$i] = $server['load'];
@@ -275,7 +281,7 @@ class LoadBalancer implements ILoadBalancer {
                                # How much lag this server nominally is allowed to have
                                $maxServerLag = isset( $this->mServers[$i]['max lag'] )
                                        ? $this->mServers[$i]['max lag']
-                                       : self::MAX_LAG_DEFAULT; // default
+                                       : $this->maxLag; // default
                                # Constrain that futher by $maxLag argument
                                $maxServerLag = min( $maxServerLag, $maxLag );
 
@@ -285,7 +291,7 @@ class LoadBalancer implements ILoadBalancer {
                                                "Server {host} is not replicating?", [ 'host' => $host ] );
                                        unset( $loads[$i] );
                                } elseif ( $lag > $maxServerLag ) {
-                                       $this->replLogger->warning(
+                                       $this->replLogger->info(
                                                "Server {host} has {lag} seconds of lag (>= {maxlag})",
                                                [ 'host' => $host, 'lag' => $lag, 'maxlag' => $maxServerLag ]
                                        );
@@ -603,8 +609,8 @@ class LoadBalancer implements ILoadBalancer {
                if ( $result == -1 || is_null( $result ) ) {
                        // Timed out waiting for replica DB, use master instead
                        $this->replLogger->warning(
-                               __METHOD__ . ": Timed out waiting on {host} pos {$this->mWaitForPos}",
-                               [ 'host' => $server ]
+                               __METHOD__ . ': Timed out waiting on {host} pos {pos}',
+                               [ 'host' => $server, 'pos' => $this->mWaitForPos ]
                        );
                        $ok = false;
                } else {
@@ -1640,16 +1646,18 @@ class LoadBalancer implements ILoadBalancer {
                if ( $pos instanceof DBMasterPos ) {
                        $result = $conn->masterPosWait( $pos, $timeout );
                        if ( $result == -1 || is_null( $result ) ) {
-                               $msg = __METHOD__ . ": Timed out waiting on {$conn->getServer()} pos {$pos}";
-                               $this->replLogger->warning( "$msg" );
+                               $msg = __METHOD__ . ': Timed out waiting on {host} pos {pos}';
+                               $this->replLogger->warning( $msg,
+                                       [ 'host' => $conn->getServer(), 'pos' => $pos ] );
                                $ok = false;
                        } else {
-                               $this->replLogger->info( __METHOD__ . ": Done" );
+                               $this->replLogger->info( __METHOD__ . ': Done' );
                                $ok = true;
                        }
                } else {
                        $ok = false; // something is misconfigured
-                       $this->replLogger->error( "Could not get master pos for {$conn->getServer()}." );
+                       $this->replLogger->error( 'Could not get master pos for {host}',
+                               [ 'host' => $conn->getServer() ] );
                }
 
                return $ok;