From 6cc65335f30cc90fcf661ed06865960c1c9ab428 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 31 Oct 2015 13:05:03 -0700 Subject: [PATCH] Convert SiteStatsUpdate to using getMainStashInstance() Also fixed various $wgMemc related comments Change-Id: I20602b672f724c8df1e82bbe3c586cb899a54640 --- includes/cache/CacheDependency.php | 2 +- includes/deferred/SiteStatsUpdate.php | 20 ++++++++----------- includes/jobqueue/README | 1 - includes/objectcache/ObjectCache.php | 2 +- .../objectcache/ObjectCacheSessionHandler.php | 2 +- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/includes/cache/CacheDependency.php b/includes/cache/CacheDependency.php index 2abcabdc22..0a45b8ef26 100644 --- a/includes/cache/CacheDependency.php +++ b/includes/cache/CacheDependency.php @@ -98,7 +98,7 @@ class DependencyWrapper { * it will be generated with the callback function (if present), and the newly * calculated value will be stored to the cache in a wrapper. * - * @param BagOStuff $cache A cache object such as $wgMemc + * @param BagOStuff $cache A cache object * @param string $key The cache key * @param int $expiry The expiry timestamp or interval in seconds * @param bool|callable $callback The callback for generating the value, or false diff --git a/includes/deferred/SiteStatsUpdate.php b/includes/deferred/SiteStatsUpdate.php index d135a80457..73de7558d8 100644 --- a/includes/deferred/SiteStatsUpdate.php +++ b/includes/deferred/SiteStatsUpdate.php @@ -207,8 +207,7 @@ class SiteStatsUpdate implements DeferrableUpdate { * @param int $delta Delta (positive or negative) */ protected function adjustPending( $type, $delta ) { - global $wgMemc; - + $cache = ObjectCache::getMainStashInstance(); if ( $delta < 0 ) { // decrement $key = $this->getTypeCacheKey( $type, '-' ); } else { // increment @@ -216,11 +215,7 @@ class SiteStatsUpdate implements DeferrableUpdate { } $magnitude = abs( $delta ); - if ( !$wgMemc->incr( $key, $magnitude ) ) { // not there? - if ( !$wgMemc->add( $key, $magnitude ) ) { // race? - $wgMemc->incr( $key, $magnitude ); - } - } + $cache->incrWithInit( $key, 0, $magnitude, $magnitude ); } /** @@ -228,15 +223,16 @@ class SiteStatsUpdate implements DeferrableUpdate { * @return array Positive and negative deltas for each type */ protected function getPendingDeltas() { - global $wgMemc; + $cache = ObjectCache::getMainStashInstance(); $pending = array(); foreach ( array( 'ss_total_edits', 'ss_good_articles', 'ss_total_pages', 'ss_users', 'ss_images' ) as $type ) { // Get pending increments and pending decrements - $pending[$type]['+'] = (int)$wgMemc->get( $this->getTypeCacheKey( $type, '+' ) ); - $pending[$type]['-'] = (int)$wgMemc->get( $this->getTypeCacheKey( $type, '-' ) ); + $flg = BagOStuff::READ_LATEST; + $pending[$type]['+'] = (int)$cache->get( $this->getTypeCacheKey( $type, '+' ), $flg ); + $pending[$type]['-'] = (int)$cache->get( $this->getTypeCacheKey( $type, '-' ), $flg ); } return $pending; @@ -247,12 +243,12 @@ class SiteStatsUpdate implements DeferrableUpdate { * @param array $pd Result of getPendingDeltas(), used for DB update */ protected function removePendingDeltas( array $pd ) { - global $wgMemc; + $cache = ObjectCache::getMainStashInstance(); foreach ( $pd as $type => $deltas ) { foreach ( $deltas as $sign => $magnitude ) { // Lower the pending counter now that we applied these changes - $wgMemc->decr( $this->getTypeCacheKey( $type, $sign ), $magnitude ); + $cache->decr( $this->getTypeCacheKey( $type, $sign ), $magnitude ); } } } diff --git a/includes/jobqueue/README b/includes/jobqueue/README index c11d5a78e0..af836bc502 100644 --- a/includes/jobqueue/README +++ b/includes/jobqueue/README @@ -61,7 +61,6 @@ large amounts of time polling empty queues, aggregators exists to keep track of which queues are ready. The following queue aggregator classes are available: -* JobQueueAggregatorMemc (uses $wgMemc to track ready queues) * JobQueueAggregatorRedis (uses a redis server to track ready queues) Some aggregators cache data for a few minutes while others may be always up to date. diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index 3d14c33f10..27d8802596 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -63,7 +63,7 @@ use MediaWiki\Logger\LoggerFactory; * Purpose: Memory storage for per-cluster coordination and tracking. * A typical use case would be a rate limit counter or cache regeneration mutex. * Stored centrally within the local data-center. Not replicated to other DCs. - * Also known as $wgMemc. Configured by $wgMainCacheType. + * Configured by $wgMainCacheType. * * - wfGetCache( $cacheType ) * Get a specific cache type by key in $wgObjectCaches. diff --git a/includes/objectcache/ObjectCacheSessionHandler.php b/includes/objectcache/ObjectCacheSessionHandler.php index 2a5d69556f..cc85074175 100644 --- a/includes/objectcache/ObjectCacheSessionHandler.php +++ b/includes/objectcache/ObjectCacheSessionHandler.php @@ -47,7 +47,7 @@ class ObjectCacheSessionHandler { // It's necessary to register a shutdown function to call session_write_close(), // because by the time the request shutdown function for the session module is - // called, $wgMemc has already been destroyed. Shutdown functions registered + // called, the BagOStuff has already been destroyed. Shutdown functions registered // this way are called before object destruction. register_shutdown_function( array( __CLASS__, 'handleShutdown' ) ); } -- 2.20.1