r94541 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94540‎ | r94541 | r94542 >
Date:18:24, 15 August 2011
Author:brion
Status:ok
Tags:
Comment:
Revert r94289, r94290, r94294, r94333, r94345, r94362, r94370 -- core schema change with no discussion
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/includes/installer/SqliteUpdater.php (modified) (history)
  • /trunk/phase3/maintenance/archives/patch-ar_sha1.sql (modified) (history)
  • /trunk/phase3/maintenance/archives/patch-rev_sha1.sql (modified) (history)
  • /trunk/phase3/maintenance/populateRevisionLength.php (modified) (history)
  • /trunk/phase3/maintenance/populateRevisionSha1.php (deleted) (history)
  • /trunk/phase3/maintenance/tables.sql (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/populateRevisionSha1.php
@@ -1,116 +0,0 @@
2 -<?php
3 -/**
4 - * Fills the rev_sha1 and ar_sha1 columns of revision
5 - * and archive tables for revisions created before MW 1.19.
6 - *
7 - * This program is free software; you can redistribute it and/or modify
8 - * it under the terms of the GNU General Public License as published by
9 - * the Free Software Foundation; either version 2 of the License, or
10 - * (at your option) any later version.
11 - *
12 - * This program is distributed in the hope that it will be useful,
13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 - * GNU General Public License for more details.
16 - *
17 - * You should have received a copy of the GNU General Public License along
18 - * with this program; if not, write to the Free Software Foundation, Inc.,
19 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 - * http://www.gnu.org/copyleft/gpl.html
21 - *
22 - * @ingroup Maintenance
23 - */
24 -
25 -require_once( dirname( __FILE__ ) . '/Maintenance.php' );
26 -
27 -class PopulateRevisionSha1 extends LoggedUpdateMaintenance {
28 - public function __construct() {
29 - parent::__construct();
30 - $this->mDescription = "Populates the rev_sha1 and ar_sha1 fields";
31 - $this->setBatchSize( 200 );
32 - }
33 -
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() {
47 - $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 - }
54 -
55 - $this->output( "Populating rev_sha1 column\n" );
56 - $rc = $this->doSha1Updates( $db, 'revision', 'rev_id', 'rev' );
57 -
58 - $this->output( "Populating ar_sha1 column\n" );
59 - $ac = $this->doSha1Updates( $db, 'archive', 'ar_rev_id', 'ar' );
60 -
61 - $this->output( "rev_sha1 and ar_sha1 population complete [$rc revision rows, $ac archive rows].\n" );
62 - return true;
63 - }
64 -
65 - /**
66 - * @return Integer Rows changed
67 - */
68 - protected function doSha1Updates( $db, $table, $idCol, $prefix ) {
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( "...$table table seems to be empty.\n" );
73 - return true;
74 - }
75 -
76 - $count = 0;
77 - # Do remaining chunk
78 - $end += $this->mBatchSize - 1;
79 - $blockStart = $start;
80 - $blockEnd = $start + $this->mBatchSize - 1;
81 - while ( $blockEnd <= $end ) {
82 - $this->output( "...doing $idCol from $blockStart to $blockEnd\n" );
83 - $cond = "$idCol BETWEEN $blockStart AND $blockEnd
84 - AND $idCol IS NOT NULL AND {$prefix}_sha1 = ''";
85 - $res = $db->select( $table, '*', $cond, __METHOD__ );
86 -
87 - $db->begin();
88 - foreach ( $res as $row ) {
89 - if ( $table === 'archive' ) {
90 - $rev = Revision::newFromArchiveRow( $row );
91 - } else {
92 - $rev = new Revision( $row );
93 - }
94 - $text = $rev->getRawText();
95 - if ( !is_string( $text ) ) {
96 - # This should not happen, but sometimes does (bug 20757)
97 - $this->output( "Text of revision {$row->$idCol} unavailable!\n" );
98 - } else {
99 - $db->update( $table,
100 - array( "{$prefix}_sha1" => Revision::base36Sha1( $text ) ),
101 - array( $idCol => $row->$idCol ),
102 - __METHOD__ );
103 - $count++;
104 - }
105 - }
106 - $db->commit();
107 -
108 - $blockStart += $this->mBatchSize;
109 - $blockEnd += $this->mBatchSize;
110 - wfWaitForSlaves();
111 - }
112 - return $count;
113 - }
114 -}
115 -
116 -$maintClass = "PopulateRevisionSha1";
117 -require_once( RUN_MAINTENANCE_IF_MAIN );
Index: trunk/phase3/maintenance/archives/patch-ar_sha1.sql
@@ -1,3 +0,0 @@
2 -ALTER TABLE /*$wgDBprefix*/archive
3 - ADD ar_sha1 varbinary(32) NOT NULL default '';
Index: trunk/phase3/maintenance/archives/patch-rev_sha1.sql
@@ -1,3 +0,0 @@
2 -ALTER TABLE /*$wgDBprefix*/revision
3 - ADD rev_sha1 varbinary(32) NOT NULL default '';
Index: trunk/phase3/maintenance/populateRevisionLength.php
@@ -22,39 +22,29 @@
2323
2424 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
2525
26 -class PopulateRevisionLength extends LoggedUpdateMaintenance {
 26+class PopulateRevisionLength extends Maintenance {
2727 public function __construct() {
2828 parent::__construct();
29 - $this->mDescription = "Populates the rev_len field";
 29+ $this->mDescription = "Populates rev_len";
3030 $this->setBatchSize( 200 );
3131 }
3232
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() {
 33+ public function execute() {
4634 $db = $this->getDB( DB_MASTER );
4735 if ( !$db->tableExists( 'revision' ) ) {
4836 $this->error( "revision table does not exist", true );
4937 }
5038 $this->output( "Populating rev_len column\n" );
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 ) {
 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 ) ) {
5542 $this->output( "...revision table seems to be empty.\n" );
56 - return true;
 43+ $db->insert( 'updatelog',
 44+ array( 'ul_key' => 'populate rev_len' ),
 45+ __METHOD__,
 46+ 'IGNORE' );
 47+ return;
5748 }
58 -
5949 # Do remaining chunks
6050 $blockStart = intval( $start );
6151 $blockEnd = intval( $start ) + $this->mBatchSize - 1;
@@ -90,9 +80,17 @@
9181 $blockEnd += $this->mBatchSize;
9282 wfWaitForSlaves();
9383 }
94 -
95 - $this->output( "rev_len population complete ... {$count} rows changed ({$missing} missing)\n" );
96 - return true;
 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+ }
9795 }
9896 }
9997
Index: trunk/phase3/maintenance/tables.sql
@@ -317,11 +317,8 @@
318318
319319 -- Key to revision.rev_id
320320 -- This field is used to add support for a tree structure (The Adjacency List Model)
321 - rev_parent_id int unsigned default NULL,
 321+ rev_parent_id int unsigned default NULL
322322
323 - -- SHA-1 text content hash in base-36
324 - rev_sha1 varbinary(32) NOT NULL default ''
325 -
326323 ) /*$wgDBTableOptions*/ MAX_ROWS=10000000 AVG_ROW_LENGTH=1024;
327324 -- In case tables are created as MyISAM, use row hints for MySQL <5.0 to avoid 4GB limit
328325
@@ -427,10 +424,7 @@
428425 ar_page_id int unsigned,
429426
430427 -- Original previous revision
431 - ar_parent_id int unsigned default NULL,
432 -
433 - -- SHA-1 text content hash in base-36
434 - ar_sha1 varbinary(32) NOT NULL default ''
 428+ ar_parent_id int unsigned default NULL
435429 ) /*$wgDBTableOptions*/;
436430
437431 CREATE INDEX /*i*/name_title_timestamp ON /*_*/archive (ar_namespace,ar_title,ar_timestamp);
Index: trunk/phase3/includes/installer/DatabaseUpdater.php
@@ -40,10 +40,7 @@
4141 protected $shared = false;
4242
4343 protected $postDatabaseUpdateMaintenance = array(
44 - 'DeleteDefaultMessages',
45 - 'PopulateRevisionLength',
46 - 'PopulateRevisionSha1',
47 - 'PopulateImageSha1'
 44+ 'DeleteDefaultMessages'
4845 );
4946
5047 /**
Index: trunk/phase3/includes/installer/MysqlUpdater.php
@@ -158,6 +158,7 @@
159159 array( 'doUpdateTranscacheField' ),
160160 array( 'renameEuWikiId' ),
161161 array( 'doUpdateMimeMinorField' ),
 162+ array( 'doPopulateRevLen' ),
162163
163164 // 1.17
164165 array( 'addTable', 'iwlinks', 'patch-iwlinks.sql' ),
@@ -185,8 +186,6 @@
186187 // 1.19
187188 array( 'addTable', 'config', 'patch-config.sql' ),
188189 array( 'addIndex', 'logging', 'type_action', 'patch-logging-type-action-index.sql'),
189 - array( 'addField', 'revision', 'rev_sha1', 'patch-rev_sha1.sql' ),
190 - array( 'addField', 'archive', 'ar_sha1', 'patch-ar_sha1.sql' )
191190 );
192191 }
193192
@@ -810,6 +809,16 @@
811810 $this->output( "done.\n" );
812811 }
813812
 813+ protected function doPopulateRevLen() {
 814+ if ( $this->updateRowExists( 'populate rev_len' ) ) {
 815+ $this->output( "...rev_len column already populated.\n" );
 816+ return;
 817+ }
 818+
 819+ $task = $this->maintenance->runChild( 'PopulateRevisionLength' );
 820+ $task->execute();
 821+ }
 822+
814823 protected function doClFieldsUpdate() {
815824 if ( $this->updateRowExists( 'cl_fields_update' ) ) {
816825 $this->output( "...categorylinks up-to-date.\n" );
Index: trunk/phase3/includes/installer/SqliteUpdater.php
@@ -62,9 +62,7 @@
6363
6464 // 1.19
6565 array( 'addTable', 'config', 'patch-config.sql' ),
66 - array( 'addIndex', 'logging', 'type_action', 'patch-logging-type-action-index.sql'),
67 - array( 'addField', 'revision', 'rev_sha1', 'patch-rev_sha1.sql' ),
68 - array( 'addField', 'archive', 'ar_sha1', 'patch-ar_sha1.sql' )
 66+ array( 'addIndex', 'logging', 'type_action', 'patch-logging-type-action-index.sql')
6967 );
7068 }
7169
Index: trunk/phase3/includes/AutoLoader.php
@@ -833,7 +833,6 @@
834834 'DeleteArchivedRevisionsImplementation' => 'maintenance/deleteArchivedRevisions.inc',
835835 'DeleteDefaultMessages' => 'maintenance/deleteDefaultMessages.php',
836836 'FakeMaintenance' => 'maintenance/Maintenance.php',
837 - 'LoggedUpdateMaintenance' => 'maintenance/Maintenance.php',
838837 'Maintenance' => 'maintenance/Maintenance.php',
839838 'PopulateCategory' => 'maintenance/populateCategory.php',
840839 'PopulateImageSha1' => 'maintenance/populateImageSha1.php',
@@ -841,7 +840,6 @@
842841 'PopulateLogUsertext' => 'maintenance/populateLogUsertext.php',
843842 'PopulateParentId' => 'maintenance/populateParentId.php',
844843 'PopulateRevisionLength' => 'maintenance/populateRevisionLength.php',
845 - 'PopulateRevisionSha1' => 'maintenance/populateRevisionSha1.php',
846844 'SevenZipStream' => 'maintenance/7zip.inc',
847845 'Sqlite' => 'maintenance/sqlite.inc',
848846 'UpdateCollation' => 'maintenance/updateCollation.php',

Follow-up revisions

RevisionCommit summaryAuthorDate
r94547Followup r94541 (reverts of r94289 undiscussed core schema change and followu...brion18:52, 15 August 2011
r94875fu r94541: Delete empty filesraymond07:49, 18 August 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
r94290Follow-up r94289: code changes to fill the new fields on insertion and select...aaron21:54, 11 August 2011
r94294Fix case of the new file added in r94289...platonides22:32, 11 August 2011
r94333Fix copy-paste mistake in r94289catrope10:00, 12 August 2011
r94345Follow-up r94289: SQLite support, unbreaks testsmaxsem13:16, 12 August 2011
r94362Fix for r94289: we want to skip rows with non-empty sha1, not non-NULL (which...aaron16:50, 12 August 2011
r94370* Added LoggedUpdateMaintenance subclass...aaron19:11, 12 August 2011

Status & tagging log