Reedy has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/396443 )
Change subject: Revert "objectcache: Make WANObjectCache interim caching not interfere with ChronologyProtector" ...................................................................... Revert "objectcache: Make WANObjectCache interim caching not interfere with ChronologyProtector" This reverts commit e90eafdf6107d4e49c9c20f6310d1d6ee5f5c47f. Bug: T182322 Change-Id: Ifaf5623c21e22822fba14156ff2490d066dba726 --- M includes/Setup.php M includes/libs/objectcache/WANObjectCache.php M tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php 3 files changed, 11 insertions(+), 94 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/43/396443/1 diff --git a/includes/Setup.php b/includes/Setup.php index d6f4b2f..081ea68 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -736,20 +736,17 @@ // Initialize the request object in $wgRequest $wgRequest = RequestContext::getMain()->getRequest(); // BackCompat -// Set user IP/agent information for causal consistency purposes. -// The cpPosTime cookie has no prefix and is set by MediaWiki::preOutputCommit(). -$cpPosTime = $wgRequest->getFloat( 'cpPosTime', $wgRequest->getCookie( 'cpPosTime', '' ) ); +// Set user IP/agent information for causal consistency purposes MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->setRequestInfo( [ 'IPAddress' => $wgRequest->getIP(), 'UserAgent' => $wgRequest->getHeader( 'User-Agent' ), 'ChronologyProtection' => $wgRequest->getHeader( 'ChronologyProtection' ), - 'ChronologyPositionTime' => $cpPosTime + // The cpPosTime cookie has no prefix and is set by MediaWiki::preOutputCommit() + 'ChronologyPositionTime' => $wgRequest->getFloat( + 'cpPosTime', + $wgRequest->getCookie( 'cpPosTime', '' ) + ) ] ); -// Make sure that caching does not compromise the consistency improvements -if ( $cpPosTime ) { - MediaWikiServices::getInstance()->getMainWANObjectCache()->useInterimHoldOffCaching( false ); -} -unset( $cpPosTime ); // Useful debug output if ( $wgCommandLineMode ) { diff --git a/includes/libs/objectcache/WANObjectCache.php b/includes/libs/objectcache/WANObjectCache.php index 8f2c72a..6451443 100644 --- a/includes/libs/objectcache/WANObjectCache.php +++ b/includes/libs/objectcache/WANObjectCache.php @@ -91,8 +91,6 @@ protected $logger; /** @var StatsdDataFactoryInterface */ protected $stats; - /** @var bool Whether to use "interim" caching while keys are tombstoned */ - protected $useInterimHoldOffCaching = true; /** @var callable|null Function that takes a WAN cache callback and runs it later */ protected $asyncHandler; @@ -1209,10 +1207,6 @@ * @return mixed */ protected function getInterimValue( $key, $versioned, $minTime, &$asOf ) { - if ( !$this->useInterimHoldOffCaching ) { - return false; // disabled - } - $wrapped = $this->cache->get( self::INTERIM_KEY_PREFIX . $key ); list( $value ) = $this->unwrap( $wrapped, $this->getCurrentTime() ); if ( $value !== false && $this->isValid( $value, $versioned, $asOf, $minTime ) ) { @@ -1602,30 +1596,6 @@ */ public function clearProcessCache() { $this->processCaches = []; - } - - /** - * Enable or disable the use of brief caching for tombstoned keys - * - * When a key is purged via delete(), there normally is a period where caching - * is hold-off limited to an extremely short time. This method will disable that - * caching, forcing the callback to run for any of: - * - WANObjectCache::getWithSetCallback() - * - WANObjectCache::getMultiWithSetCallback() - * - WANObjectCache::getMultiWithUnionSetCallback() - * - * This is useful when both: - * - a) the database used by the callback is known to be up-to-date enough - * for some particular purpose (e.g. replica DB has applied transaction X) - * - b) the caller needs to exploit that fact, and therefore needs to avoid the - * use of inherently volatile and possibly stale interim keys - * - * @see WANObjectCache::delete() - * @param bool $enabled Whether to enable interim caching - * @since 1.31 - */ - final public function useInterimHoldOffCaching( $enabled ) { - $this->useInterimHoldOffCaching = $enabled; } /** diff --git a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php index e534f92..59b739d 100644 --- a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php +++ b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php @@ -808,6 +808,8 @@ $calls = 0; $func = function () use ( &$calls, $value, $cache, $key ) { ++$calls; + // Immediately kill any mutex rather than waiting a second + $cache->delete( $cache::MUTEX_KEY_PREFIX . $key ); return $value; }; @@ -815,7 +817,7 @@ $this->assertEquals( $value, $ret ); $this->assertEquals( 1, $calls, 'Value was populated' ); - // Acquire the mutex to verify that getWithSetCallback uses lockTSE properly + // Acquire a lock to verify that getWithSetCallback uses lockTSE properly $this->internalCache->add( $cache::MUTEX_KEY_PREFIX . $key, 1, 0 ); $checkKeys = [ wfRandomString() ]; // new check keys => force misses @@ -832,8 +834,8 @@ $ret = $cache->getWithSetCallback( $key, 30, $func, [ 'lockTSE' => 5, 'checkKeys' => $checkKeys ] ); - $this->assertEquals( $value, $ret, 'Callback was not used; used interim (mutex failed)' ); - $this->assertEquals( 2, $calls, 'Callback was not used; used interim (mutex failed)' ); + $this->assertEquals( $value, $ret, 'Callback was not used; used interim' ); + $this->assertEquals( 2, $calls, 'Callback was not used; used interim' ); } /** @@ -1222,58 +1224,6 @@ [ [], false ], [ [ 'version' => 1 ], true ] ]; - } - - /** - * @covers WANObjectCache::useInterimHoldOffCaching - * @covers WANObjectCache::getInterimValue - */ - public function testInterimHoldOffCaching() { - $cache = $this->cache; - - $value = 'CRL-40-940'; - $wasCalled = 0; - $func = function () use ( &$wasCalled, $value ) { - $wasCalled++; - - return $value; - }; - - $cache->useInterimHoldOffCaching( true ); - - $key = wfRandomString( 32 ); - $v = $cache->getWithSetCallback( $key, 60, $func ); - $v = $cache->getWithSetCallback( $key, 60, $func ); - $this->assertEquals( 1, $wasCalled, 'Value cached' ); - $cache->delete( $key ); - $v = $cache->getWithSetCallback( $key, 60, $func ); - $this->assertEquals( 2, $wasCalled, 'Value regenerated (got mutex)' ); // sets interim - $v = $cache->getWithSetCallback( $key, 60, $func ); - $this->assertEquals( 3, $wasCalled, 'Value regenerated (got mutex)' ); // sets interim - // Lock up the mutex so interim cache is used - $this->internalCache->add( $cache::MUTEX_KEY_PREFIX . $key, 1, 0 ); - $v = $cache->getWithSetCallback( $key, 60, $func ); - $this->assertEquals( 3, $wasCalled, 'Value interim cached (failed mutex)' ); - $this->internalCache->delete( $cache::MUTEX_KEY_PREFIX . $key ); - - $cache->useInterimHoldOffCaching( false ); - - $wasCalled = 0; - $key = wfRandomString( 32 ); - $v = $cache->getWithSetCallback( $key, 60, $func ); - $v = $cache->getWithSetCallback( $key, 60, $func ); - $this->assertEquals( 1, $wasCalled, 'Value cached' ); - $cache->delete( $key ); - $v = $cache->getWithSetCallback( $key, 60, $func ); - $this->assertEquals( 2, $wasCalled, 'Value regenerated (got mutex)' ); - $v = $cache->getWithSetCallback( $key, 60, $func ); - $this->assertEquals( 3, $wasCalled, 'Value still regenerated (got mutex)' ); - $v = $cache->getWithSetCallback( $key, 60, $func ); - $this->assertEquals( 4, $wasCalled, 'Value still regenerated (got mutex)' ); - // Lock up the mutex so interim cache is used - $this->internalCache->add( $cache::MUTEX_KEY_PREFIX . $key, 1, 0 ); - $v = $cache->getWithSetCallback( $key, 60, $func ); - $this->assertEquals( 5, $wasCalled, 'Value still regenerated (failed mutex)' ); } /** -- To view, visit https://gerrit.wikimedia.org/r/396443 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ifaf5623c21e22822fba14156ff2490d066dba726 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Reedy <re...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits