jenkins-bot has submitted this change and it was merged.
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
---
M lib/includes/store/sql/WikiPageEntityLookup.php
1 file changed, 51 insertions(+), 9 deletions(-)
Approvals:
Daniel Kinzler: Looks good to me, approved
jenkins-bot: Verified
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/130350
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I440285888f9af5e3d401c974dc5678bd54018832
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: WikidataJenkins <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits