Remove unnecessary exception from Title::getLatestRevID()
authorTim Starling <tstarling@wikimedia.org>
Thu, 6 Jun 2013 06:45:50 +0000 (16:45 +1000)
committerSiebrand Mazeland <s.mazeland@xs4all.nl>
Tue, 11 Jun 2013 06:58:32 +0000 (08:58 +0200)
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

index a543126..6f43e44 100644 (file)
@@ -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 );