From d52a559fba83f3a1720de92e22797e7447af494a Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 18 Apr 2014 17:02:19 -0700 Subject: [PATCH] Make room for preloadFileStat() call in FileBackend::doOperationsInternal Change-Id: I60f71155abcf7f69423639b10ec301ac192df728 --- includes/filebackend/FileBackendStore.php | 7 +++++++ includes/libs/ProcessCacheLRU.php | 24 +++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/includes/filebackend/FileBackendStore.php b/includes/filebackend/FileBackendStore.php index 2fd1bf66a7..e0b5224901 100644 --- a/includes/filebackend/FileBackendStore.php +++ b/includes/filebackend/FileBackendStore.php @@ -1102,6 +1102,10 @@ abstract class FileBackendStore extends FileBackend { $paths = array_merge( $paths, $op->storagePathsRead() ); $paths = array_merge( $paths, $op->storagePathsChanged() ); } + + // Enlarge the cache to fit the stat entries of these files + $this->cheapCache->resize( max( 2 * count( $paths ), self::CACHE_CHEAP_SIZE ) ); + // Load from the persistent container caches $this->primeContainerCache( $paths ); // Get the latest stat info for all the files (having locked them) @@ -1115,6 +1119,9 @@ abstract class FileBackendStore extends FileBackend { $status->merge( $subStatus ); $status->success = $subStatus->success; // not done in merge() + // Shrink the stat cache back to normal size + $this->cheapCache->resize( self::CACHE_CHEAP_SIZE ); + return $status; } diff --git a/includes/libs/ProcessCacheLRU.php b/includes/libs/ProcessCacheLRU.php index f2d9f42aba..f988207a89 100644 --- a/includes/libs/ProcessCacheLRU.php +++ b/includes/libs/ProcessCacheLRU.php @@ -38,10 +38,7 @@ class ProcessCacheLRU { * @throws UnexpectedValueException When $maxCacheKeys is not an int or =< 0. */ public function __construct( $maxKeys ) { - if ( !is_int( $maxKeys ) || $maxKeys < 1 ) { - throw new UnexpectedValueException( __METHOD__ . " must be given an integer >= 1" ); - } - $this->maxCacheKeys = $maxKeys; + $this->resize( $maxKeys ); } /** @@ -119,6 +116,25 @@ class ProcessCacheLRU { } } + /** + * Resize the maximum number of cache entries, removing older entries as needed + * + * @param $maxKeys integer + * @return void + */ + public function resize( $maxKeys ) { + if ( !is_int( $maxKeys ) || $maxKeys < 1 ) { + throw new UnexpectedValueException( __METHOD__ . " must be given an integer >= 1" ); + } + $this->maxCacheKeys = $maxKeys; + while ( count( $this->cache ) > $this->maxCacheKeys ) { + reset( $this->cache ); + $evictKey = key( $this->cache ); + unset( $this->cache[$evictKey] ); + unset( $this->cacheTimes[$evictKey] ); + } + } + /** * Push an entry to the top of the cache * -- 2.20.1