[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Fix $wgFileCache DB outage fallback

2016-09-15 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Fix $wgFileCache DB outage fallback
..


Fix $wgFileCache DB outage fallback

Change-Id: I5c41b4669ca29d119de5c08a2c61dbadae7cf55c
---
M includes/MediaWiki.php
M includes/cache/HTMLFileCache.php
M includes/exception/MWExceptionRenderer.php
3 files changed, 56 insertions(+), 21 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php
index 2aa4b80..2fce08c 100644
--- a/includes/MediaWiki.php
+++ b/includes/MediaWiki.php
@@ -528,6 +528,24 @@
$e->report(); // display the GUI error
}
} catch ( Exception $e ) {
+   $context = $this->context;
+   if (
+   $e instanceof DBConnectionError &&
+   $context->hasTitle() &&
+   $context->getTitle()->canExist() &&
+   $context->getRequest()->getVal( 'action', 
'view' ) === 'view' &&
+   HTMLFileCache::useFileCache( $this->context, 
HTMLFileCache::MODE_OUTAGE )
+   ) {
+   // Try to use any (even stale) file during 
outages...
+   $cache = new HTMLFileCache( 
$context->getTitle(), 'view' );
+   if ( $cache->isCached() ) {
+   $cache->loadFromFileCache( $context, 
HTMLFileCache::MODE_OUTAGE );
+   print MWExceptionRenderer::getHTML( $e 
);
+   exit;
+   }
+
+   }
+
MWExceptionHandler::handleException( $e );
}
 
@@ -819,24 +837,22 @@
}
}
 
-   if ( $this->config->get( 'UseFileCache' ) && 
$title->getNamespace() >= 0 ) {
-   if ( HTMLFileCache::useFileCache( $this->context ) ) {
-   // Try low-level file cache hit
-   $cache = new HTMLFileCache( $title, $action );
-   if ( $cache->isCacheGood( /* Assume up to date 
*/ ) ) {
-   // Check incoming headers to see if 
client has this cached
-   $timestamp = $cache->cacheTimestamp();
-   if ( !$output->checkLastModified( 
$timestamp ) ) {
-   $cache->loadFromFileCache( 
$this->context );
-   }
-   // Do any stats increment/watchlist 
stuff
-   // Assume we're viewing the latest 
revision (this should always be the case with file cache)
-   
$this->context->getWikiPage()->doViewUpdates( $this->context->getUser() );
-   // Tell OutputPage that output is taken 
care of
-   $output->disable();
-
-   return;
+   if ( $title->canExist() && HTMLFileCache::useFileCache( 
$this->context ) ) {
+   // Try low-level file cache hit
+   $cache = new HTMLFileCache( $title, $action );
+   if ( $cache->isCacheGood( /* Assume up to date */ ) ) {
+   // Check incoming headers to see if client has 
this cached
+   $timestamp = $cache->cacheTimestamp();
+   if ( !$output->checkLastModified( $timestamp ) 
) {
+   $cache->loadFromFileCache( 
$this->context );
}
+   // Do any stats increment/watchlist stuff, 
assuming user is viewing the
+   // latest revision (which should always be the 
case for file cache)
+   $this->context->getWikiPage()->doViewUpdates( 
$this->context->getUser() );
+   // Tell OutputPage that output is taken care of
+   $output->disable();
+
+   return;
}
}
 
diff --git a/includes/cache/HTMLFileCache.php b/includes/cache/HTMLFileCache.php
index 1bab0f5..52ae279 100644
--- a/includes/cache/HTMLFileCache.php
+++ b/includes/cache/HTMLFileCache.php
@@ -29,6 +29,9 @@
  * @ingroup Cache
  */
 class HTMLFileCache extends FileCacheBase {
+   const MODE_NORMAL = 0; // normal cache mode
+   const MODE_OUTAGE = 1; // fallback cache for DB outages
+
/**
 * Construct an 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Fix $wgFileCache DB outage fallback

2016-09-14 Thread Aaron Schulz (Code Review)
Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/310696

Change subject: Fix $wgFileCache DB outage fallback
..

Fix $wgFileCache DB outage fallback

Change-Id: I5c41b4669ca29d119de5c08a2c61dbadae7cf55c
---
M includes/MediaWiki.php
M includes/cache/HTMLFileCache.php
M includes/exception/MWExceptionRenderer.php
3 files changed, 51 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/96/310696/1

diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php
index 9bbbd35..af096cc 100644
--- a/includes/MediaWiki.php
+++ b/includes/MediaWiki.php
@@ -527,6 +527,25 @@
$e->report(); // display the GUI error
}
} catch ( Exception $e ) {
+   $context = $this->context;
+   if (
+   $e instanceof DBConnectionError &&
+   $context->hasTitle() &&
+   $context->getTitle()->canExist() &&
+   $context->getRequest()->getVal( 'action', 
'view' ) === 'view' &&
+   HTMLFileCache::useFileCache( $this->context, 
HTMLFileCache::MODE_OUTAGE )
+   ) {
+   // Try to use any (even stale) file during 
outages...
+   $cache = new HTMLFileCache( 
$context->getTitle(), 'view' );
+   if ( $cache->isCached() ) {
+   $cache->loadFromFileCache( $context );
+   $msgHtml = 
MWExceptionRenderer::getHTML( $e );
+   print "\n$msgHtml\n\n";
+   exit;
+   }
+
+   }
+
MWExceptionHandler::handleException( $e );
}
 
@@ -809,24 +828,22 @@
}
}
 
-   if ( $this->config->get( 'UseFileCache' ) && 
$title->getNamespace() >= 0 ) {
-   if ( HTMLFileCache::useFileCache( $this->context ) ) {
-   // Try low-level file cache hit
-   $cache = new HTMLFileCache( $title, $action );
-   if ( $cache->isCacheGood( /* Assume up to date 
*/ ) ) {
-   // Check incoming headers to see if 
client has this cached
-   $timestamp = $cache->cacheTimestamp();
-   if ( !$output->checkLastModified( 
$timestamp ) ) {
-   $cache->loadFromFileCache( 
$this->context );
-   }
-   // Do any stats increment/watchlist 
stuff
-   // Assume we're viewing the latest 
revision (this should always be the case with file cache)
-   
$this->context->getWikiPage()->doViewUpdates( $this->context->getUser() );
-   // Tell OutputPage that output is taken 
care of
-   $output->disable();
-
-   return;
+   if ( $title->canExist() && HTMLFileCache::useFileCache( 
$this->context ) ) {
+   // Try low-level file cache hit
+   $cache = new HTMLFileCache( $title, $action );
+   if ( $cache->isCacheGood( /* Assume up to date */ ) ) {
+   // Check incoming headers to see if client has 
this cached
+   $timestamp = $cache->cacheTimestamp();
+   if ( !$output->checkLastModified( $timestamp ) 
) {
+   $cache->loadFromFileCache( 
$this->context );
}
+   // Do any stats increment/watchlist stuff, 
assuming user is viewing the
+   // latest revision (which should always be the 
case for file cache)
+   $this->context->getWikiPage()->doViewUpdates( 
$this->context->getUser() );
+   // Tell OutputPage that output is taken care of
+   $output->disable();
+
+   return;
}
}
 
diff --git a/includes/cache/HTMLFileCache.php b/includes/cache/HTMLFileCache.php
index 1bab0f5..285e152 100644
--- a/includes/cache/HTMLFileCache.php
+++ b/includes/cache/HTMLFileCache.php
@@ -29,6 +29,9 @@
  * @ingroup Cache
  */
 class HTMLFileCache extends FileCacheBase {
+   const MODE_NORMAL = 0; // normal cache mode
+   const