Aude has uploaded a new change for review.

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

Change subject: Make WikiPageEntityLookup more robust with attempt to load from 
DB_MASTER
......................................................................

Make WikiPageEntityLookup more robust with attempt to load from DB_MASTER

Try load entity revision from DB_MASTER on failed load from slave.

Fix issue and exception being reported in logs.

Bug: 62547
Change-Id: I440285888f9af5e3d401c974dc5678bd54018832
(cherry picked from commit 891be097c01d23449bd467df0956049355750d0f)
---
M lib/includes/store/sql/WikiPageEntityLookup.php
1 file changed, 51 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/15/130415/1

diff --git a/lib/includes/store/sql/WikiPageEntityLookup.php 
b/lib/includes/store/sql/WikiPageEntityLookup.php
index 24a3638..6a73b3e 100644
--- a/lib/includes/store/sql/WikiPageEntityLookup.php
+++ b/lib/includes/store/sql/WikiPageEntityLookup.php
@@ -69,10 +69,9 @@
                        $revision = 0;
                }
 
-               $row = $this->selectRevisionRow( $entityId, $revision, true );
+               $row = $this->loadRevisionRow( $entityId, $revision );
 
                if ( $row ) {
-
                        $entityRev = $this->loadEntity( 
$entityId->getEntityType(), $row );
 
                        if ( !$entityRev ) {
@@ -112,7 +111,7 @@
         * @throws StorageException
         */
        public function hasEntity( EntityID $entityId ) {
-               $row = $this->selectPageRow( $entityId );
+               $row = $this->loadPageRow( $entityId );
 
                return ( $row !== null );
        }
@@ -127,9 +126,30 @@
         * @return int|false
         */
        public function getLatestRevisionId( EntityID $entityId ) {
-               $row = $this->selectPageRow( $entityId );
+               $row = $this->loadPageRow( $entityId );
 
                return $row === null ? false : $row->page_latest;
+       }
+
+       /**
+        * @param EntityId $entityId
+        * @param int $revision
+        *
+        * @throws DBQueryError
+        * @return object|null
+        */
+       private function loadRevisionRow( EntityId $entityId, $revision ) {
+               $row = $this->selectRevisionRow( $entityId, $revision );
+
+               if ( !$row ) {
+                       // try loading from master
+                       wfDebugLog(  __CLASS__, __FUNCTION__ . ': try to load '
+                               . $entityId->getSerialization() . "with 
$revision from DB_MASTER." );
+
+                       $row = $this->selectRevisionRow( $entityId, $revision, 
DB_MASTER );
+               }
+
+               return $row;
        }
 
        /**
@@ -138,14 +158,15 @@
         * @since 0.4
         *
         * @param EntityID $entityId The entity to query the DB for.
-        * @param int      $revision The desired revision id, 0 means "current".
+        * @param int $revision The desired revision id, 0 means "current".
+        * @param boolean $connType DB_READ or DB_MASTER
         *
         * @throws \DBQueryError If the query fails.
         * @return object|null a raw database row object, or null if no such 
entity revision exists.
         */
-       protected function selectRevisionRow( EntityID $entityId, $revision = 0 
) {
+       protected function selectRevisionRow( EntityID $entityId, $revision = 
0, $connType = DB_READ ) {
                wfProfileIn( __METHOD__ );
-               $db = $this->getConnection( DB_READ );
+               $db = $this->getConnection( $connType );
 
                $opt = array();
 
@@ -218,18 +239,39 @@
        }
 
        /**
+        * @param EntityId $entityId
+        *
+        * @throws DBQueryError
+        * @return object|null
+        */
+       private function loadPageRow( EntityId $entityId ) {
+               $row = $this->selectPageRow( $entityId );
+
+               if ( !$row ) {
+                       // try to load from master
+                       wfDebugLog(  __CLASS__, __FUNCTION__ . ': try to load '
+                               . $entityId->getSerialization() . ' from 
DB_MASTER.' );
+
+                       $row = $this->selectPageRow( $entityId, DB_MASTER );
+               }
+
+               return $row;
+       }
+
+       /**
         * Selects page information from the page table.
         *
         * @since 0.4
         *
         * @param EntityID $entityId The entity to query the DB for.
+        * @param boolean $connType DB_READ or DB_MASTER
         *
         * @throws \DBQueryError If the query fails.
         * @return object|null a raw database row object, or null if no such 
entity revision exists.
         */
-       protected function selectPageRow( EntityID $entityId ) {
+       protected function selectPageRow( EntityID $entityId, $connType = 
DB_READ ) {
                wfProfileIn( __METHOD__ );
-               $db = $this->getConnection( DB_READ );
+               $db = $this->getConnection( $connType );
 
                $tables = array(
                        'page',

-- 
To view, visit https://gerrit.wikimedia.org/r/130415
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I440285888f9af5e3d401c974dc5678bd54018832
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: mw1.24-wmf2
Gerrit-Owner: Aude <aude.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to