r96578 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96577‎ | r96578 | r96579 >
Date:15:52, 8 September 2011
Author:demon
Status:ok
Tags:
Comment:
Tweaks to LoggedUpdateMaintenance:
* Reduce some duplication
* Prefix skipped steps with "..." per updater convention
* Make PopulateLogUsertext, PopulateLogSearch and PopulateParentId use LoggedUpdateMaintenance -- now they will properly log when there was "Nothing to do" and we can skip the clutter on future update runs
* Docs, etc.
Modified paths:
  • /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/populateImageSha1.php (modified) (history)
  • /trunk/phase3/maintenance/populateLogSearch.php (modified) (history)
  • /trunk/phase3/maintenance/populateLogUsertext.php (modified) (history)
  • /trunk/phase3/maintenance/populateParentId.php (modified) (history)
  • /trunk/phase3/maintenance/populateRevisionLength.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/populateRevisionLength.php
@@ -26,7 +26,6 @@
2727 public function __construct() {
2828 parent::__construct();
2929 $this->mDescription = "Populates the rev_len field";
30 - $this->setBatchSize( 200 );
3130 }
3231
3332 protected function getUpdateKey() {
@@ -37,10 +36,6 @@
3837 return 'rev_len column of revision table already populated.';
3938 }
4039
41 - protected function updatelogFailedMessage() {
42 - return 'Could not insert rev_len population row.';
43 - }
44 -
4540 public function doDBUpdates() {
4641 $db = $this->getDB( DB_MASTER );
4742 if ( !$db->tableExists( 'revision' ) ) {
Index: trunk/phase3/maintenance/populateParentId.php
@@ -24,28 +24,32 @@
2525
2626 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
2727
28 -class PopulateParentId extends Maintenance {
 28+class PopulateParentId extends LoggedUpdateMaintenance {
2929 public function __construct() {
3030 parent::__construct();
3131 $this->mDescription = "Populates rev_parent_id";
32 - $this->setBatchSize( 200 );
3332 }
3433
35 - public function execute() {
 34+ protected function getUpdateKey() {
 35+ return 'populate rev_parent_id';
 36+ }
 37+
 38+ protected function updateSkippedMessage() {
 39+ return 'rev_parent_id column of revision table already populated.';
 40+ }
 41+
 42+ protected function doDBUpdates() {
3643 $db = wfGetDB( DB_MASTER );
3744 if ( !$db->tableExists( 'revision' ) ) {
38 - $this->error( "revision table does not exist", true );
 45+ $this->error( "revision table does not exist" );
 46+ return false;
3947 }
4048 $this->output( "Populating rev_parent_id column\n" );
4149 $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __FUNCTION__ );
4250 $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __FUNCTION__ );
4351 if ( is_null( $start ) || is_null( $end ) ) {
44 - $this->output( "...revision table seems to be empty.\n" );
45 - $db->insert( 'updatelog',
46 - array( 'ul_key' => 'populate rev_parent_id' ),
47 - __METHOD__,
48 - 'IGNORE' );
49 - return;
 52+ $this->output( "...revision table seems to be empty, nothing to do.\n" );
 53+ return true;
5054 }
5155 # Do remaining chunk
5256 $blockStart = intval( $start );
@@ -100,17 +104,8 @@
101105 $blockEnd += $this->mBatchSize;
102106 wfWaitForSlaves();
103107 }
104 - $logged = $db->insert( 'updatelog',
105 - array( 'ul_key' => 'populate rev_parent_id' ),
106 - __METHOD__,
107 - 'IGNORE' );
108 - if ( $logged ) {
109 - $this->output( "rev_parent_id population complete ... {$count} rows [{$changed} changed]\n" );
110 - return true;
111 - } else {
112 - $this->output( "Could not insert rev_parent_id population row.\n" );
113 - return false;
114 - }
 108+ $this->output( "rev_parent_id population complete ... {$count} rows [{$changed} changed]\n" );
 109+ return true;
115110 }
116111 }
117112
Index: trunk/phase3/maintenance/Maintenance.php
@@ -1224,6 +1224,9 @@
12251225 }
12261226 }
12271227
 1228+/**
 1229+ * Fake maintenance wrapper, mostly used for the web installer/updater
 1230+ */
12281231 class FakeMaintenance extends Maintenance {
12291232 protected $mSelf = "FakeMaintenanceScript";
12301233 public function execute() {
@@ -1231,10 +1234,15 @@
12321235 }
12331236 }
12341237
 1238+/**
 1239+ * Class for scripts that perform database maintenance and want to log the
 1240+ * update in `updatelog` so we can later skip it
 1241+ */
12351242 abstract class LoggedUpdateMaintenance extends Maintenance {
12361243 public function __construct() {
12371244 parent::__construct();
12381245 $this->addOption( 'force', 'Run the update even if it was completed already' );
 1246+ $this->setBatchSize( 200 );
12391247 }
12401248
12411249 public function execute() {
@@ -1244,7 +1252,7 @@
12451253 if ( !$this->hasOption( 'force' ) &&
12461254 $db->selectRow( 'updatelog', '1', array( 'ul_key' => $key ), __METHOD__ ) )
12471255 {
1248 - $this->output( $this->updateSkippedMessage() . "\n" );
 1256+ $this->output( "..." . $this->updateSkippedMessage() . "\n" );
12491257 return true;
12501258 }
12511259
@@ -1263,6 +1271,15 @@
12641272 }
12651273
12661274 /**
 1275+ * Message to show the the update log was unable to log the completion of this update
 1276+ * @return String
 1277+ */
 1278+ protected function updatelogFailedMessage() {
 1279+ $key = $this->getUpdateKey();
 1280+ return "Unable to log update '{$key}' as completed.";
 1281+ }
 1282+
 1283+ /**
12671284 * Do the actual work. All child classes will need to implement this.
12681285 * Return true to log the update as done or false (usually on failure).
12691286 * @return Bool
@@ -1280,10 +1297,4 @@
12811298 * @return String
12821299 */
12831300 abstract protected function updateSkippedMessage();
1284 -
1285 - /**
1286 - * Message to show the the update log was unable to log the completion of this update
1287 - * @return String
1288 - */
1289 - abstract protected function updatelogFailedMessage();
12901301 }
Index: trunk/phase3/maintenance/populateLogUsertext.php
@@ -25,14 +25,22 @@
2626
2727 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
2828
29 -class PopulateLogUsertext extends Maintenance {
 29+class PopulateLogUsertext extends LoggedUpdateMaintenance {
3030 public function __construct() {
3131 parent::__construct();
32 - $this->mDescription = "Populates the log_user_text";
 32+ $this->mDescription = "Populates the log_user_text field";
3333 $this->setBatchSize( 100 );
3434 }
3535
36 - public function execute() {
 36+ protected function getUpdateKey() {
 37+ return 'populate log_usertext';
 38+ }
 39+
 40+ protected function updateSkippedMessage() {
 41+ return 'log_user_text column of logging table already populated.';
 42+ }
 43+
 44+ protected function doDBUpdates() {
3745 $db = $this->getDB( DB_MASTER );
3846 $start = $db->selectField( 'logging', 'MIN(log_id)', false, __METHOD__ );
3947 if ( !$start ) {
@@ -61,19 +69,8 @@
6270 $blockEnd += $this->mBatchSize;
6371 wfWaitForSlaves();
6472 }
65 - if ( $db->insert(
66 - 'updatelog',
67 - array( 'ul_key' => 'populate log_usertext' ),
68 - __METHOD__,
69 - 'IGNORE'
70 - )
71 - ) {
72 - $this->output( "log_usertext population complete.\n" );
73 - return true;
74 - } else {
75 - $this->output( "Could not insert log_usertext population row.\n" );
76 - return false;
77 - }
 73+ $this->output( "Done populating log_user_text field.\n" );
 74+ return true;
7875 }
7976 }
8077
Index: trunk/phase3/maintenance/populateImageSha1.php
@@ -29,7 +29,6 @@
3030 $this->addOption( 'method', "Use 'pipe' to pipe to mysql command line,\n" .
3131 "\t\tdefault uses Database class", false, true );
3232 $this->addOption( 'file', 'Fix for a specific file, without File: namespace prefixed', false, true );
33 - $this->setBatchSize( 200 );
3433 }
3534
3635 protected function getUpdateKey() {
@@ -40,10 +39,6 @@
4140 return 'img_sha1 column of image table already populated.';
4241 }
4342
44 - protected function updatelogFailedMessage() {
45 - return 'Could not insert img_sha1 population row.';
46 - }
47 -
4843 public function doDBUpdates() {
4944 $method = $this->getOption( 'method', 'normal' );
5045 $file = $this->getOption( 'file' );
Index: trunk/phase3/maintenance/populateLogSearch.php
@@ -23,21 +23,28 @@
2424
2525 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
2626
27 -class PopulateLogSearch extends Maintenance {
28 -
29 - const LOG_SEARCH_BATCH_SIZE = 100;
30 -
 27+class PopulateLogSearch extends LoggedUpdateMaintenance {
3128 static $tableMap = array( 'rev' => 'revision', 'fa' => 'filearchive', 'oi' => 'oldimage', 'ar' => 'archive' );
3229
3330 public function __construct() {
3431 parent::__construct();
3532 $this->mDescription = "Migrate log params to new table and index for searching";
 33+ $this->setBatchSize( 100 );
3634 }
3735
38 - public function execute() {
 36+ protected function getUpdateKey() {
 37+ return 'populate log_search';
 38+ }
 39+
 40+ protected function updateSkippedMessage() {
 41+ return 'log_search table already populated.';
 42+ }
 43+
 44+ protected function doDBUpdates() {
3945 $db = $this->getDB( DB_MASTER );
4046 if ( !$db->tableExists( 'log_search' ) ) {
41 - $this->error( "log_search does not exist", true );
 47+ $this->error( "log_search does not exist" );
 48+ return false;
4249 }
4350 $start = $db->selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ );
4451 if ( !$start ) {
@@ -47,9 +54,9 @@
4855 $end = $db->selectField( 'logging', 'MAX(log_id)', false, __FUNCTION__ );
4956
5057 # Do remaining chunk
51 - $end += self::LOG_SEARCH_BATCH_SIZE - 1;
 58+ $end += $this->mBatchSize - 1;
5259 $blockStart = $start;
53 - $blockEnd = $start + self::LOG_SEARCH_BATCH_SIZE - 1;
 60+ $blockEnd = $start + $this->mBatchSize - 1;
5461
5562 $delTypes = array( 'delete', 'suppress' ); // revisiondelete types
5663 while ( $blockEnd <= $end ) {
@@ -128,23 +135,12 @@
129136 $log->addRelations( 'target_author_ip', $userIPs, $row->log_id );
130137 }
131138 }
132 - $blockStart += self::LOG_SEARCH_BATCH_SIZE;
133 - $blockEnd += self::LOG_SEARCH_BATCH_SIZE;
 139+ $blockStart += $this->mBatchSize;
 140+ $blockEnd += $this->mBatchSize;
134141 wfWaitForSlaves();
135142 }
136 - if ( $db->insert(
137 - 'updatelog',
138 - array( 'ul_key' => 'populate log_search' ),
139 - __FUNCTION__,
140 - 'IGNORE'
141 - )
142 - ) {
143 - $this->output( "log_search population complete.\n" );
144 - return true;
145 - } else {
146 - $this->output( "Could not insert log_search population row.\n" );
147 - return false;
148 - }
 143+ $this->output( "Done populating log_search table.\n" );
 144+ return true;
149145 }
150146 }
151147
Index: trunk/phase3/includes/installer/DatabaseUpdater.php
@@ -519,33 +519,25 @@
520520 }
521521
522522 protected function doLogUsertextPopulation() {
523 - if ( $this->updateRowExists( 'populate log_usertext' ) ) {
524 - $this->output( "...log_user_text field already populated.\n" );
525 - return;
526 - }
527 -
528 - $this->output(
 523+ if ( !$this->updateRowExists( 'populate log_usertext' ) ) {
 524+ $this->output(
529525 "Populating log_user_text field, printing progress markers. For large\n" .
530526 "databases, you may want to hit Ctrl-C and do this manually with\n" .
531527 "maintenance/populateLogUsertext.php.\n" );
 528+ }
532529 $task = $this->maintenance->runChild( 'PopulateLogUsertext' );
533530 $task->execute();
534 - $this->output( "Done populating log_user_text field.\n" );
535531 }
536532
537533 protected function doLogSearchPopulation() {
538 - if ( $this->updateRowExists( 'populate log_search' ) ) {
539 - $this->output( "...log_search table already populated.\n" );
540 - return;
 534+ if ( !$this->updateRowExists( 'populate log_search' ) ) {
 535+ $this->output(
 536+ "Populating log_search table, printing progress markers. For large\n" .
 537+ "databases, you may want to hit Ctrl-C and do this manually with\n" .
 538+ "maintenance/populateLogSearch.php.\n" );
541539 }
542 -
543 - $this->output(
544 - "Populating log_search table, printing progress markers. For large\n" .
545 - "databases, you may want to hit Ctrl-C and do this manually with\n" .
546 - "maintenance/populateLogSearch.php.\n" );
547540 $task = $this->maintenance->runChild( 'PopulateLogSearch' );
548541 $task->execute();
549 - $this->output( "Done populating log_search table.\n" );
550542 }
551543
552544 protected function doUpdateTranscacheField() {
Index: trunk/phase3/includes/installer/MysqlUpdater.php
@@ -747,11 +747,12 @@
748748 }
749749
750750 protected function doPopulateParentId() {
751 - if ( $this->updateRowExists( 'populate rev_parent_id' ) ) {
752 - $this->output( "...rev_parent_id column already populated.\n" );
753 - return;
 751+ if ( !$this->updateRowExists( 'populate rev_parent_id' ) ) {
 752+ $this->output(
 753+ "Populating rev_parent_id fields, printing progress markers. For large\n" .
 754+ "databases, you may want to hit Ctrl-C and do this manually with\n" .
 755+ "maintenance/populateParentId.php.\n" );
754756 }
755 -
756757 $task = $this->maintenance->runChild( 'PopulateParentId' );
757758 $task->execute();
758759 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r103033REL1_18 Partial manual merge of r94370, r94382, r96578, r101019 to bring Logg...reedy21:20, 14 November 2011

Status & tagging log