X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2Floadmonitor%2FLoadMonitor.php;h=fdc5ac8146fe7b5fcac1482b43d6c8f8e902b90f;hp=4300e9f1cd614601595c2d50d71584ecd15a8598;hb=802c199d0bd80ff0f4d730c61fd58cbf08a52d8d;hpb=aae0c8d42562d5d3f70cc18fa687ae331996b66f diff --git a/includes/libs/rdbms/loadmonitor/LoadMonitor.php b/includes/libs/rdbms/loadmonitor/LoadMonitor.php index 4300e9f1cd..fdc5ac8146 100644 --- a/includes/libs/rdbms/loadmonitor/LoadMonitor.php +++ b/includes/libs/rdbms/loadmonitor/LoadMonitor.php @@ -25,6 +25,7 @@ use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use Wikimedia\ScopedCallback; use BagOStuff; +use WANObjectCache; /** * Basic DB load monitor with no external dependencies @@ -37,8 +38,8 @@ class LoadMonitor implements ILoadMonitor { protected $parent; /** @var BagOStuff */ protected $srvCache; - /** @var BagOStuff */ - protected $mainCache; + /** @var WANObjectCache */ + protected $wanCache; /** @var LoggerInterface */ protected $replLogger; @@ -48,11 +49,11 @@ class LoadMonitor implements ILoadMonitor { const VERSION = 1; // cache key version public function __construct( - ILoadBalancer $lb, BagOStuff $srvCache, BagOStuff $cache, array $options = [] + ILoadBalancer $lb, BagOStuff $srvCache, WANObjectCache $wCache, array $options = [] ) { $this->parent = $lb; $this->srvCache = $srvCache; - $this->mainCache = $cache; + $this->wanCache = $wCache; $this->replLogger = new NullLogger(); $this->movingAveRatio = isset( $options['movingAveRatio'] ) @@ -109,7 +110,7 @@ class LoadMonitor implements ILoadMonitor { $staleValue = $value ?: false; # (b) Check the shared cache and backfill APC - $value = $this->mainCache->get( $key ); + $value = $this->wanCache->get( $key ); if ( $value && $value['timestamp'] > ( microtime( true ) - $ttl ) ) { $this->srvCache->set( $key, $value, $staleTTL ); $this->replLogger->debug( __METHOD__ . ": got lag times ($key) from main cache" ); @@ -119,12 +120,12 @@ class LoadMonitor implements ILoadMonitor { $staleValue = $value ?: $staleValue; # (c) Cache key missing or expired; regenerate and backfill - if ( $this->mainCache->lock( $key, 0, 10 ) ) { - # Let this process alone update the cache value - $cache = $this->mainCache; + if ( $this->srvCache->lock( $key, 0, 10 ) ) { + # Let only this process update the cache value on this server + $sCache = $this->srvCache; /** @noinspection PhpUnusedLocalVariableInspection */ - $unlocker = new ScopedCallback( function () use ( $cache, $key ) { - $cache->unlock( $key ); + $unlocker = new ScopedCallback( function () use ( $sCache, $key ) { + $sCache->unlock( $key ); } ); } elseif ( $staleValue ) { # Could not acquire lock but an old cache exists, so use it @@ -145,7 +146,7 @@ class LoadMonitor implements ILoadMonitor { if ( $conn ) { $close = false; // already open } else { - $conn = $this->parent->openConnection( $i, $domain ); + $conn = $this->parent->openConnection( $i, '' ); $close = true; // new connection } @@ -196,7 +197,7 @@ class LoadMonitor implements ILoadMonitor { 'weightScales' => $weightScales, 'timestamp' => microtime( true ) ]; - $this->mainCache->set( $key, $value, $staleTTL ); + $this->wanCache->set( $key, $value, $staleTTL ); $this->srvCache->set( $key, $value, $staleTTL ); $this->replLogger->info( __METHOD__ . ": re-calculated lag times ($key)" ); @@ -204,7 +205,7 @@ class LoadMonitor implements ILoadMonitor { } /** - * @param integer $index Server index + * @param int $index Server index * @param IDatabase|null $conn Connection handle or null on connection failure * @return float */