| Index: trunk/phase3/maintenance/updateCollation.php |
| — | — | @@ -29,7 +29,8 @@ |
| 30 | 30 | require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
| 31 | 31 | |
| 32 | 32 | class UpdateCollation extends Maintenance { |
| 33 | | - const BATCH_SIZE = 50; |
| | 33 | + const BATCH_SIZE = 50; // Number of rows to process in one batch |
| | 34 | + const SYNC_INTERVAL = 20; // Wait for slaves after this many batches |
| 34 | 35 | |
| 35 | 36 | public function __construct() { |
| 36 | 37 | parent::__construct(); |
| — | — | @@ -44,10 +45,17 @@ |
| 45 | 46 | |
| 46 | 47 | $this->addOption( 'force', 'Run on all rows, even if the collation is ' . |
| 47 | 48 | 'supposed to be up-to-date.' ); |
| | 49 | + $this->addOption( 'previous-collation', 'Set the previous value of ' . |
| | 50 | + '$wgCategoryCollation here to speed up this script, especially if your ' . |
| | 51 | + 'categorylinks table is large. This will only update rows with that ' . |
| | 52 | + 'collation, though, so it may miss out-of-date rows with a different, ' . |
| | 53 | + 'even older collation.', false, true ); |
| 48 | 54 | } |
| 49 | 55 | |
| 50 | 56 | public function syncDBs() { |
| | 57 | + // TODO: Most of this is duplicated from wfWaitForSlaves(), except for the waitTimeout() call |
| 51 | 58 | $lb = wfGetLB(); |
| | 59 | + $lb->waitTimeout(100000); |
| 52 | 60 | // bug 27975 - Don't try to wait for slaves if there are none |
| 53 | 61 | // Prevents permission error when getting master position |
| 54 | 62 | if ( $lb->getServerCount() > 1 ) { |
| — | — | @@ -63,14 +71,19 @@ |
| 64 | 72 | $dbw = $this->getDB( DB_MASTER ); |
| 65 | 73 | $force = $this->getOption( 'force' ); |
| 66 | 74 | |
| 67 | | - $options = array( 'LIMIT' => self::BATCH_SIZE ); |
| | 75 | + $options = array( 'LIMIT' => self::BATCH_SIZE, 'STRAIGHT_JOIN' ); |
| 68 | 76 | |
| 69 | 77 | if ( $force ) { |
| 70 | 78 | $options['ORDER BY'] = 'cl_from, cl_to'; |
| 71 | 79 | $collationConds = array(); |
| 72 | 80 | } else { |
| 73 | | - $collationConds = array( 0 => |
| 74 | | - 'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ) ); |
| | 81 | + if ( $this->hasOption( 'previous-collation' ) ) { |
| | 82 | + $collationConds['cl_collation'] = $this->getOption( 'previous-collation' ); |
| | 83 | + } else { |
| | 84 | + $collationConds = array( 0 => |
| | 85 | + 'cl_collation != ' . $dbw->addQuotes( $wgCategoryCollation ) |
| | 86 | + ); |
| | 87 | + } |
| 75 | 88 | |
| 76 | 89 | if ( !$wgMiserMode ) { |
| 77 | 90 | $count = $dbw->selectField( |
| — | — | @@ -89,9 +102,10 @@ |
| 90 | 103 | } |
| 91 | 104 | |
| 92 | 105 | $count = 0; |
| | 106 | + $batchCount = 0; |
| 93 | 107 | $batchConds = array(); |
| 94 | 108 | do { |
| 95 | | - $this->output( 'Processing next ' . self::BATCH_SIZE . ' rows... '); |
| | 109 | + $this->output( "Selecting next " . self::BATCH_SIZE . " rows..." ); |
| 96 | 110 | $res = $dbw->select( |
| 97 | 111 | array( 'categorylinks', 'page' ), |
| 98 | 112 | array( 'cl_from', 'cl_to', 'cl_sortkey_prefix', 'cl_collation', |
| — | — | @@ -101,6 +115,7 @@ |
| 102 | 116 | __METHOD__, |
| 103 | 117 | $options |
| 104 | 118 | ); |
| | 119 | + $this->output( " processing..." ); |
| 105 | 120 | |
| 106 | 121 | $dbw->begin(); |
| 107 | 122 | foreach ( $res as $row ) { |
| — | — | @@ -154,7 +169,11 @@ |
| 155 | 170 | $count += $res->numRows(); |
| 156 | 171 | $this->output( "$count done.\n" ); |
| 157 | 172 | |
| 158 | | - $this->syncDBs(); |
| | 173 | + if ( ++$batchCount % self::SYNC_INTERVAL == 0 ) { |
| | 174 | + $this->output( "Waiting for slaves ... " ); |
| | 175 | + $this->syncDBs(); |
| | 176 | + $this->output( "done\n" ); |
| | 177 | + } |
| 159 | 178 | } while ( $res->numRows() == self::BATCH_SIZE ); |
| 160 | 179 | } |
| 161 | 180 | } |
| Property changes on: trunk/phase3/maintenance/updateCollation.php |
| ___________________________________________________________________ |
| Added: svn:mergeinfo |
| 162 | 181 | Merged /branches/REL1_17/phase3/maintenance/updateCollation.php:r81445,81448 |
| 163 | 182 | Merged /branches/sqlite/maintenance/updateCollation.php:r58211-58321 |
| 164 | 183 | Merged /branches/new-installer/phase3/maintenance/updateCollation.php:r43664-66004 |
| 165 | 184 | Merged /branches/wmf/1.17wmf1/maintenance/updateCollation.php:r83992 |
| 166 | 185 | Merged /branches/REL1_15/phase3/maintenance/updateCollation.php:r51646 |