From c9e8a7012fbb4f0e124d001b766e15425d2a9ea9 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 19 Dec 2012 12:49:54 -0800 Subject: [PATCH] [MessageCache] Cleaned message cache load() error handling. Change-Id: Ic8d62fa4162b54c776d934bd7106978fb36a6d32 --- includes/cache/MessageCache.php | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php index d567035e40..e2cf1b42e9 100644 --- a/includes/cache/MessageCache.php +++ b/includes/cache/MessageCache.php @@ -264,6 +264,8 @@ class MessageCache { function load( $code = false ) { global $wgUseLocalMessageCache; + $exception = null; // deferred error + if( !is_string( $code ) ) { # This isn't really nice, so at least make a note about it and try to # fall back @@ -326,25 +328,30 @@ class MessageCache { $where[] = 'loading from database'; $this->lock( $cacheKey ); - # 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 ) { + if ( $success ) { // acquired lock $cache = $this->loadFromDB( $code ); $success = $this->setCache( $cache, $code ); - } - if ( $success ) { - $success = $this->saveToCaches( $cache, true, $code ); - if ( $success ) { - $this->mMemc->delete( $statusKey ); + if ( $success ) { // messages loaded + $success = $this->saveToCaches( $cache, true, $code ); + if ( $success ) { + $this->mMemc->delete( $statusKey ); + } else { + $this->mMemc->set( $statusKey, 'error', 60 * 5 ); + wfDebug( __METHOD__ . ": set() error: restart memcached server!\n" ); + $exception = new MWException( "Could not save cache for '$code'." ); + } } else { - $this->mMemc->set( $statusKey, 'error', 60 * 5 ); - wfDebug( "MemCached set error in MessageCache: restart memcached server!\n" ); + $this->mMemc->delete( $statusKey ); + $exception = new MWException( "Could not load cache from DB for '$code'." ); } + } else { + $exception = new MWException( "Could not acquire '$statusKey' lock." ); } - $this->unlock($cacheKey); + $this->unlock( $cacheKey ); } if ( !$success ) { @@ -353,7 +360,11 @@ class MessageCache { // This used to go on, but that led to lots of nasty side // effects like gadgets and sidebar getting cached with their // default content - throw new MWException( "MessageCache failed to load messages" ); + if ( $exception instanceof Exception ) { + throw $exception; + } else { + throw new MWException( "MessageCache failed to load messages" ); + } } else { # All good, just record the success $info = implode( ', ', $where ); -- 2.20.1