Aaron Schulz has uploaded a new change for review. https://gerrit.wikimedia.org/r/206958
Change subject: Converted FileBackendStore caching to WANObjectCache ...................................................................... Converted FileBackendStore caching to WANObjectCache Change-Id: I76efb0dc45a697c5fdfc50932e1198a6d663a445 --- M includes/filebackend/FileBackendGroup.php M includes/filebackend/FileBackendStore.php M includes/filebackend/SwiftFileBackend.php M includes/libs/objectcache/WANObjectCache.php 4 files changed, 26 insertions(+), 21 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/58/206958/1 diff --git a/includes/filebackend/FileBackendGroup.php b/includes/filebackend/FileBackendGroup.php index 1b88db7..e8d8f9e 100644 --- a/includes/filebackend/FileBackendGroup.php +++ b/includes/filebackend/FileBackendGroup.php @@ -145,6 +145,8 @@ * @throws FileBackendException */ public function get( $name ) { + global $wgMainWANCache; + if ( !isset( $this->backends[$name] ) ) { throw new FileBackendException( "No backend defined with the name `$name`." ); } @@ -160,6 +162,8 @@ $config['fileJournal'] = isset( $config['fileJournal'] ) ? FileJournal::factory( $config['fileJournal'], $name ) : FileJournal::factory( array( 'class' => 'NullFileJournal' ), $name ); + $config['wanCache'] = ObjectCache::getWANInstance( $wgMainWANCache ); + $this->backends[$name]['instance'] = new $class( $config ); } diff --git a/includes/filebackend/FileBackendStore.php b/includes/filebackend/FileBackendStore.php index 25e87d4..9f147f0 100644 --- a/includes/filebackend/FileBackendStore.php +++ b/includes/filebackend/FileBackendStore.php @@ -36,7 +36,7 @@ * @since 1.19 */ abstract class FileBackendStore extends FileBackend { - /** @var BagOStuff */ + /** @var WANObjectCache */ protected $memCache; /** @var ProcessCacheLRU Map of paths to small (RAM/disk) cache items */ protected $cheapCache; @@ -58,6 +58,7 @@ /** * @see FileBackend::__construct() * Additional $config params include: + * - wanCache : WANOBjectCache object to use for persistent caching. * - mimeCallback : Callback that takes (storage path, content, file system path) and * returns the MIME type of the file or 'unknown/unknown'. The file * system path parameter should be used if the content one is null. @@ -72,7 +73,7 @@ // @todo handle the case of extension-less files using the contents return StreamFile::contentTypeFromPath( $storagePath ) ?: 'unknown/unknown'; }; - $this->memCache = new EmptyBagOStuff(); // disabled by default + $this->memCache = WANObjectCache::newEmpty(); // disabled by default $this->cheapCache = new ProcessCacheLRU( self::CACHE_CHEAP_SIZE ); $this->expensiveCache = new ProcessCacheLRU( self::CACHE_EXPENSIVE_SIZE ); } @@ -1592,7 +1593,7 @@ * @param array $val Information to cache */ final protected function setContainerCache( $container, array $val ) { - $this->memCache->add( $this->containerCacheKey( $container ), $val, 14 * 86400 ); + $this->memCache->set( $this->containerCacheKey( $container ), $val, 14 * 86400 ); } /** @@ -1602,7 +1603,7 @@ * @param string $container Resolved container name */ final protected function deleteContainerCache( $container ) { - if ( !$this->memCache->set( $this->containerCacheKey( $container ), 'PURGED', 300 ) ) { + if ( !$this->memCache->delete( $this->containerCacheKey( $container ), 300 ) ) { trigger_error( "Unable to delete stat cache for container $container." ); } } @@ -1682,21 +1683,8 @@ $age = time() - wfTimestamp( TS_UNIX, $val['mtime'] ); $ttl = min( 7 * 86400, max( 300, floor( .1 * $age ) ) ); $key = $this->fileCacheKey( $path ); - // Set the cache unless it is currently salted with the value "PURGED". - // Using add() handles this except it also is a no-op in that case where - // the current value is not "latest" but $val is, so use CAS in that case. - if ( !$this->memCache->add( $key, $val, $ttl ) && !empty( $val['latest'] ) ) { - $this->memCache->merge( - $key, - function ( BagOStuff $cache, $key, $cValue ) use ( $val ) { - return ( is_array( $cValue ) && empty( $cValue['latest'] ) ) - ? $val // update the stat cache with the lastest info - : false; // do nothing (cache is salted or some error happened) - }, - $ttl, - 1 - ); - } + // Set the cache unless it is currently salted. + $this->memCache->set( $key, $val, $ttl ); } /** @@ -1712,7 +1700,7 @@ if ( $path === null ) { return; // invalid storage path } - if ( !$this->memCache->set( $this->fileCacheKey( $path ), 'PURGED', 300 ) ) { + if ( !$this->memCache->delete( $this->fileCacheKey( $path ), 300 ) ) { trigger_error( "Unable to delete stat cache for file $path." ); } } diff --git a/includes/filebackend/SwiftFileBackend.php b/includes/filebackend/SwiftFileBackend.php index 5f406c9..42f4014 100644 --- a/includes/filebackend/SwiftFileBackend.php +++ b/includes/filebackend/SwiftFileBackend.php @@ -128,7 +128,9 @@ // HTTP helper client $this->http = new MultiHttpClient( array() ); // Cache container information to mask latency - $this->memCache = wfGetMainCache(); + if ( isset( $config['wanCache'] ) && $config['wanCache'] instanceof WANObjectCache ) { + $this->memCache = $config['wanCache']; + } // Process cache for container info $this->containerStatCache = new ProcessCacheLRU( 300 ); // Cache auth token information to avoid RTTs diff --git a/includes/libs/objectcache/WANObjectCache.php b/includes/libs/objectcache/WANObjectCache.php index 6e5cad6..d22e56a 100755 --- a/includes/libs/objectcache/WANObjectCache.php +++ b/includes/libs/objectcache/WANObjectCache.php @@ -109,6 +109,17 @@ } /** + * @return WANObjectCache Cache that wraps EmptyBagOStuff + */ + public static function newEmpty() { + return new self( array( + 'cache' => new EmptyBagOStuff(), + 'pool' => 'empty', + 'relayer' => new EventRelayerNull( array() ) + ) ); + } + + /** * Fetch the value of a key from cache * * If passed in, $curTTL is set to the remaining TTL (current time left): -- To view, visit https://gerrit.wikimedia.org/r/206958 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I76efb0dc45a697c5fdfc50932e1198a6d663a445 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits