Ed Hoo has uploaded a new change for review. https://gerrit.wikimedia.org/r/261106
Change subject: Use of DB_MASTER in order to consider replication lag ...................................................................... Use of DB_MASTER in order to consider replication lag Fix 1: Change calls from DB_SLAVE to DB_MASTER in order to ensure that slaves being out of date will not cause updates to be driven off stale information. Fix 2: Use of the naming convention 'dbw' to indicate connections to DB_MASTER. Bug: T122469 Change-Id: I79020572366fa114f5ae724125fc94e160e5db56 --- M Cargo.hooks.php M CargoUtils.php M parserfunctions/CargoAttach.php M parserfunctions/CargoStore.php M specials/CargoDeleteTable.php M specials/CargoPageValues.php M specials/CargoRecreateData.php 7 files changed, 53 insertions(+), 53 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo refs/changes/06/261106/1 diff --git a/Cargo.hooks.php b/Cargo.hooks.php index 3ea7ddd..9abbb8c 100644 --- a/Cargo.hooks.php +++ b/Cargo.hooks.php @@ -117,15 +117,15 @@ // efficiently delete from the former.) // Get all the "main" tables that this page is contained in. - $dbr = wfGetDB( DB_MASTER ); + $dbw = wfGetDB( DB_MASTER ); $cdb = CargoUtils::getDB(); - $res = $dbr->select( 'cargo_pages', 'table_name', array( 'page_id' => $pageID ) ); - while ( $row = $dbr->fetchRow( $res ) ) { + $res = $dbw->select( 'cargo_pages', 'table_name', array( 'page_id' => $pageID ) ); + while ( $row = $dbw->fetchRow( $res ) ) { $curMainTable = $row['table_name']; // First, delete from the "field" tables. - $res2 = $dbr->select( 'cargo_tables', 'field_tables', array( 'main_table' => $curMainTable ) ); - $row2 = $dbr->fetchRow( $res2 ); + $res2 = $dbw->select( 'cargo_tables', 'field_tables', array( 'main_table' => $curMainTable ) ); + $row2 = $dbw->fetchRow( $res2 ); $fieldTableNames = unserialize( $row2['field_tables'] ); foreach ( $fieldTableNames as $curFieldTable ) { // Thankfully, the MW DB API already provides a @@ -139,7 +139,7 @@ } // Finally, delete from cargo_pages. - $dbr->delete( 'cargo_pages', array( 'page_id' => $pageID ) ); + $dbw->delete( 'cargo_pages', array( 'page_id' => $pageID ) ); // This call is needed to get deletions to actually happen. $cdb->close(); @@ -222,13 +222,13 @@ $newPageName = $newtitle->getPrefixedText(); $newPageTitle = $newtitle->getText(); $newPageNamespace = $newtitle->getNamespace(); - $dbr = wfGetDB( DB_MASTER ); + $dbw = wfGetDB( DB_MASTER ); $cdb = CargoUtils::getDB(); // We use $oldid, because that's the page ID - $newid is the // ID of the redirect page. // @TODO - do anything with the redirect? - $res = $dbr->select( 'cargo_pages', 'table_name', array( 'page_id' => $oldid ) ); - while ( $row = $dbr->fetchRow( $res ) ) { + $res = $dbw->select( 'cargo_pages', 'table_name', array( 'page_id' => $oldid ) ); + while ( $row = $dbw->fetchRow( $res ) ) { $curMainTable = $row['table_name']; $cdb->update( $curMainTable, array( diff --git a/CargoUtils.php b/CargoUtils.php index 0ecd191..e1ad9fd 100644 --- a/CargoUtils.php +++ b/CargoUtils.php @@ -22,10 +22,10 @@ public static function getDB() { global $wgDBuser, $wgDBpassword, $wgDBprefix; global $wgCargoDBserver, $wgCargoDBname, $wgCargoDBuser, $wgCargoDBpassword, $wgCargoDBtype; - $dbr = wfGetDB( DB_SLAVE ); - $server = $dbr->getServer(); - $name = $dbr->getDBname(); - $type = $dbr->getType(); + $dbw = wfGetDB( DB_MASTER ); + $server = $dbw->getServer(); + $name = $dbw->getDBname(); + $type = $dbw->getType(); $dbType = is_null( $wgCargoDBtype ) ? $type : $wgCargoDBtype; $dbServer = is_null( $wgCargoDBserver ) ? $server : $wgCargoDBserver; @@ -52,8 +52,8 @@ * Gets a page property for the specified page ID and property name. */ public static function getPageProp( $pageID, $pageProp ) { - $dbr = wfGetDB( DB_SLAVE ); - $res = $dbr->select( 'page_props', array( + $dbw = wfGetDB( DB_MASTER ); + $res = $dbw->select( 'page_props', array( 'pp_value' ), array( 'pp_page' => $pageID, @@ -61,7 +61,7 @@ ) ); - if ( !$row = $dbr->fetchRow( $res ) ) { + if ( !$row = $dbw->fetchRow( $res ) ) { return null; } @@ -72,8 +72,8 @@ * Similar to getPageProp(). */ public static function getAllPageProps( $pageProp ) { - $dbr = wfGetDB( DB_SLAVE ); - $res = $dbr->select( 'page_props', array( + $dbw = wfGetDB( DB_MASTER ); + $res = $dbw->select( 'page_props', array( 'pp_page', 'pp_value' ), array( @@ -82,7 +82,7 @@ ); $pagesPerValue = array(); - while ( $row = $dbr->fetchRow( $res ) ) { + while ( $row = $dbw->fetchRow( $res ) ) { $pageID = $row['pp_page']; $pageValue = $row['pp_value']; if ( array_key_exists( $pageValue, $pagesPerValue ) ) { @@ -100,15 +100,15 @@ * hopefully there's exactly one of them. */ public static function getTemplateIDForDBTable( $tableName ) { - $dbr = wfGetDB( DB_SLAVE ); - $res = $dbr->select( 'page_props', array( + $dbw = wfGetDB( DB_MASTER ); + $res = $dbw->select( 'page_props', array( 'pp_page' ), array( 'pp_value' => $tableName, 'pp_propname' => 'CargoTableName' ) ); - if ( !$row = $dbr->fetchRow( $res ) ) { + if ( !$row = $dbw->fetchRow( $res ) ) { return null; } return $row['pp_page']; @@ -120,9 +120,9 @@ public static function getTables() { $tableNames = array(); - $dbr = wfGetDB( DB_SLAVE ); - $res = $dbr->select( 'cargo_tables', 'main_table' ); - while ( $row = $dbr->fetchRow( $res ) ) { + $dbw = wfGetDB( DB_MASTER ); + $res = $dbw->select( 'cargo_tables', 'main_table' ); + while ( $row = $dbw->fetchRow( $res ) ) { $tableNames[] = $row[0]; } return $tableNames; @@ -141,10 +141,10 @@ } } $tableSchemas = array(); - $dbr = wfGetDB( DB_SLAVE ); - $res = $dbr->select( 'cargo_tables', array( 'main_table', 'table_schema' ), + $dbw = wfGetDB( DB_MASTER ); + $res = $dbw->select( 'cargo_tables', array( 'main_table', 'table_schema' ), array( 'main_table' => $mainTableNames ) ); - while ( $row = $dbr->fetchRow( $res ) ) { + while ( $row = $dbw->fetchRow( $res ) ) { $tableName = $row['main_table']; $tableSchemaString = $row['table_schema']; $tableSchemas[$tableName] = CargoTableSchema::newFromDBString( $tableSchemaString ); @@ -397,11 +397,11 @@ } $tableSchema = CargoTableSchema::newFromDBString( $tableSchemaString ); - $dbr = wfGetDB( DB_MASTER ); + $dbw = wfGetDB( DB_MASTER ); $cdb = self::getDB(); - $res = $dbr->select( 'cargo_tables', 'main_table', array( 'template_id' => $templatePageID ) ); - while ( $row = $dbr->fetchRow( $res ) ) { + $res = $dbw->select( 'cargo_tables', 'main_table', array( 'template_id' => $templatePageID ) ); + while ( $row = $dbw->fetchRow( $res ) ) { $curTable = $row['main_table']; try { $cdb->dropTable( $curTable ); @@ -409,10 +409,10 @@ throw new MWException( "Caught exception ($e) while trying to drop Cargo table. " . "Please make sure that your database user account has the DROP permission." ); } - $dbr->delete( 'cargo_pages', array( 'table_name' => $curTable ) ); + $dbw->delete( 'cargo_pages', array( 'table_name' => $curTable ) ); } - $dbr->delete( 'cargo_tables', array( 'template_id' => $templatePageID ) ); + $dbw->delete( 'cargo_tables', array( 'template_id' => $templatePageID ) ); if ( $tableName == null ) { $tableName = self::getPageProp( $templatePageID, 'CargoTableName' ); @@ -521,7 +521,7 @@ $cdb->close(); // Finally, store all the info in the cargo_tables table. - $dbr->insert( 'cargo_tables', + $dbw->insert( 'cargo_tables', array( 'template_id' => $templatePageID, 'main_table' => $tableName, 'field_tables' => serialize( $fieldTableNames ), 'table_schema' => $tableSchemaString ) ); return true; diff --git a/parserfunctions/CargoAttach.php b/parserfunctions/CargoAttach.php index 5a5cae9..31eb9e5 100644 --- a/parserfunctions/CargoAttach.php +++ b/parserfunctions/CargoAttach.php @@ -41,9 +41,9 @@ return CargoUtils::formatError( "Error: Table name must be specified." ); } - $dbr = wfGetDB( DB_SLAVE ); - $res = $dbr->select( 'cargo_tables', 'COUNT(*)', array( 'main_table' => $tableName ) ); - $row = $dbr->fetchRow( $res ); + $dbw = wfGetDB( DB_MASTER ); + $res = $dbw->select( 'cargo_tables', 'COUNT(*)', array( 'main_table' => $tableName ) ); + $row = $dbw->fetchRow( $res ); if ( $row[0] == 0 ) { return CargoUtils::formatError( "Error: The specified table, \"$tableName\", does not exist." ); } diff --git a/parserfunctions/CargoStore.php b/parserfunctions/CargoStore.php index e6b9463..2c4c49e 100644 --- a/parserfunctions/CargoStore.php +++ b/parserfunctions/CargoStore.php @@ -93,9 +93,9 @@ } // Get the declaration of the table. - $dbr = wfGetDB( DB_SLAVE ); - $res = $dbr->select( 'cargo_tables', 'table_schema', array( 'main_table' => $tableName ) ); - $row = $dbr->fetchRow( $res ); + $dbw = wfGetDB( DB_MASTER ); + $res = $dbw->select( 'cargo_tables', 'table_schema', array( 'main_table' => $tableName ) ); + $row = $dbw->fetchRow( $res ); if ( $row == '' ) { // This table probably has not been created yet - // just exit silently. diff --git a/specials/CargoDeleteTable.php b/specials/CargoDeleteTable.php index 026c1bb..f3342c3 100644 --- a/specials/CargoDeleteTable.php +++ b/specials/CargoDeleteTable.php @@ -56,8 +56,8 @@ } // Make sure that this table exists. - $dbr = wfGetDB( DB_SLAVE ); - $res = $dbr->select( 'cargo_tables', array( 'main_table', 'field_tables' ), + $dbw = wfGetDB( DB_MASTER ); + $res = $dbw->select( 'cargo_tables', array( 'main_table', 'field_tables' ), array( 'main_table' => $subpage ) ); if ( $res->numRows() == 0 ) { $out->addHTML( CargoUtils::formatError( "Error: no table found named \"$subpage\"." ) ); diff --git a/specials/CargoPageValues.php b/specials/CargoPageValues.php index db948b4..473b298 100644 --- a/specials/CargoPageValues.php +++ b/specials/CargoPageValues.php @@ -36,10 +36,10 @@ $text = ''; - $dbr = wfGetDB( DB_MASTER ); - $res = $dbr->select( + $dbw = wfGetDB( DB_MASTER ); + $res = $dbw->select( 'cargo_pages', 'table_name', array( 'page_id' => $this->mTitle->getArticleID() ) ); - while ( $row = $dbr->fetchRow( $res ) ) { + while ( $row = $dbw->fetchRow( $res ) ) { $tableName = $row['table_name']; $queryResults = $this->getRowsForPageInTable( $tableName ); $text .= Html::element( 'h2', null, diff --git a/specials/CargoRecreateData.php b/specials/CargoRecreateData.php index d1b10c8..0a21067 100644 --- a/specials/CargoRecreateData.php +++ b/specials/CargoRecreateData.php @@ -46,16 +46,16 @@ $out->addModules( 'ext.cargo.recreatedata' ); $templateData = array(); - $dbr = wfGetDB( DB_SLAVE ); + $dbw = wfGetDB( DB_MASTER ); $templateData[] = array( 'name' => $this->mTemplateTitle->getText(), - 'numPages' => $this->getNumPagesThatCallTemplate( $dbr, $this->mTemplateTitle ) + 'numPages' => $this->getNumPagesThatCallTemplate( $dbw, $this->mTemplateTitle ) ); if ( $this->mIsDeclared ) { // Get all attached templates. - $res = $dbr->select( 'page_props', + $res = $dbw->select( 'page_props', array( 'pp_page' ), @@ -64,10 +64,10 @@ 'pp_propname' => 'CargoAttachedTable' ) ); - while ( $row = $dbr->fetchRow( $res ) ) { + while ( $row = $dbw->fetchRow( $res ) ) { $templateID = $row['pp_page']; $attachedTemplateTitle = Title::newFromID( $templateID ); - $numPages = $this->getNumPagesThatCallTemplate( $dbr, $attachedTemplateTitle ); + $numPages = $this->getNumPagesThatCallTemplate( $dbw, $attachedTemplateTitle ); $attachedTemplateName = $attachedTemplateTitle->getText(); $templateData[] = array( 'name' => $attachedTemplateName, @@ -104,8 +104,8 @@ return true; } - function getNumPagesThatCallTemplate( $dbr, $templateTitle ) { - $res = $dbr->select( + function getNumPagesThatCallTemplate($dbw, $templateTitle ) { + $res = $dbw->select( array( 'page', 'templatelinks' ), 'COUNT(*)', array( @@ -115,7 +115,7 @@ __METHOD__, array() ); - $row = $dbr->fetchRow( $res ); + $row = $dbw->fetchRow( $res ); return $row[0]; } -- To view, visit https://gerrit.wikimedia.org/r/261106 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I79020572366fa114f5ae724125fc94e160e5db56 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Cargo Gerrit-Branch: master Gerrit-Owner: Ed Hoo <edward....@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits