r94370 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94369‎ | r94370 | r94371 >
Date:19:11, 12 August 2011
Author:aaron
Status:reverted (Comments)
Tags:
Comment:
* Added LoggedUpdateMaintenance subclass
* Moved PopulateRevisionLength/PopulateRevisionSha1 scripts to $postDatabaseUpdateMaintenance
* Fixed bogus "{$prefix}_sha1 != ''" comparison (r94362)
* Removed unneeded NOT NULL check (speeds up script a bit) from populateRevisionSha1 script
* Various code cleanups
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/installer/DatabaseUpdater.php (modified) (history)
  • /trunk/phase3/includes/installer/MysqlUpdater.php (modified) (history)
  • /trunk/phase3/maintenance/Maintenance.php (modified) (history)
  • /trunk/phase3/maintenance/populateRevisionLength.php (modified) (history)
  • /trunk/phase3/maintenance/populateRevisionSha1.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/populateRevisionSha1.php
@@ -1,6 +1,7 @@
22 <?php
33 /**
4 - * Fills the rev_sha1 and ar_sha1 columns of revision & archive tables.
 4+ * Fills the rev_sha1 and ar_sha1 columns of revision
 5+ * and archive tables for revisions created before MW 1.19.
56 *
67 * This program is free software; you can redistribute it and/or modify
78 * it under the terms of the GNU General Public License as published by
@@ -22,45 +23,56 @@
2324
2425 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
2526
26 -class PopulateRevisionSha1 extends Maintenance {
 27+class PopulateRevisionSha1 extends LoggedUpdateMaintenance {
2728 public function __construct() {
2829 parent::__construct();
2930 $this->mDescription = "Populates the rev_sha1 and ar_sha1 fields";
3031 $this->setBatchSize( 200 );
3132 }
3233
33 - public function execute() {
 34+ protected function getUpdateKey() {
 35+ return 'populate rev_sha1';
 36+ }
 37+
 38+ protected function updateSkippedMessage() {
 39+ return 'rev_sha1 column of revision table already populated.';
 40+ }
 41+
 42+ protected function updatelogFailedMessage() {
 43+ return 'Could not insert rev_sha1 population row.';
 44+ }
 45+
 46+ protected function doDBUpdates() {
3447 $db = $this->getDB( DB_MASTER );
 48+ if ( !$db->tableExists( 'revision' ) ) {
 49+ $this->error( "revision table does not exist", true );
 50+ }
 51+ if ( !$db->tableExists( 'archive' ) ) {
 52+ $this->error( "archive table does not exist", true );
 53+ }
3554
3655 $this->output( "Populating rev_sha1 column\n" );
37 - $this->doSha1Updates( $db, 'revision', 'rev_id', 'rev' );
 56+ $rc = $this->doSha1Updates( $db, 'revision', 'rev_id', 'rev' );
3857
3958 $this->output( "Populating ar_sha1 column\n" );
40 - $this->doSha1Updates( $db, 'archive', 'ar_rev_id', 'ar' );
 59+ $ac = $this->doSha1Updates( $db, 'archive', 'ar_rev_id', 'ar' );
4160
42 - if ( $db->insert(
43 - 'updatelog',
44 - array( 'ul_key' => 'populate rev_sha1' ),
45 - __METHOD__,
46 - 'IGNORE'
47 - )
48 - ) {
49 - $this->output( "rev_sha1 and ar_sha1 population complete.\n" );
50 - return true;
51 - } else {
52 - $this->output( "Could not insert rev_sha1 population row.\n" );
53 - return false;
54 - }
 61+ $this->output( "rev_sha1 and ar_sha1 population complete [$rc revision rows, $ac archive rows].\n" );
 62+ return true;
5563 }
5664
 65+ /**
 66+ * @return Integer Rows changed
 67+ */
5768 protected function doSha1Updates( $db, $table, $idCol, $prefix ) {
58 - $start = $db->selectField( $table, "MIN($idCol)", "$idCol IS NOT NULL", __METHOD__ );
59 - if ( !$start ) {
60 - $this->output( "Nothing to do.\n" );
 69+ $start = $db->selectField( $table, "MIN($idCol)", false, __METHOD__ );
 70+ $end = $db->selectField( $table, "MAX($idCol)", false, __METHOD__ );
 71+ if ( !$start || !$end ) {
 72+ $this->output( "...revision table seems to be empty.\n" );
6173 return true;
6274 }
63 - $end = $db->selectField( $table, "MAX($idCol)", "$idCol IS NOT NULL", __METHOD__ );
6475
 76+ $count = 0;
6577 # Do remaining chunk
6678 $end += $this->mBatchSize - 1;
6779 $blockStart = $start;
@@ -68,7 +80,7 @@
6981 while ( $blockEnd <= $end ) {
7082 $this->output( "...doing $idCol from $blockStart to $blockEnd\n" );
7183 $cond = "$idCol BETWEEN $blockStart AND $blockEnd
72 - AND $idCol IS NOT NULL AND {$prefix}_sha1 != ''";
 84+ AND $idCol IS NOT NULL AND {$prefix}_sha1 = ''";
7385 $res = $db->select( $table, '*', $cond, __METHOD__ );
7486
7587 $db->begin();
@@ -87,6 +99,7 @@
88100 array( "{$prefix}_sha1" => Revision::base36Sha1( $text ) ),
89101 array( $idCol => $row->$idCol ),
90102 __METHOD__ );
 103+ $count++;
91104 }
92105 }
93106 $db->commit();
@@ -95,6 +108,7 @@
96109 $blockEnd += $this->mBatchSize;
97110 wfWaitForSlaves();
98111 }
 112+ return $count;
99113 }
100114 }
101115
Index: trunk/phase3/maintenance/populateRevisionLength.php
@@ -22,29 +22,39 @@
2323
2424 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
2525
26 -class PopulateRevisionLength extends Maintenance {
 26+class PopulateRevisionLength extends LoggedUpdateMaintenance {
2727 public function __construct() {
2828 parent::__construct();
29 - $this->mDescription = "Populates rev_len";
 29+ $this->mDescription = "Populates the rev_len field";
3030 $this->setBatchSize( 200 );
3131 }
3232
33 - public function execute() {
 33+ protected function getUpdateKey() {
 34+ return 'populate rev_len';
 35+ }
 36+
 37+ protected function updateSkippedMessage() {
 38+ return 'rev_len column of revision table already populated.';
 39+ }
 40+
 41+ protected function updatelogFailedMessage() {
 42+ return 'Could not insert rev_len population row.';
 43+ }
 44+
 45+ public function doDBUpdates() {
3446 $db = $this->getDB( DB_MASTER );
3547 if ( !$db->tableExists( 'revision' ) ) {
3648 $this->error( "revision table does not exist", true );
3749 }
3850 $this->output( "Populating rev_len column\n" );
39 - $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __FUNCTION__ );
40 - $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __FUNCTION__ );
41 - if ( is_null( $start ) || is_null( $end ) ) {
 51+
 52+ $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __METHOD__ );
 53+ $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __METHOD__ );
 54+ if ( !$start || !$end ) {
4255 $this->output( "...revision table seems to be empty.\n" );
43 - $db->insert( 'updatelog',
44 - array( 'ul_key' => 'populate rev_len' ),
45 - __METHOD__,
46 - 'IGNORE' );
47 - return;
 56+ return true;
4857 }
 58+
4959 # Do remaining chunks
5060 $blockStart = intval( $start );
5161 $blockEnd = intval( $start ) + $this->mBatchSize - 1;
@@ -80,17 +90,9 @@
8191 $blockEnd += $this->mBatchSize;
8292 wfWaitForSlaves();
8393 }
84 - $logged = $db->insert( 'updatelog',
85 - array( 'ul_key' => 'populate rev_len' ),
86 - __METHOD__,
87 - 'IGNORE' );
88 - if ( $logged ) {
89 - $this->output( "rev_len population complete ... {$count} rows changed ({$missing} missing)\n" );
90 - return true;
91 - } else {
92 - $this->output( "Could not insert rev_len population row.\n" );
93 - return false;
94 - }
 94+
 95+ $this->output( "rev_len population complete ... {$count} rows changed ({$missing} missing)\n" );
 96+ return true;
9597 }
9698 }
9799
Index: trunk/phase3/maintenance/Maintenance.php
@@ -1271,3 +1271,60 @@
12721272 return;
12731273 }
12741274 }
 1275+
 1276+abstract class LoggedUpdateMaintenance extends Maintenance {
 1277+ public function __construct() {
 1278+ parent::__construct();
 1279+ $this->addOption( 'force', 'Run the update even if it was completed already' );
 1280+ }
 1281+
 1282+ public function execute() {
 1283+ $db = $this->getDB( DB_MASTER );
 1284+ $key = $this->getUpdateKey();
 1285+
 1286+ if ( !$this->hasOption( 'force' ) &&
 1287+ $db->selectRow( 'updatelog', '1', array( 'ul_key' => $key ), __METHOD__ ) )
 1288+ {
 1289+ $this->output( $this->updateSkippedMessage() . "\n" );
 1290+ return true;
 1291+ }
 1292+
 1293+ if ( !$this->doDBUpdates() ) {
 1294+ return false;
 1295+ }
 1296+
 1297+ if (
 1298+ $db->insert( 'updatelog', array( 'ul_key' => $key ), __METHOD__, 'IGNORE' ) )
 1299+ {
 1300+ return true;
 1301+ } else {
 1302+ $this->output( $this->updatelogFailedMessage() . "\n" );
 1303+ return false;
 1304+ }
 1305+ }
 1306+
 1307+ /**
 1308+ * Do the actual work. All child classes will need to implement this.
 1309+ * Return true to log the update as done or false on failure.
 1310+ * @return Bool
 1311+ */
 1312+ abstract protected function doDBUpdates();
 1313+
 1314+ /**
 1315+ * Get the update key name to go in the update log table
 1316+ * @return String
 1317+ */
 1318+ abstract protected function getUpdateKey();
 1319+
 1320+ /**
 1321+ * Message to show that the update was done already and was just skipped
 1322+ * @return String
 1323+ */
 1324+ abstract protected function updateSkippedMessage();
 1325+
 1326+ /**
 1327+ * Message to show the the update log was unable to log the completion of this update
 1328+ * @return String
 1329+ */
 1330+ abstract protected function updatelogFailedMessage();
 1331+}
Index: trunk/phase3/includes/installer/DatabaseUpdater.php
@@ -40,7 +40,9 @@
4141 protected $shared = false;
4242
4343 protected $postDatabaseUpdateMaintenance = array(
44 - 'DeleteDefaultMessages'
 44+ 'DeleteDefaultMessages',
 45+ 'PopulateRevisionLength',
 46+ 'PopulateRevisionSha1'
4547 );
4648
4749 /**
@@ -573,14 +575,4 @@
574576 $task = $this->maintenance->runChild( 'UpdateCollation' );
575577 $task->execute();
576578 }
577 -
578 - protected function doPopulateRevSha1() {
579 - if ( $this->updateRowExists( 'populate rev_sha1' ) ) {
580 - $this->output( "...rev_sha1/ar_sha1 columns already populated.\n" );
581 - return;
582 - }
583 -
584 - $task = $this->maintenance->runChild( 'PopulateRevisionSha1' );
585 - $task->execute();
586 - }
587579 }
Index: trunk/phase3/includes/installer/MysqlUpdater.php
@@ -158,7 +158,6 @@
159159 array( 'doUpdateTranscacheField' ),
160160 array( 'renameEuWikiId' ),
161161 array( 'doUpdateMimeMinorField' ),
162 - array( 'doPopulateRevLen' ),
163162
164163 // 1.17
165164 array( 'addTable', 'iwlinks', 'patch-iwlinks.sql' ),
@@ -187,8 +186,7 @@
188187 array( 'addTable', 'config', 'patch-config.sql' ),
189188 array( 'addIndex', 'logging', 'type_action', 'patch-logging-type-action-index.sql'),
190189 array( 'addField', 'revision', 'rev_sha1', 'patch-rev_sha1.sql' ),
191 - array( 'addField', 'archive', 'ar_sha1', 'patch-ar_sha1.sql' ),
192 - array( 'doPopulateRevSha1' )
 190+ array( 'addField', 'archive', 'ar_sha1', 'patch-ar_sha1.sql' )
193191 );
194192 }
195193
@@ -812,16 +810,6 @@
813811 $this->output( "done.\n" );
814812 }
815813
816 - protected function doPopulateRevLen() {
817 - if ( $this->updateRowExists( 'populate rev_len' ) ) {
818 - $this->output( "...rev_len column already populated.\n" );
819 - return;
820 - }
821 -
822 - $task = $this->maintenance->runChild( 'PopulateRevisionLength' );
823 - $task->execute();
824 - }
825 -
826814 protected function doClFieldsUpdate() {
827815 if ( $this->updateRowExists( 'cl_fields_update' ) ) {
828816 $this->output( "...categorylinks up-to-date.\n" );
Index: trunk/phase3/includes/AutoLoader.php
@@ -832,6 +832,7 @@
833833 'DeleteArchivedRevisionsImplementation' => 'maintenance/deleteArchivedRevisions.inc',
834834 'DeleteDefaultMessages' => 'maintenance/deleteDefaultMessages.php',
835835 'FakeMaintenance' => 'maintenance/Maintenance.php',
 836+ 'LoggedUpdateMaintenance' => 'maintenance/Maintenance.php',
836837 'Maintenance' => 'maintenance/Maintenance.php',
837838 'PopulateCategory' => 'maintenance/populateCategory.php',
838839 'PopulateLogSearch' => 'maintenance/populateLogSearch.php',

Follow-up revisions

RevisionCommit summaryAuthorDate
r94374More to r94370:...aaron19:24, 12 August 2011
r94541Revert r94289, r94290, r94294, r94333, r94345, r94362, r94370 -- core schema ...brion18:24, 15 August 2011
r94546Restored r94370 changes PopulateRevisionLen, moving it to $postDatabaseUpdate...aaron18:52, 15 August 2011
r103033REL1_18 Partial manual merge of r94370, r94382, r96578, r101019 to bring Logg...reedy21:20, 14 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r94289* Added rev_sha1 and ar_sha1 columns to revision/archive tables (useful for b......aaron21:52, 11 August 2011
r94362Fix for r94289: we want to skip rows with non-empty sha1, not non-NULL (which...aaron16:50, 12 August 2011

Comments

#Comment by Krinkle (talk | contribs)   19:18, 12 August 2011

Thanks, finally I can update my wiki again :-)

Populating ar_sha1 column
...revision table seems to be empty.
rev_sha1 and ar_sha1 population complete [28 revision rows, 1 archive rows].

The comment seems wrong though, it hardcodes "revision".

#Comment by Krinkle (talk | contribs)   19:21, 12 August 2011

http://ci.tesla.usability.wikimedia.org/cruisecontrol/buildresults/mw:

PHP Warning:  call_user_func_array() expects parameter 1 to be a valid callback, function 'doPopulateRevSha1' not found or invalid function name in /home/ci/cruisecontrol-bin-2.8.3/projects/mw/source/includes/installer/DatabaseUpdater.php on line 230
#Comment by Brion VIBBER (talk | contribs)   18:27, 15 August 2011

undiscussed core schema change, reverted in r94541.

#Comment by 😂 (talk | contribs)   18:31, 15 August 2011

The ideas in this commit are good and should be reapplied :)

#Comment by Aaron Schulz (talk | contribs)   18:32, 15 August 2011

Yeah, I'm trying to do that now.

Status & tagging log