Tim Starling has submitted this change and it was merged. Change subject: Tweaked MessageCache locks to handle exceptions better. ......................................................................
Tweaked MessageCache locks to handle exceptions better. Change-Id: I3066d8dbebc97abcc0567d71625f995d62549b4c --- M includes/cache/MessageCache.php 1 file changed, 14 insertions(+), 6 deletions(-) Approvals: Tim Starling: Verified; Looks good to me, approved diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php index 6e9d413..7425978 100644 --- a/includes/cache/MessageCache.php +++ b/includes/cache/MessageCache.php @@ -327,31 +327,39 @@ $where[] = 'cache is empty'; $where[] = 'loading from database'; - $this->lock( $cacheKey ); + if ( $this->lock( $cacheKey ) ) { + $that = $this; + $osc = new ScopedCallback( function() use ( $that, $cacheKey ) { + $that->unlock( $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 ) { // acquired lock + $cache = $this->mMemc; + $isc = new ScopedCallback( function() use ( $cache, $statusKey ) { + $cache->delete( $statusKey ); + } ); $cache = $this->loadFromDB( $code ); $success = $this->setCache( $cache, $code ); if ( $success ) { // messages loaded $success = $this->saveToCaches( $cache, true, $code ); - if ( $success ) { - $this->mMemc->delete( $statusKey ); - } else { + $isc = null; // unlock + if ( !$success ) { $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->delete( $statusKey ); + $isc = null; // unlock $exception = new MWException( "Could not load cache from DB for '$code'." ); } } else { $exception = new MWException( "Could not acquire '$statusKey' lock." ); } - $this->unlock( $cacheKey ); + $osc = null; // unlock } if ( !$success ) { -- To view, visit https://gerrit.wikimedia.org/r/53474 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I3066d8dbebc97abcc0567d71625f995d62549b4c Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Nikerabbit <niklas.laxst...@gmail.com> Gerrit-Reviewer: Tim Starling <tstarl...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits