[MessageCache] Cleaned message cache load() error handling.
Change-Id: Ic8d62fa4162b54c776d934bd7106978fb36a6d32
This commit is contained in:
parent
b65bcc765d
commit
c9e8a7012f
1 changed files with 22 additions and 11 deletions
33
includes/cache/MessageCache.php
vendored
33
includes/cache/MessageCache.php
vendored
|
|
@ -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 );
|
||||
|
|
|
|||
Loading…
Reference in a new issue