Debug logging and possible fix for bug 31177: mystery sidebar message failures
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 27 Sep 2011 00:41:24 +0000 (00:41 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 27 Sep 2011 00:41:24 +0000 (00:41 +0000)
This may be related to things failing on load from External Storage; however we have not yet been able to verify this.

Tweaks MessageCache::loadFromDB() and MessageCache::getMsgFromNamespace() to avoid storing empty cache entries when loading text fails.
When building initial cache if we get a failure we'll log and store a '!TOO BIG' message which requests on-demand load later.
If an on-demand load failures, we'll log and return the false through but won't update the cache with the bad value.

To enable the logging in production, set up a $wgDebugLogFiles entry for 'MessageCache'.

Note that MessageCache::loadFromDB() bypasses Revision's text entry memcaching and may cause a lot of ES fetches at once.
However any ES failures *should* already be logged in the 'ExternalStoreDB' log file.

includes/cache/MessageCache.php

index 3f787e9..59ee8c2 100644 (file)
@@ -428,7 +428,16 @@ class MessageCache {
                );
 
                foreach ( $res as $row ) {
-                       $cache[$row->page_title] = ' ' . Revision::getRevisionText( $row );
+                       $text = Revision::getRevisionText( $row );
+                       if( $text === false ) {
+                               // Failed to fetch data; possible ES errors?
+                               // Store a marker to fetch on-demand as a workaround...
+                               $entry = '!TOO BIG';
+                               wfDebugLog( 'MessageCache', __METHOD__ . ": failed to load message page text for {$row->page_title} ($code)" );
+                       } else {
+                               $entry = ' ' . $text;
+                       }
+                       $cache[$row->page_title] = $entry;
                }
 
                foreach ( $mostused as $key ) {
@@ -741,8 +750,13 @@ class MessageCache {
                $revision = Revision::newFromTitle( Title::makeTitle( NS_MEDIAWIKI, $title ) );
                if ( $revision ) {
                        $message = $revision->getText();
-                       $this->mCache[$code][$title] = ' ' . $message;
-                       $this->mMemc->set( $titleKey, ' ' . $message, $this->mExpiry );
+                       if ($message === false) {
+                               // A possibly temporary loading failure.
+                               wfDebugLog( 'MessageCache', __METHOD__ . ": failed to load message page text for {$title->getDbKey()} ($code)" );
+                       } else {
+                               $this->mCache[$code][$title] = ' ' . $message;
+                               $this->mMemc->set( $titleKey, ' ' . $message, $this->mExpiry );
+                       }
                } else {
                        $message = false;
                        $this->mCache[$code][$title] = '!NONEXISTENT';