From bee2a209035169e1307106536338a413fb52f8fc Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 21 Jul 2019 02:53:53 -0700 Subject: [PATCH] objectcache: make WANObjectCache::relayPurge() actually use $holdoff Fixes a regression introduced by 70547f3fa304 in 2016. Change-Id: I5996b63c31ac3b382e838a6858b8585bdc8c585c --- .../objectcache/wancache/WANObjectCache.php | 7 +++-- .../libs/objectcache/WANObjectCacheTest.php | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/includes/libs/objectcache/wancache/WANObjectCache.php b/includes/libs/objectcache/wancache/WANObjectCache.php index 1852685d6c..b88b49697a 100644 --- a/includes/libs/objectcache/wancache/WANObjectCache.php +++ b/includes/libs/objectcache/wancache/WANObjectCache.php @@ -506,6 +506,7 @@ class WANObjectCache implements IExpiringStore, IStoreKeyEncoder, LoggerAwareInt } $purgeValues[] = $purge; } + return $purgeValues; } @@ -2207,14 +2208,14 @@ class WANObjectCache implements IExpiringStore, IStoreKeyEncoder, LoggerAwareInt // Wildcards select all matching routes, e.g. the WAN cluster on all DCs $ok = $this->cache->set( "/*/{$this->cluster}/{$key}", - $this->makePurgeValue( $this->getCurrentTime(), self::HOLDOFF_TTL_NONE ), + $this->makePurgeValue( $this->getCurrentTime(), $holdoff ), $ttl ); } else { - // This handles the mcrouter and the single-DC case + // Some other proxy handles broadcasting or there is only one datacenter $ok = $this->cache->set( $key, - $this->makePurgeValue( $this->getCurrentTime(), self::HOLDOFF_TTL_NONE ), + $this->makePurgeValue( $this->getCurrentTime(), $holdoff ), $ttl ); } diff --git a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php index 329c6426bf..ac988e6467 100644 --- a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php +++ b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php @@ -1348,6 +1348,35 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase { } } + /** + * @covers WANObjectCache::get() + * @covers WANObjectCache::processCheckKeys() + */ + public function testCheckKeyHoldoff() { + $cache = $this->cache; + $key = wfRandomString(); + $checkKey = wfRandomString(); + + $mockWallClock = 1549343530.2053; + $cache->setMockTime( $mockWallClock ); + $cache->touchCheckKey( $checkKey, 8 ); + + $mockWallClock += 1; + $cache->set( $key, 1, 60 ); + $this->assertEquals( 1, $cache->get( $key, $curTTL, [ $checkKey ] ) ); + $this->assertLessThan( 0, $curTTL, "Key in hold-off due to check key" ); + + $mockWallClock += 3; + $cache->set( $key, 1, 60 ); + $this->assertEquals( 1, $cache->get( $key, $curTTL, [ $checkKey ] ) ); + $this->assertLessThan( 0, $curTTL, "Key in hold-off due to check key" ); + + $mockWallClock += 10; + $cache->set( $key, 1, 60 ); + $this->assertEquals( 1, $cache->get( $key, $curTTL, [ $checkKey ] ) ); + $this->assertGreaterThan( 0, $curTTL, "Key not in hold-off due to check key" ); + } + /** * @covers WANObjectCache::delete * @covers WANObjectCache::relayDelete -- 2.20.1