Convert SiteStatsUpdate to using getMainStashInstance()
authorAaron Schulz <aschulz@wikimedia.org>
Sat, 31 Oct 2015 20:05:03 +0000 (13:05 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Sat, 31 Oct 2015 20:05:03 +0000 (13:05 -0700)
Also fixed various $wgMemc related comments

Change-Id: I20602b672f724c8df1e82bbe3c586cb899a54640

includes/cache/CacheDependency.php
includes/deferred/SiteStatsUpdate.php
includes/jobqueue/README
includes/objectcache/ObjectCache.php
includes/objectcache/ObjectCacheSessionHandler.php

index 2abcabd..0a45b8e 100644 (file)
@@ -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
index d135a80..73de755 100644 (file)
@@ -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 );
                        }
                }
        }
index c11d5a7..af836bc 100644 (file)
@@ -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.
index 3d14c33..27d8802 100644 (file)
@@ -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.
index 2a5d695..cc85074 100644 (file)
@@ -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' ) );
        }