X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2Fstorage%2FtrackBlobs.php;h=d9793b40bcc2b631875471550d05232226c916b7;hb=69f78bb554ed8d950b3c79690d5a2a07e5c6d6c4;hp=2dd48caf98dfadce99fc9d4cc0e83769fcef47f3;hpb=2dd32981a8326a6207ac866b39410f1b86179288;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/storage/trackBlobs.php b/maintenance/storage/trackBlobs.php index 2dd48caf98..d9793b40bc 100644 --- a/maintenance/storage/trackBlobs.php +++ b/maintenance/storage/trackBlobs.php @@ -23,6 +23,7 @@ */ use MediaWiki\MediaWikiServices; +use MediaWiki\Revision\SlotRecord; use Wikimedia\Rdbms\DBConnectionError; require __DIR__ . '/../commandLine.inc'; @@ -130,6 +131,8 @@ class TrackBlobs { * Scan the revision table for rows stored in the specified clusters */ function trackRevisions() { + global $wgMultiContentRevisionSchemaMigrationStage; + $dbw = wfGetDB( DB_MASTER ); $dbr = wfGetDB( DB_REPLICA ); @@ -141,20 +144,40 @@ class TrackBlobs { 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; @@ -209,7 +232,7 @@ class TrackBlobs { $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; @@ -302,9 +325,9 @@ class TrackBlobs { $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"; @@ -339,8 +362,8 @@ class TrackBlobs { foreach ( $res as $row ) { gmp_setbit( $actualBlobs, $row->blob_id ); + $startId = $row->blob_id; } - $startId = $row->blob_id; ++$batchesDone; if ( $batchesDone >= $this->reportingInterval ) {