*/
use MediaWiki\MediaWikiServices;
+use MediaWiki\Revision\SlotRecord;
use Wikimedia\Rdbms\DBConnectionError;
require __DIR__ . '/../commandLine.inc';
* Scan the revision table for rows stored in the specified clusters
*/
function trackRevisions() {
+ global $wgMultiContentRevisionSchemaMigrationStage;
+
$dbw = wfGetDB( DB_MASTER );
$dbr = wfGetDB( DB_REPLICA );
echo "Finding revisions...\n";
+ $fields = [ 'rev_id', 'rev_page', 'old_id', 'old_flags', 'old_text' ];
+ $options = [
+ 'ORDER BY' => 'rev_id',
+ 'LIMIT' => $this->batchSize
+ ];
+ $conds = [
+ $textClause,
+ 'old_flags ' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ),
+ ];
+ if ( $wgMultiContentRevisionSchemaMigrationStage & SCHEMA_COMPAT_READ_OLD ) {
+ $tables = [ 'revision', 'text' ];
+ $conds = array_merge( [
+ 'rev_text_id=old_id',
+ ], $conds );
+ } else {
+ $slotRoleStore = MediaWikiServices::getInstance()->getSlotRoleStore();
+ $tables = [ 'revision', 'slots', 'content', 'text' ];
+ $conds = array_merge( [
+ 'rev_id=slot_revision_id',
+ 'slot_role_id=' . $slotRoleStore->getId( SlotRecord::MAIN ),
+ 'content_id=slot_content_id',
+ 'SUBSTRING(content_address, 1, 3)=' . $dbr->addQuotes( 'tt:' ),
+ 'SUBSTRING(content_address, 4)=old_id',
+ ], $conds );
+ }
+
while ( true ) {
- $res = $dbr->select( [ 'revision', 'text' ],
- [ 'rev_id', 'rev_page', 'old_id', 'old_flags', 'old_text' ],
- [
+ $res = $dbr->select( $tables,
+ $fields,
+ array_merge( [
'rev_id > ' . $dbr->addQuotes( $startId ),
- 'rev_text_id=old_id',
- $textClause,
- 'old_flags ' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ),
- ],
+ ], $conds ),
__METHOD__,
- [
- 'ORDER BY' => 'rev_id',
- 'LIMIT' => $this->batchSize
- ]
+ $options
);
if ( !$res->numRows() ) {
break;
$pos = $dbw->getMasterPos();
$dbr->masterPosWait( $pos, 100000 );
- $textClause = $this->getTextClause( $this->clusters );
+ $textClause = $this->getTextClause();
$startId = 0;
$endId = $dbr->selectField( 'text', 'MAX(old_id)', '', __METHOD__ );
$rowsInserted = 0;
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
$lb = $lbFactory->getExternalLB( $cluster );
try {
- $extDB = $lb->getConnection( DB_REPLICA );
+ $extDB = $lb->getMaintenanceConnectionRef( DB_REPLICA );
} catch ( DBConnectionError $e ) {
- if ( strpos( $e->error, 'Unknown database' ) !== false ) {
+ if ( strpos( $e->getMessage(), 'Unknown database' ) !== false ) {
echo "No database on $cluster\n";
} else {
echo "Error on $cluster: " . $e->getMessage() . "\n";
foreach ( $res as $row ) {
gmp_setbit( $actualBlobs, $row->blob_id );
+ $startId = $row->blob_id;
}
- $startId = $row->blob_id;
++$batchesDone;
if ( $batchesDone >= $this->reportingInterval ) {