Index: trunk/phase3/includes/MessageCache.php |
— | — | @@ -260,12 +260,23 @@ |
261 | 261 | |
262 | 262 | $this->lock($cacheKey); |
263 | 263 | |
264 | | - $cache = $this->loadFromDB( $code ); |
265 | | - $success = $this->setCache( $cache, $code ); |
| 264 | + # Limit the concurrency of loadFromDB to a single process |
| 265 | + # This prevents the site from going down when the cache expires |
| 266 | + $statusKey = wfMemcKey( 'messages', $code, 'status' ); |
| 267 | + $success = $this->mMemc->add( $statusKey, 'loading', MSG_LOAD_TIMEOUT ); |
266 | 268 | if ( $success ) { |
267 | | - $this->saveToCaches( $cache, true, $code ); |
| 269 | + $cache = $this->loadFromDB( $code ); |
| 270 | + $success = $this->setCache( $cache, $code ); |
268 | 271 | } |
269 | | - |
| 272 | + if ( $success ) { |
| 273 | + $success = $this->saveToCaches( $cache, true, $code ); |
| 274 | + if ( $success ) { |
| 275 | + $this->mMemc->delete( $statusKey ); |
| 276 | + } else { |
| 277 | + $this->mMemc->set( $statusKey, 'error', 60*5 ); |
| 278 | + wfDebug( "MemCached set error in MessageCache: restart memcached server!\n" ); |
| 279 | + } |
| 280 | + } |
270 | 281 | $this->unlock($cacheKey); |
271 | 282 | } |
272 | 283 | |
— | — | @@ -413,11 +424,7 @@ |
414 | 425 | global $wgLocalMessageCache, $wgLocalMessageCacheSerialized; |
415 | 426 | |
416 | 427 | $cacheKey = wfMemcKey( 'messages', $code ); |
417 | | - $statusKey = wfMemcKey( 'messages', $code, 'status' ); |
418 | 428 | |
419 | | - $success = $this->mMemc->add( $statusKey, 'loading', MSG_LOAD_TIMEOUT ); |
420 | | - if ( !$success ) return true; # Other process should be updating them now |
421 | | - |
422 | 429 | $i = 0; |
423 | 430 | if ( $memc ) { |
424 | 431 | # Save in memcached |
— | — | @@ -443,11 +450,8 @@ |
444 | 451 | } |
445 | 452 | |
446 | 453 | if ( $i == 20 ) { |
447 | | - $this->mMemc->set( $statusKey, 'error', 60*5 ); |
448 | | - wfDebug( "MemCached set error in MessageCache: restart memcached server!\n" ); |
449 | 454 | $success = false; |
450 | 455 | } else { |
451 | | - $this->mMemc->delete( $statusKey ); |
452 | 456 | $success = true; |
453 | 457 | } |
454 | 458 | wfProfileOut( __METHOD__ ); |