[MediaWiki-commits] [Gerrit] objectcache: Move WANObjectCache holdoff from get() to purge... - change (mediawiki/core)
Krinkle has uploaded a new change for review. https://gerrit.wikimedia.org/r/256414 Change subject: objectcache: Move WANObjectCache holdoff from get() to purge value .. objectcache: Move WANObjectCache holdoff from get() to purge value Move the holdoff period into the purge value instead of deciding it at runtime. This opens the way for touchCheckKey() to support a custom $holdoff parameter, which will allow callers to invalidate keys without a holdoff period. Right now the holdoff period is decided at run time. Change-Id: Id10c036272e92ae4429effc823b75e08fb11a48b --- M includes/libs/objectcache/WANObjectCache.php 1 file changed, 75 insertions(+), 42 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/14/256414/1 diff --git a/includes/libs/objectcache/WANObjectCache.php b/includes/libs/objectcache/WANObjectCache.php index 16e894e..8533d28 100644 --- a/includes/libs/objectcache/WANObjectCache.php +++ b/includes/libs/objectcache/WANObjectCache.php @@ -115,6 +115,7 @@ const FLD_TTL = 2; const FLD_TIME = 3; const FLD_FLAGS = 4; + const FLD_HOLDOFF = 4; /** @var integer Treat this value as expired-on-arrival */ const FLG_STALE = 1; @@ -232,18 +233,18 @@ $vPrefixLen = strlen( self::VALUE_KEY_PREFIX ); $valueKeys = self::prefixCacheKeys( $keys, self::VALUE_KEY_PREFIX ); - $checksForAll = array(); - $checksByKey = array(); + $checkKeysForAll = array(); + $checkKeysByKey = array(); $checkKeysFlat = array(); foreach ( $checkKeys as $i => $keys ) { $prefixed = self::prefixCacheKeys( (array)$keys, self::TIME_KEY_PREFIX ); $checkKeysFlat = array_merge( $checkKeysFlat, $prefixed ); // Is this check keys for a specific cache key, or for all keys being fetched? if ( is_int( $i ) ) { - $checksForAll = array_merge( $checksForAll, $prefixed ); + $checkKeysForAll = array_merge( $checkKeysForAll, $prefixed ); } else { - $checksByKey[$i] = isset( $checksByKey[$i] ) - ? array_merge( $checksByKey[$i], $prefixed ) + $checkKeysByKey[$i] = isset( $checkKeysByKey[$i] ) + ? array_merge( $checkKeysByKey[$i], $prefixed ) : $prefixed; } } @@ -253,10 +254,10 @@ $now = microtime( true ); // Collect timestamps from all "check" keys - $checkKeyTimesForAll = $this->processCheckKeys( $checksForAll, $wrappedValues, $now ); - $checkKeyTimesByKey = array(); - foreach ( $checksByKey as $cacheKey => $checks ) { - $checkKeyTimesByKey[$cacheKey] = + $purgeValuesForAll = $this->processCheckKeys( $checkKeysForAll, $wrappedValues, $now ); + $purgeValuesByKey = array(); + foreach ( $checkKeysByKey as $cacheKey => $checks ) { + $purgeValuesByKey[$cacheKey] = $this->processCheckKeys( $checks, $wrappedValues, $now ); } @@ -274,14 +275,14 @@ // Force dependant keys to be invalid for a while after purging // to reduce race conditions involving stale data getting cached - $checkKeyTimes = $checkKeyTimesForAll; - if ( isset( $checkKeyTimesByKey[$key] ) ) { - $checkKeyTimes = array_merge( $checkKeyTimes, $checkKeyTimesByKey[$key] ); + $purgeValues = $purgeValuesForAll; + if ( isset( $purgeValuesByKey[$key] ) ) { + $purgeValues = array_merge( $purgeValues, $purgeValuesByKey[$key] ); } - foreach ( $checkKeyTimes as $checkKeyTime ) { - $safeTimestamp = $checkKeyTime + self::HOLDOFF_TTL; + foreach ( $purgeValues as $purge ) { + $safeTimestamp = $purge[self::FLD_TIME] + $purge[self::FLD_HOLDOFF]; if ( $safeTimestamp >= $wrappedValues[$vKey][self::FLD_TIME] ) { - $curTTL = min( $curTTL, $checkKeyTime - $now ); + $curTTL = min( $curTTL, $purge[self::FLD_TIME] - $now ); }
[MediaWiki-commits] [Gerrit] objectcache: Move WANObjectCache holdoff from get() to purge... - change (mediawiki/core)
jenkins-bot has submitted this change and it was merged. Change subject: objectcache: Move WANObjectCache holdoff from get() to purge value .. objectcache: Move WANObjectCache holdoff from get() to purge value Move the holdoff period into the purge value instead of deciding it at runtime. This opens the way for touchCheckKey() to support a custom $holdoff parameter, which will allow callers to invalidate keys without a holdoff period. Similar to what we already support in delete(). Right now the holdoff period is decided at run time. Change-Id: Id10c036272e92ae4429effc823b75e08fb11a48b --- M includes/libs/objectcache/WANObjectCache.php 1 file changed, 81 insertions(+), 47 deletions(-) Approvals: Aaron Schulz: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/libs/objectcache/WANObjectCache.php b/includes/libs/objectcache/WANObjectCache.php index 16e894e..1c900cd 100644 --- a/includes/libs/objectcache/WANObjectCache.php +++ b/includes/libs/objectcache/WANObjectCache.php @@ -115,6 +115,7 @@ const FLD_TTL = 2; const FLD_TIME = 3; const FLD_FLAGS = 4; + const FLD_HOLDOFF = 5; /** @var integer Treat this value as expired-on-arrival */ const FLG_STALE = 1; @@ -232,18 +233,18 @@ $vPrefixLen = strlen( self::VALUE_KEY_PREFIX ); $valueKeys = self::prefixCacheKeys( $keys, self::VALUE_KEY_PREFIX ); - $checksForAll = array(); - $checksByKey = array(); + $checkKeysForAll = array(); + $checkKeysByKey = array(); $checkKeysFlat = array(); foreach ( $checkKeys as $i => $keys ) { $prefixed = self::prefixCacheKeys( (array)$keys, self::TIME_KEY_PREFIX ); $checkKeysFlat = array_merge( $checkKeysFlat, $prefixed ); // Is this check keys for a specific cache key, or for all keys being fetched? if ( is_int( $i ) ) { - $checksForAll = array_merge( $checksForAll, $prefixed ); + $checkKeysForAll = array_merge( $checkKeysForAll, $prefixed ); } else { - $checksByKey[$i] = isset( $checksByKey[$i] ) - ? array_merge( $checksByKey[$i], $prefixed ) + $checkKeysByKey[$i] = isset( $checkKeysByKey[$i] ) + ? array_merge( $checkKeysByKey[$i], $prefixed ) : $prefixed; } } @@ -253,10 +254,10 @@ $now = microtime( true ); // Collect timestamps from all "check" keys - $checkKeyTimesForAll = $this->processCheckKeys( $checksForAll, $wrappedValues, $now ); - $checkKeyTimesByKey = array(); - foreach ( $checksByKey as $cacheKey => $checks ) { - $checkKeyTimesByKey[$cacheKey] = + $purgeValuesForAll = $this->processCheckKeys( $checkKeysForAll, $wrappedValues, $now ); + $purgeValuesByKey = array(); + foreach ( $checkKeysByKey as $cacheKey => $checks ) { + $purgeValuesByKey[$cacheKey] = $this->processCheckKeys( $checks, $wrappedValues, $now ); } @@ -274,14 +275,14 @@ // Force dependant keys to be invalid for a while after purging // to reduce race conditions involving stale data getting cached - $checkKeyTimes = $checkKeyTimesForAll; - if ( isset( $checkKeyTimesByKey[$key] ) ) { - $checkKeyTimes = array_merge( $checkKeyTimes, $checkKeyTimesByKey[$key] ); + $purgeValues = $purgeValuesForAll; + if ( isset( $purgeValuesByKey[$key] ) ) { + $purgeValues = array_merge( $purgeValues, $purgeValuesByKey[$key] ); } - foreach ( $checkKeyTimes as $checkKeyTime ) { - $safeTimestamp = $checkKeyTime + self::HOLDOFF_TTL; + foreach ( $purgeValues as $purge ) { + $safeTimestamp = $purge[self::FLD_TIME] + $purge[self::FLD_HOLDOFF]; if ( $safeTimestamp >= $wrappedValues[$vKey][self::FLD_TIME] ) { - $curTTL = min( $curTTL, $checkKeyTime - $now ); + $curTTL = min( $curTTL, $purge[self::FLD_TIME] - $now );