X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2Floadbalancer%2FLoadBalancer.php;h=a9eaa9974e512b5b8b6ffe64212f9cfa4644d52a;hb=2ef178072f6f46abde7bdcc2630389a8b2837557;hp=1be8926bfa55042bdde924fd268db5db7024c7d8;hpb=db7d59355e4c8b70fc0a510f9bfde93134d6991c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php b/includes/libs/rdbms/loadbalancer/LoadBalancer.php index 1be8926bfa..a9eaa9974e 100644 --- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php @@ -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;