2525use Psr \Log \NullLogger ;
2626use Wikimedia \ScopedCallback ;
2727use BagOStuff ;
28+ use WANObjectCache ;
2829
2930/**
3031 * Basic DB load monitor with no external dependencies
@@ -37,8 +38,8 @@ class LoadMonitor implements ILoadMonitor {
3738protected $ parent ;
3839/** @var BagOStuff */
3940protected $ srvCache ;
40- /** @var BagOStuff */
41- protected $ mainCache ;
41+ /** @var WANObjectCache */
42+ protected $ wanCache ;
4243/** @var LoggerInterface */
4344protected $ replLogger ;
4445
@@ -48,11 +49,11 @@ class LoadMonitor implements ILoadMonitor {
4849const VERSION = 1 ; // cache key version
4950
5051public function __construct (
51- ILoadBalancer $ lb , BagOStuff $ srvCache , BagOStuff $ cache , array $ options = []
52+ ILoadBalancer $ lb , BagOStuff $ srvCache , WANObjectCache $ wCache , array $ options = []
5253) {
5354$ this ->parent = $ lb ;
5455$ this ->srvCache = $ srvCache ;
55- $ this ->mainCache = $ cache ;
56+ $ this ->wanCache = $ wCache ;
5657$ this ->replLogger = new NullLogger ();
5758
5859$ this ->movingAveRatio = isset ( $ options ['movingAveRatio ' ] )
@@ -109,7 +110,7 @@ protected function getServerStates( array $serverIndexes, $domain ) {
109110$ staleValue = $ value ?: false ;
110111
111112# (b) Check the shared cache and backfill APC
112- $ value = $ this ->mainCache ->get ( $ key );
113+ $ value = $ this ->wanCache ->get ( $ key );
113114if ( $ value && $ value ['timestamp ' ] > ( microtime ( true ) - $ ttl ) ) {
114115$ this ->srvCache ->set ( $ key , $ value , $ staleTTL );
115116$ this ->replLogger ->debug ( __METHOD__ . ": got lag times ( $ key) from main cache " );
@@ -119,12 +120,12 @@ protected function getServerStates( array $serverIndexes, $domain ) {
119120$ staleValue = $ value ?: $ staleValue ;
120121
121122# (c) Cache key missing or expired; regenerate and backfill
122- if ( $ this ->mainCache ->lock ( $ key , 0 , 10 ) ) {
123- # Let this process alone update the cache value
124- $ cache = $ this ->mainCache ;
123+ if ( $ this ->srvCache ->lock ( $ key , 0 , 10 ) ) {
124+ # Let only this process update the cache value on this server
125+ $ sCache = $ this ->srvCache ;
125126/** @noinspection PhpUnusedLocalVariableInspection */
126- $ unlocker = new ScopedCallback ( function () use ( $ cache , $ key ) {
127- $ cache ->unlock ( $ key );
127+ $ unlocker = new ScopedCallback ( function () use ( $ sCache , $ key ) {
128+ $ sCache ->unlock ( $ key );
128129} );
129130} elseif ( $ staleValue ) {
130131# Could not acquire lock but an old cache exists, so use it
@@ -196,7 +197,7 @@ protected function getServerStates( array $serverIndexes, $domain ) {
196197'weightScales ' => $ weightScales ,
197198'timestamp ' => microtime ( true )
198199];
199- $ this ->mainCache ->set ( $ key , $ value , $ staleTTL );
200+ $ this ->wanCache ->set ( $ key , $ value , $ staleTTL );
200201$ this ->srvCache ->set ( $ key , $ value , $ staleTTL );
201202$ this ->replLogger ->info ( __METHOD__ . ": re-calculated lag times ( $ key) " );
202203
0 commit comments