From 22e2e96088d81022cb40e9991683a335029e7565 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Thu, 6 Jun 2013 16:45:50 +1000 Subject: [PATCH] Remove unnecessary exception from Title::getLatestRevID() Bug 37209: An exception was thrown where the data cached in the Title object was inconsistent with the data in LinkCache. It shouldn't be surprising that this happens, since there is no guarantee that the data was derived from the same transaction or even the same DB server. But I don't think it is a problem worth troubling the user over, since with $flags=0, the slave DB server will be used, and no special guarantee of consistency should be expected by callers. If callers do need consistency, then they should make their own arrangements to get it, such as clearing the LinkCache. Since we have to pick a winner, and the choice is mostly arbitrary since it's not possible to tell which is fresher, I think LinkCache is a better choice since the lifetime of its cache entries can be controlled. Change-Id: I0add48463341e56fe8c155b1007487278ad2705d --- includes/Title.php | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index a54312616e..6f43e441db 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2945,11 +2945,13 @@ class Title { $linkCache = LinkCache::singleton(); $cached = $linkCache->getGoodLinkFieldObj( $this, 'redirect' ); if ( $cached === null ) { - // TODO: check the assumption that the cache actually knows about this title - // and handle this, such as get the title from the database. - // See https://bugzilla.wikimedia.org/show_bug.cgi?id=37209 - wfDebug( "LinkCache doesn't currently know about this title: " . $this->getPrefixedDBkey() ); - wfDebug( wfBacktrace() ); + # Trust LinkCache's state over our own + # LinkCache is telling us that the page doesn't exist, despite there being cached + # data relating to an existing page in $this->mArticleID. Updaters should clear + # LinkCache as appropriate, or use $flags = Title::GAID_FOR_UPDATE. If that flag is + # set, then LinkCache will definitely be up to date here, since getArticleID() forces + # LinkCache to refresh its data from the master. + return $this->mRedirect = false; } $this->mRedirect = (bool)$cached; @@ -2974,11 +2976,9 @@ class Title { } $linkCache = LinkCache::singleton(); $cached = $linkCache->getGoodLinkFieldObj( $this, 'length' ); - if ( $cached === null ) { # check the assumption that the cache actually knows about this title - # XXX: this does apparently happen, see https://bugzilla.wikimedia.org/show_bug.cgi?id=37209 - # as a stop gap, perhaps log this, but don't throw an exception? - wfDebug( "LinkCache doesn't currently know about this title: " . $this->getPrefixedDBkey() ); - wfDebug( wfBacktrace() ); + if ( $cached === null ) { + # Trust LinkCache's state over our own, as for isRedirect() + return $this->mLength = 0; } $this->mLength = intval( $cached ); @@ -2990,7 +2990,6 @@ class Title { * What is the page_latest field for this page? * * @param int $flags a bit field; may be Title::GAID_FOR_UPDATE to select for update - * @throws MWException * @return Int or 0 if the page doesn't exist */ public function getLatestRevID( $flags = 0 ) { @@ -3004,10 +3003,9 @@ class Title { $linkCache = LinkCache::singleton(); $linkCache->addLinkObj( $this ); $cached = $linkCache->getGoodLinkFieldObj( $this, 'revision' ); - if ( $cached === null ) { # check the assumption that the cache actually knows about this title - # XXX: this does apparently happen, see https://bugzilla.wikimedia.org/show_bug.cgi?id=37209 - # as a stop gap, perhaps log this, but don't throw an exception? - throw new MWException( "LinkCache doesn't currently know about this title: " . $this->getPrefixedDBkey() ); + if ( $cached === null ) { + # Trust LinkCache's state over our own, as for isRedirect() + return $this->mLatestID = 0; } $this->mLatestID = intval( $cached ); -- 2.20.1