Merge "User: Migrate from foreign cache to global cache for UserRightsProxy"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 2 Nov 2015 23:51:52 +0000 (23:51 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 2 Nov 2015 23:51:52 +0000 (23:51 +0000)
21 files changed:
includes/DefaultSettings.php
includes/GlobalFunctions.php
includes/TemplateParser.php
includes/cache/CacheDependency.php
includes/cache/MessageCache.php
includes/db/Database.php
includes/db/loadbalancer/LoadMonitorMySQL.php
includes/deferred/SiteStatsUpdate.php
includes/filebackend/SwiftFileBackend.php
includes/filebackend/lockmanager/DBLockManager.php
includes/jobqueue/README
includes/media/TransformationalImageHandler.php
includes/objectcache/ObjectCache.php
includes/objectcache/ObjectCacheSessionHandler.php
includes/parser/DateFormatter.php
includes/registration/ExtensionRegistry.php
includes/resourceloader/ResourceLoader.php
includes/resourceloader/ResourceLoaderFileModule.php
includes/utils/FileContentsHasher.php
includes/utils/MWCryptHKDF.php
includes/utils/UIDGenerator.php

index d20b931..6032ba3 100644 (file)
@@ -2211,7 +2211,7 @@ $wgObjectCaches = array(
        CACHE_DB => array( 'class' => 'SqlBagOStuff', 'loggroup' => 'SQLBagOStuff' ),
 
        CACHE_ANYTHING => array( 'factory' => 'ObjectCache::newAnything' ),
-       CACHE_ACCEL => array( 'factory' => 'ObjectCache::newAccelerator' ),
+       CACHE_ACCEL => array( 'factory' => 'ObjectCache::getLocalServerInstance' ),
        CACHE_MEMCACHED => array( 'class' => 'MemcachedPhpBagOStuff', 'loggroup' => 'memcached' ),
 
        'db-replicated' => array(
index 791bf33..3bc3a90 100644 (file)
@@ -4010,7 +4010,7 @@ function wfIsBadImage( $name, $contextTitle = false, $blacklist = null ) {
                return $bad;
        }
 
-       $cache = ObjectCache::newAccelerator( 'hash' );
+       $cache = ObjectCache::getLocalServerInstance( 'hash' );
        $key = wfMemcKey( 'bad-image-list', ( $blacklist === null ) ? 'default' : md5( $blacklist ) );
        $badImages = $cache->get( $key );
 
index 44d264d..8ce3420 100644 (file)
@@ -103,7 +103,7 @@ class TemplateParser {
 
                if ( $secretKey ) {
                        // See if the compiled PHP code is stored in cache.
-                       $cache = ObjectCache::newAccelerator( CACHE_ANYTHING );
+                       $cache = ObjectCache::getLocalServerInstance( CACHE_ANYTHING );
                        $key = $cache->makeKey( 'template', $templateName, $fastHash );
                        $code = $this->forceRecompile ? null : $cache->get( $key );
 
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 bcfa792..ae746e3 100644 (file)
@@ -154,7 +154,7 @@ class MessageCache {
                $this->mExpiry = $expiry;
 
                if ( $wgUseLocalMessageCache ) {
-                       $this->localCache = ObjectCache::newAccelerator( CACHE_NONE );
+                       $this->localCache = ObjectCache::getLocalServerInstance( CACHE_NONE );
                } else {
                        $this->localCache = wfGetCache( CACHE_NONE );
                }
index cf774fa..531086b 100644 (file)
@@ -615,7 +615,7 @@ abstract class DatabaseBase implements IDatabase {
        function __construct( array $params ) {
                global $wgDBprefix, $wgDBmwschema, $wgCommandLineMode;
 
-               $this->srvCache = ObjectCache::newAccelerator( 'hash' );
+               $this->srvCache = ObjectCache::getLocalServerInstance( 'hash' );
 
                $server = $params['host'];
                $user = $params['user'];
index f49e965..59d6ef6 100644 (file)
@@ -36,7 +36,7 @@ class LoadMonitorMySQL implements LoadMonitor {
        public function __construct( $parent ) {
                $this->parent = $parent;
 
-               $this->srvCache = ObjectCache::newAccelerator( 'hash' );
+               $this->srvCache = ObjectCache::getLocalServerInstance( 'hash' );
                $this->mainCache = ObjectCache::getLocalClusterInstance();
        }
 
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 83c1da1..8097549 100644 (file)
@@ -140,7 +140,7 @@ class SwiftFileBackend extends FileBackendStore {
                                $this->srvCache = ObjectCache::getLocalClusterInstance();
                        } else {
                                // Look for APC, XCache, WinCache, ect...
-                               $this->srvCache = ObjectCache::newAccelerator( CACHE_NONE );
+                               $this->srvCache = ObjectCache::getLocalServerInstance( CACHE_NONE );
                        }
                } else {
                        $this->srvCache = new EmptyBagOStuff();
index 9d4f009..42ebb46 100644 (file)
@@ -95,12 +95,7 @@ abstract class DBLockManager extends QuorumLockManager {
                        if ( count( $bucket ) > 1 ) { // multiple peers
                                // Tracks peers that couldn't be queried recently to avoid lengthy
                                // connection timeouts. This is useless if each bucket has one peer.
-                               try {
-                                       $this->statusCache = ObjectCache::newAccelerator();
-                               } catch ( Exception $e ) {
-                                       trigger_error( __CLASS__ .
-                                               " using multiple DB peers without apc, xcache, or wincache." );
-                               }
+                               $this->statusCache = ObjectCache::getLocalServerInstance();
                                break;
                        }
                }
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 30f9e2e..f72df19 100644 (file)
@@ -508,7 +508,7 @@ abstract class TransformationalImageHandler extends ImageHandler {
         * @return string|bool Representing the IM version; false on error
         */
        protected function getMagickVersion() {
-               $cache = ObjectCache::newAccelerator( CACHE_NONE );
+               $cache = ObjectCache::getLocalServerInstance( CACHE_NONE );
                return $cache->getWithSetCallback(
                        'imagemagick-version',
                        $cache::TTL_HOUR,
index abb88ba..b4aecee 100644 (file)
@@ -42,30 +42,31 @@ use MediaWiki\Logger\LoggerFactory;
  *
  * Primary entry points:
  *
- * - ObjectCache::newAccelerator( $fallbackType )
- *   Purpose: Cache for very hot keys.
- *   Stored only on the individual web server.
- *   Not associated with other servers.
- *
  * - ObjectCache::getMainWANInstance()
- *   Purpose: Cache.
+ *   Purpose: Memory cache.
  *   Stored in the local data-center's main cache (uses different cache keys).
  *   Delete events are broadcasted to other DCs. See WANObjectCache for details.
  *
- * - ObjectCache::getMainStashInstance()
- *   Purpose: Ephemeral storage.
- *   Stored centrally within the primary data-center.
- *   Changes are applied there first and replicated to other DCs (best-effort).
- *   To retrieve the latest value (e.g. not from a slave), use BagOStuff:READ_LATEST.
- *   This store may be subject to LRU style evictions.
+ * - ObjectCache::getLocalServerInstance( $fallbackType )
+ *   Purpose: Memory cache for very hot keys.
+ *   Stored only on the individual web server (often EmptyBagOStuff in CLI mode).
+ *   Not replicated to the other servers.
  *
  * - ObjectCache::getLocalClusterInstance()
  *   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 )
+ * - ObjectCache::getMainStashInstance()
+ *   Purpose: Ephemeral global storage.
+ *   Stored centrally within the primary data-center.
+ *   Changes are applied there first and replicated to other DCs (best-effort).
+ *   To retrieve the latest value (e.g. not from a slave), use BagOStuff:READ_LATEST.
+ *   This store may be subject to LRU style evictions.
+ *
+ * - ObjectCache::getInstance( $cacheType )
+ *   Purpose: Special cases (like tiered memory/disk caches).
  *   Get a specific cache type by key in $wgObjectCaches.
  *
  * All the above cache instances (BagOStuff and WANObjectCache) have their makeKey()
@@ -231,15 +232,39 @@ class ObjectCache {
         * A fallback cache can be specified if none is found.
         *
         *     // Direct calls
-        *     ObjectCache::newAccelerator( $fallbackType );
+        *     ObjectCache::getLocalServerInstance( $fallbackType );
         *
         *     // From $wgObjectCaches via newFromParams()
-        *     ObjectCache::newAccelerator( array( 'fallback' => $fallbackType ) );
+        *     ObjectCache::getLocalServerInstance( array( 'fallback' => $fallbackType ) );
         *
+        * @param int|string|array $fallback Fallback cache or parameter map with 'fallback'
+        * @return BagOStuff
+        * @throws MWException
+        * @since 1.27
+        */
+       public static function getLocalServerInstance( $fallback = CACHE_NONE ) {
+               if ( function_exists( 'apc_fetch' ) ) {
+                       $id = 'apc';
+               } elseif ( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) {
+                       $id = 'xcache';
+               } elseif ( function_exists( 'wincache_ucache_get' ) ) {
+                       $id = 'wincache';
+               } else {
+                       if ( is_array( $fallback ) ) {
+                               $id = isset( $fallback['fallback'] ) ? $fallback['fallback'] : CACHE_NONE;
+                       } else {
+                               $id = $fallback;
+                       }
+               }
+
+               return self::getInstance( $id );
+       }
+
+       /**
         * @param array $params [optional] Array key 'fallback' for $fallback.
         * @param int|string $fallback Fallback cache, e.g. (CACHE_NONE, "hash") (since 1.24)
         * @return BagOStuff
-        * @throws MWException
+        * @deprecated 1.27
         */
        public static function newAccelerator( $params = array(), $fallback = null ) {
                if ( $fallback === null ) {
@@ -251,20 +276,8 @@ class ObjectCache {
                                $fallback = $params;
                        }
                }
-               if ( function_exists( 'apc_fetch' ) ) {
-                       $id = 'apc';
-               } elseif ( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) {
-                       $id = 'xcache';
-               } elseif ( function_exists( 'wincache_ucache_get' ) ) {
-                       $id = 'wincache';
-               } else {
-                       if ( $fallback === null ) {
-                               throw new MWException( 'CACHE_ACCEL requested but no suitable object ' .
-                                       'cache is present. You may want to install APC.' );
-                       }
-                       $id = $fallback;
-               }
-               return self::getInstance( $id );
+
+               return self::getLocalServerInstance( $fallback );
        }
 
        /**
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' ) );
        }
index 5ffca23..edb9ff1 100644 (file)
@@ -128,7 +128,7 @@ class DateFormatter {
                global $wgContLang, $wgMainCacheType;
 
                $lang = $lang ? wfGetLangObj( $lang ) : $wgContLang;
-               $cache = ObjectCache::newAccelerator( $wgMainCacheType );
+               $cache = ObjectCache::getLocalServerInstance( $wgMainCacheType );
 
                static $dateFormatter = false;
                if ( !$dateFormatter ) {
index 59b9249..732b4a0 100644 (file)
@@ -86,7 +86,7 @@ class ExtensionRegistry {
                // we don't want to fail here if $wgObjectCaches is not configured
                // properly for APC setup
                try {
-                       $this->cache = ObjectCache::newAccelerator();
+                       $this->cache = ObjectCache::getLocalServerInstance();
                } catch ( MWException $e ) {
                        $this->cache = new EmptyBagOStuff();
                }
index f7ba4d2..d9416e4 100644 (file)
@@ -197,7 +197,7 @@ class ResourceLoader implements LoggerAwareInterface {
                }
 
                $stats = RequestContext::getMain()->getStats();
-               $cache = ObjectCache::newAccelerator( CACHE_ANYTHING );
+               $cache = ObjectCache::getLocalServerInstance( CACHE_ANYTHING );
 
                $key = $cache->makeGlobalKey(
                        'resourceloader',
@@ -802,11 +802,6 @@ class ResourceLoader implements LoggerAwareInterface {
                        $exp = min( $maxage, $smaxage );
                        header( 'Expires: ' . wfTimestamp( TS_RFC2822, $exp + time() ) );
                }
-
-               // Send the current time expressed as fractional seconds since epoch,
-               // with microsecond precision. This helps distinguish hits from misses
-               // in edge caches.
-               header( 'MediaWiki-Timestamp: ' . microtime( true ) );
        }
 
        /**
index ef98400..1421b10 100644 (file)
@@ -935,7 +935,7 @@ class ResourceLoaderFileModule extends ResourceLoaderModule {
                static $cache;
 
                if ( !$cache ) {
-                       $cache = ObjectCache::newAccelerator( CACHE_ANYTHING );
+                       $cache = ObjectCache::getLocalServerInstance( CACHE_ANYTHING );
                }
 
                // Construct a cache key from the LESS file name and a hash digest
index c866919..12f6285 100644 (file)
@@ -31,7 +31,7 @@ class FileContentsHasher {
         * Constructor.
         */
        public function __construct() {
-               $this->cache = ObjectCache::newAccelerator( 'hash' );
+               $this->cache = ObjectCache::getLocalServerInstance( 'hash' );
        }
 
        /**
index 740df92..2dfc902 100644 (file)
@@ -176,7 +176,7 @@ class MWCryptHKDF {
                $context[] = gethostname();
 
                // Setup salt cache. Use APC, or fallback to the main cache if it isn't setup
-               $cache = ObjectCache::newAccelerator( $wgMainCacheType );
+               $cache = ObjectCache::getLocalServerInstance( $wgMainCacheType );
 
                if ( is_null( self::$singleton ) ) {
                        self::$singleton = new self( $secret, $wgHKDFAlgorithm, $cache, $context );
index 04c8e19..26eebcd 100644 (file)
@@ -282,11 +282,7 @@ class UIDGenerator {
                // Counter values would not survive accross script instances in CLI mode.
                $cache = null;
                if ( ( $flags & self::QUICK_VOLATILE ) && PHP_SAPI !== 'cli' ) {
-                       try {
-                               $cache = ObjectCache::newAccelerator();
-                       } catch ( Exception $e ) {
-                               // not supported
-                       }
+                       $cache = ObjectCache::getLocalServerInstance();
                }
                if ( $cache ) {
                        $counter = $cache->incr( $bucket, $count );