Merge "objectcache: Always use interim values on WAN cache tombstones"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 24 Oct 2017 00:42:46 +0000 (00:42 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 24 Oct 2017 00:42:46 +0000 (00:42 +0000)
includes/libs/objectcache/WANObjectCache.php
tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php

index bacea7b..0531d7f 100644 (file)
@@ -969,6 +969,10 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
 
                // A deleted key with a negative TTL left must be tombstoned
                $isTombstone = ( $curTTL !== null && $value === false );
+               if ( $isTombstone && $lockTSE <= 0 ) {
+                       // Use the INTERIM value for tombstoned keys to reduce regeneration load
+                       $lockTSE = 1;
+               }
                // Assume a key is hot if requested soon after invalidation
                $isHot = ( $curTTL !== null && $curTTL <= 0 && abs( $curTTL ) <= $lockTSE );
                // Use the mutex if there is no value and a busy fallback is given
@@ -1037,7 +1041,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
 
                if ( $lockAcquired ) {
                        // Avoid using delete() to avoid pointless mcrouter broadcasting
-                       $this->cache->changeTTL( self::MUTEX_KEY_PREFIX . $key, 1 );
+                       $this->cache->changeTTL( self::MUTEX_KEY_PREFIX . $key, (int)$preCallbackTime - 60 );
                }
 
                return $value;
@@ -1756,7 +1760,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
                return array_diff( $keys, $keysFound );
        }
 
-               /**
+       /**
         * @param array $keys
         * @param array $checkKeys
         * @return array Map of (cache key => mixed)
index c5a1759..e23f318 100644 (file)
@@ -159,8 +159,9 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
                $this->assertEquals( 9, $hit, "Values evicted" );
 
                $key = reset( $keys );
-               // Get into cache
+               // Get into cache (default process cache group)
                $this->cache->getWithSetCallback( $key, 100, $callback, [ 'pcTTL' => 5 ] );
+               $this->assertEquals( 10, $hit, "Value calculated" );
                $this->cache->getWithSetCallback( $key, 100, $callback, [ 'pcTTL' => 5 ] );
                $this->assertEquals( 10, $hit, "Value cached" );
                $outerCallback = function () use ( &$callback, $key ) {
@@ -168,7 +169,8 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase {
 
                        return 43 + $v;
                };
-               $this->cache->getWithSetCallback( $key, 100, $outerCallback );
+               // Outer key misses and refuses inner key process cache value
+               $this->cache->getWithSetCallback( "$key-miss-outer", 100, $outerCallback );
                $this->assertEquals( 11, $hit, "Nested callback value process cache skipped" );
        }