objectcache: make WANObjectCache::relayPurge() actually use $holdoff
authorAaron Schulz <aschulz@wikimedia.org>
Sun, 21 Jul 2019 09:53:53 +0000 (02:53 -0700)
committerKrinkle <krinklemail@gmail.com>
Sat, 24 Aug 2019 22:41:39 +0000 (22:41 +0000)
Fixes a regression introduced by 70547f3fa304 in 2016.

Change-Id: I5996b63c31ac3b382e838a6858b8585bdc8c585c

includes/libs/objectcache/wancache/WANObjectCache.php
tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php

index 1852685..b88b496 100644 (file)
@@ -506,6 +506,7 @@ class WANObjectCache implements IExpiringStore, IStoreKeyEncoder, LoggerAwareInt
                        }
                        $purgeValues[] = $purge;
                }
                        }
                        $purgeValues[] = $purge;
                }
+
                return $purgeValues;
        }
 
                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}",
                        // 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 {
                                $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,
                        $ok = $this->cache->set(
                                $key,
-                               $this->makePurgeValue( $this->getCurrentTime(), self::HOLDOFF_TTL_NONE ),
+                               $this->makePurgeValue( $this->getCurrentTime(), $holdoff ),
                                $ttl
                        );
                }
                                $ttl
                        );
                }
index 329c642..ac988e6 100644 (file)
@@ -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
        /**
         * @covers WANObjectCache::delete
         * @covers WANObjectCache::relayDelete