require_once __DIR__ . '/Maintenance.php';
+use Wikimedia\Rdbms\IDatabase;
+
/**
* Maintenance script that will find all rows in the categorylinks table
* whose collation is out-of-date.
*/
class UpdateCollation extends Maintenance {
const BATCH_SIZE = 100; // Number of rows to process in one batch
- const SYNC_INTERVAL = 20; // Wait for slaves after this many batches
+ const SYNC_INTERVAL = 5; // Wait for replica DBs after this many batches
public $sizeHistogram = [];
global $wgCategoryCollation;
$dbw = $this->getDB( DB_MASTER );
+ $dbr = $this->getDB( DB_REPLICA );
$force = $this->getOption( 'force' );
$dryRun = $this->getOption( 'dry-run' );
$verboseStats = $this->getOption( 'verbose-stats' );
$options = [
'LIMIT' => self::BATCH_SIZE,
'ORDER BY' => $orderBy,
+ 'STRAIGHT_JOIN' // per T58041
];
- if ( $force || $dryRun ) {
+ if ( $force ) {
$collationConds = [];
} else {
if ( $this->hasOption( 'previous-collation' ) ) {
];
}
- $count = $dbw->estimateRowCount(
+ $count = $dbr->estimateRowCount(
'categorylinks',
'*',
$collationConds,
);
// Improve estimate if feasible
if ( $count < 1000000 ) {
- $count = $dbw->selectField(
+ $count = $dbr->selectField(
'categorylinks',
'COUNT(*)',
$collationConds,
return;
}
- $this->output( "Fixing collation for $count rows.\n" );
+ if ( $dryRun ) {
+ $this->output( "$count rows would be updated.\n" );
+ } else {
+ $this->output( "Fixing collation for $count rows.\n" );
+ }
+ wfWaitForSlaves();
}
$count = 0;
$batchCount = 0;
$this->output( "$count done.\n" );
if ( !$dryRun && ++$batchCount % self::SYNC_INTERVAL == 0 ) {
- $this->output( "Waiting for slaves ... " );
+ $this->output( "Waiting for replica DBs ... " );
wfWaitForSlaves();
$this->output( "done\n" );
}
* Return an SQL expression selecting rows which sort above the given row,
* assuming an ordering of cl_collation, cl_to, cl_type, cl_from
* @param stdClass $row
- * @param DatabaseBase $dbw
+ * @param IDatabase $dbw
* @return string
*/
function getBatchCondition( $row, $dbw ) {