class TrackBlobs {
public $clusters, $textClause;
public $doBlobOrphans;
- public $trackedBlobs = array();
+ public $trackedBlobs = [];
public $batchSize = 1000;
public $reportingInterval = 10;
function checkIntegrity() {
echo "Doing integrity check...\n";
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = wfGetDB( DB_REPLICA );
- // Scan for HistoryBlobStub objects in the text table (bug 20757)
+ // Scan for HistoryBlobStub objects in the text table (T22757)
$exists = $dbr->selectField( 'text', 1,
'old_flags LIKE \'%object%\' AND old_flags NOT LIKE \'%external%\' ' .
exit( 1 );
}
- // Scan the archive table for HistoryBlobStub objects or external flags (bug 22624)
+ // Scan the archive table for HistoryBlobStub objects or external flags (T24624)
$flags = $dbr->selectField( 'archive', 'ar_flags',
'ar_flags LIKE \'%external%\' OR (' .
'ar_flags LIKE \'%object%\' ' .
function getTextClause() {
if ( !$this->textClause ) {
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = wfGetDB( DB_REPLICA );
$this->textClause = '';
foreach ( $this->clusters as $cluster ) {
if ( $this->textClause != '' ) {
return false;
}
- return array(
+ return [
'cluster' => $m[1],
'id' => intval( $m[2] ),
'hash' => isset( $m[3] ) ? $m[3] : null
- );
+ ];
}
/**
*/
function trackRevisions() {
$dbw = wfGetDB( DB_MASTER );
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = wfGetDB( DB_REPLICA );
$textClause = $this->getTextClause();
$startId = 0;
echo "Finding revisions...\n";
while ( true ) {
- $res = $dbr->select( array( 'revision', 'text' ),
- array( 'rev_id', 'rev_page', 'old_id', 'old_flags', 'old_text' ),
- array(
+ $res = $dbr->select( [ 'revision', 'text' ],
+ [ 'rev_id', 'rev_page', 'old_id', 'old_flags', 'old_text' ],
+ [
'rev_id > ' . $dbr->addQuotes( $startId ),
'rev_text_id=old_id',
$textClause,
'old_flags ' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ),
- ),
+ ],
__METHOD__,
- array(
+ [
'ORDER BY' => 'rev_id',
'LIMIT' => $this->batchSize
- )
+ ]
);
if ( !$res->numRows() ) {
break;
}
- $insertBatch = array();
+ $insertBatch = [];
foreach ( $res as $row ) {
$startId = $row->rev_id;
$info = $this->interpretPointer( $row->old_text );
echo "Invalid cluster returned in SQL query: {$info['cluster']}\n";
continue;
}
- $insertBatch[] = array(
+ $insertBatch[] = [
'bt_page' => $row->rev_page,
'bt_rev_id' => $row->rev_id,
'bt_text_id' => $row->old_id,
'bt_cluster' => $info['cluster'],
'bt_blob_id' => $info['id'],
'bt_cgz_hash' => $info['hash']
- );
+ ];
if ( $this->doBlobOrphans ) {
gmp_setbit( $this->trackedBlobs[$info['cluster']], $info['id'] );
}
* archive table counts as orphan for our purposes.
*/
function trackOrphanText() {
- # Wait until the blob_tracking table is available in the slave
+ # Wait until the blob_tracking table is available in the replica DB
$dbw = wfGetDB( DB_MASTER );
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = wfGetDB( DB_REPLICA );
$pos = $dbw->getMasterPos();
$dbr->masterPosWait( $pos, 100000 );
# Scan the text table for orphan text
while ( true ) {
- $res = $dbr->select( array( 'text', 'blob_tracking' ),
- array( 'old_id', 'old_flags', 'old_text' ),
- array(
+ $res = $dbr->select( [ 'text', 'blob_tracking' ],
+ [ 'old_id', 'old_flags', 'old_text' ],
+ [
'old_id>' . $dbr->addQuotes( $startId ),
$textClause,
'old_flags ' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ),
'bt_text_id IS NULL'
- ),
+ ],
__METHOD__,
- array(
+ [
'ORDER BY' => 'old_id',
'LIMIT' => $this->batchSize
- ),
- array( 'blob_tracking' => array( 'LEFT JOIN', 'bt_text_id=old_id' ) )
+ ],
+ [ 'blob_tracking' => [ 'LEFT JOIN', 'bt_text_id=old_id' ] ]
);
- $ids = array();
+ $ids = [];
foreach ( $res as $row ) {
$ids[] = $row->old_id;
}
break;
}
- $insertBatch = array();
+ $insertBatch = [];
foreach ( $res as $row ) {
$startId = $row->old_id;
$info = $this->interpretPointer( $row->old_text );
continue;
}
- $insertBatch[] = array(
+ $insertBatch[] = [
'bt_page' => 0,
'bt_rev_id' => 0,
'bt_text_id' => $row->old_id,
'bt_cluster' => $info['cluster'],
'bt_blob_id' => $info['id'],
'bt_cgz_hash' => $info['hash']
- );
+ ];
if ( $this->doBlobOrphans ) {
gmp_setbit( $this->trackedBlobs[$info['cluster']], $info['id'] );
}
echo "Searching for orphan blobs in $cluster...\n";
$lb = wfGetLBFactory()->getExternalLB( $cluster );
try {
- $extDB = $lb->getConnection( DB_SLAVE );
+ $extDB = $lb->getConnection( DB_REPLICA );
} catch ( DBConnectionError $e ) {
if ( strpos( $e->error, 'Unknown database' ) !== false ) {
echo "No database on $cluster\n";
// Build a bitmap of actual blob rows
while ( true ) {
$res = $extDB->select( $table,
- array( 'blob_id' ),
- array( 'blob_id > ' . $extDB->addQuotes( $startId ) ),
+ [ 'blob_id' ],
+ [ 'blob_id > ' . $extDB->addQuotes( $startId ) ],
__METHOD__,
- array( 'LIMIT' => $this->batchSize, 'ORDER BY' => 'blob_id' )
+ [ 'LIMIT' => $this->batchSize, 'ORDER BY' => 'blob_id' ]
);
if ( !$res->numRows() ) {
$orphans = gmp_and( $actualBlobs, gmp_com( $this->trackedBlobs[$cluster] ) );
// Traverse the orphan list
- $insertBatch = array();
+ $insertBatch = [];
$id = 0;
$numOrphans = 0;
while ( true ) {
if ( $id == -1 ) {
break;
}
- $insertBatch[] = array(
+ $insertBatch[] = [
'bo_cluster' => $cluster,
'bo_blob_id' => $id
- );
+ ];
if ( count( $insertBatch ) > $this->batchSize ) {
$dbw->insert( 'blob_orphans', $insertBatch, __METHOD__ );
- $insertBatch = array();
+ $insertBatch = [];
}
++$id;