From 5f2680289f08429f3421025f1c73e77af403f69b Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Fri, 10 Oct 2008 13:02:57 +0000 Subject: [PATCH] Fixed regression from r35821: the status key is meant to prevent DB overload, not memcached overload. --- includes/MessageCache.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/includes/MessageCache.php b/includes/MessageCache.php index 4fd7dda455..2721708478 100644 --- a/includes/MessageCache.php +++ b/includes/MessageCache.php @@ -260,12 +260,23 @@ class MessageCache { $this->lock($cacheKey); - $cache = $this->loadFromDB( $code ); - $success = $this->setCache( $cache, $code ); + # Limit the concurrency of loadFromDB to a single process + # This prevents the site from going down when the cache expires + $statusKey = wfMemcKey( 'messages', $code, 'status' ); + $success = $this->mMemc->add( $statusKey, 'loading', MSG_LOAD_TIMEOUT ); if ( $success ) { - $this->saveToCaches( $cache, true, $code ); + $cache = $this->loadFromDB( $code ); + $success = $this->setCache( $cache, $code ); + } + if ( $success ) { + $success = $this->saveToCaches( $cache, true, $code ); + if ( $success ) { + $this->mMemc->delete( $statusKey ); + } else { + $this->mMemc->set( $statusKey, 'error', 60*5 ); + wfDebug( "MemCached set error in MessageCache: restart memcached server!\n" ); + } } - $this->unlock($cacheKey); } @@ -413,10 +424,6 @@ class MessageCache { global $wgLocalMessageCache, $wgLocalMessageCacheSerialized; $cacheKey = wfMemcKey( 'messages', $code ); - $statusKey = wfMemcKey( 'messages', $code, 'status' ); - - $success = $this->mMemc->add( $statusKey, 'loading', MSG_LOAD_TIMEOUT ); - if ( !$success ) return true; # Other process should be updating them now $i = 0; if ( $memc ) { @@ -443,11 +450,8 @@ class MessageCache { } if ( $i == 20 ) { - $this->mMemc->set( $statusKey, 'error', 60*5 ); - wfDebug( "MemCached set error in MessageCache: restart memcached server!\n" ); $success = false; } else { - $this->mMemc->delete( $statusKey ); $success = true; } wfProfileOut( __METHOD__ ); -- 2.20.1