Skip to content

Commit 7bada04

Browse files
jenkins-botGerrit Code Review
authored andcommitted
Merge "Remove "memCache" field from LoadBalancer"
2 parents ebcb7ae + 62fcaec commit 7bada04

File tree

6 files changed

+21
-25
lines changed

6 files changed

+21
-25
lines changed

includes/libs/rdbms/loadbalancer/ILoadBalancer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ interface ILoadBalancer {
9494
* - readOnlyReason : Reason the master DB is read-only if so [optional]
9595
* - waitTimeout : Maximum time to wait for replicas for consistency [optional]
9696
* - srvCache : BagOStuff object for server cache [optional]
97-
* - memCache : BagOStuff object for cluster memory cache [optional]
9897
* - wanCache : WANObjectCache object [optional]
9998
* - chronologyProtector: ChronologyProtector object [optional]
10099
* - hostname : The name of the current server [optional]

includes/libs/rdbms/loadbalancer/LoadBalancer.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ class LoadBalancer implements ILoadBalancer {
6262
private $chronProt;
6363
/** @var BagOStuff */
6464
private $srvCache;
65-
/** @var BagOStuff */
66-
private $memCache;
6765
/** @var WANObjectCache */
6866
private $wanCache;
6967
/** @var object|string Class name or object With profileIn/profileOut methods */
@@ -187,11 +185,6 @@ public function __construct( array $params ) {
187185
} else {
188186
$this->srvCache = new EmptyBagOStuff();
189187
}
190-
if ( isset( $params['memCache'] ) ) {
191-
$this->memCache = $params['memCache'];
192-
} else {
193-
$this->memCache = new EmptyBagOStuff();
194-
}
195188
if ( isset( $params['wanCache'] ) ) {
196189
$this->wanCache = $params['wanCache'];
197190
} else {
@@ -244,7 +237,7 @@ private function getLoadMonitor() {
244237
}
245238

246239
$this->loadMonitor = new $class(
247-
$this, $this->srvCache, $this->memCache, $this->loadMonitorConfig );
240+
$this, $this->srvCache, $this->wanCache, $this->loadMonitorConfig );
248241
$this->loadMonitor->setLogger( $this->replLogger );
249242
}
250243

includes/libs/rdbms/loadmonitor/ILoadMonitor.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
use Psr\Log\LoggerAwareInterface;
2727
use BagOStuff;
28+
use WANObjectCache;
2829

2930
/**
3031
* An interface for database load monitoring
@@ -37,11 +38,11 @@ interface ILoadMonitor extends LoggerAwareInterface {
3738
*
3839
* @param ILoadBalancer $lb LoadBalancer this instance serves
3940
* @param BagOStuff $sCache Local server memory cache
40-
* @param BagOStuff $cCache Local cluster memory cache
41+
* @param WANObjectCache $wCache Local cluster memory cache
4142
* @param array $options Options map
4243
*/
4344
public function __construct(
44-
ILoadBalancer $lb, BagOStuff $sCache, BagOStuff $cCache, array $options = []
45+
ILoadBalancer $lb, BagOStuff $sCache, WANObjectCache $wCache, array $options = []
4546
);
4647

4748
/**

includes/libs/rdbms/loadmonitor/LoadMonitor.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Psr\Log\NullLogger;
2626
use Wikimedia\ScopedCallback;
2727
use BagOStuff;
28+
use WANObjectCache;
2829

2930
/**
3031
* Basic DB load monitor with no external dependencies
@@ -37,8 +38,8 @@ class LoadMonitor implements ILoadMonitor {
3738
protected $parent;
3839
/** @var BagOStuff */
3940
protected $srvCache;
40-
/** @var BagOStuff */
41-
protected $mainCache;
41+
/** @var WANObjectCache */
42+
protected $wanCache;
4243
/** @var LoggerInterface */
4344
protected $replLogger;
4445

@@ -48,11 +49,11 @@ class LoadMonitor implements ILoadMonitor {
4849
const VERSION = 1; // cache key version
4950

5051
public 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 );
113114
if ( $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

includes/libs/rdbms/loadmonitor/LoadMonitorMySQL.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
namespace Wikimedia\Rdbms;
2323

2424
use BagOStuff;
25+
use WANObjectCache;
2526

2627
/**
2728
* Basic MySQL load monitor with no external dependencies
@@ -34,9 +35,9 @@ class LoadMonitorMySQL extends LoadMonitor {
3435
private $warmCacheRatio;
3536

3637
public function __construct(
37-
ILoadBalancer $lb, BagOStuff $srvCache, BagOStuff $cache, array $options = []
38+
ILoadBalancer $lb, BagOStuff $srvCache, WANObjectCache $wCache, array $options = []
3839
) {
39-
parent::__construct( $lb, $srvCache, $cache, $options );
40+
parent::__construct( $lb, $srvCache, $wCache, $options );
4041

4142
$this->warmCacheRatio = isset( $options['warmCacheRatio'] )
4243
? $options['warmCacheRatio']

includes/libs/rdbms/loadmonitor/LoadMonitorNull.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323

2424
use Psr\Log\LoggerInterface;
2525
use BagOStuff;
26+
use WANObjectCache;
2627

2728
class LoadMonitorNull implements ILoadMonitor {
2829
public function __construct(
29-
ILoadBalancer $lb, BagOStuff $sCache, BagOStuff $cCache, array $options = []
30+
ILoadBalancer $lb, BagOStuff $sCache, WANObjectCache $wCache, array $options = []
3031
) {
3132
}
3233

0 commit comments

Comments
 (0)