X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=maintenance%2Fstorage%2FrecompressTracked.php;h=2f414dfaede57a961af5bffe78abbdb3989064d3;hb=c340c41b37b5079ba90489f6b212bb8e4642031a;hp=120ccb6cb62430404d29d04cbca414e17a8e15db;hpb=1271bb75c60f98720a24ed1bac13a48f2181fb00;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/storage/recompressTracked.php b/maintenance/storage/recompressTracked.php index 120ccb6cb6..2f414dfaed 100644 --- a/maintenance/storage/recompressTracked.php +++ b/maintenance/storage/recompressTracked.php @@ -58,6 +58,7 @@ class RecompressTracked { public $orphanBatchSize = 1000; public $reportingInterval = 10; public $numProcs = 1; + public $numBatches = 0; public $useDiff, $pageBlobClass, $orphanBlobClass; public $slavePipes, $slaveProcs, $prevSlaveId; public $copyOnly = false; @@ -67,15 +68,15 @@ class RecompressTracked { public $debugLog, $infoLog, $criticalLog; public $store; - private static $optionsWithArgs = array( + private static $optionsWithArgs = [ 'procs', 'slave-id', 'debug-log', 'info-log', 'critical-log' - ); + ]; - private static $cmdLineOptionMap = array( + private static $cmdLineOptionMap = [ 'no-count' => 'noCount', 'procs' => 'numProcs', 'copy-only' => 'copyOnly', @@ -84,14 +85,14 @@ class RecompressTracked { 'debug-log' => 'debugLog', 'info-log' => 'infoLog', 'critical-log' => 'criticalLog', - ); + ]; static function getOptionsWithArgs() { return self::$optionsWithArgs; } static function newFromCommandLine( $args, $options ) { - $jobOptions = array( 'destClusters' => $args ); + $jobOptions = [ 'destClusters' => $args ]; foreach ( self::$cmdLineOptionMap as $cmdOption => $classOption ) { if ( isset( $options[$cmdOption] ) ) { $jobOptions[$classOption] = $options[$cmdOption]; @@ -195,7 +196,7 @@ class RecompressTracked { return false; } - $row = $dbr->selectRow( 'blob_tracking', '*', false, __METHOD__ ); + $row = $dbr->selectRow( 'blob_tracking', '*', '', __METHOD__ ); if ( !$row ) { $this->info( "Warning: blob_tracking table contains no rows, skipping this wiki." ); @@ -226,14 +227,14 @@ class RecompressTracked { ' --wiki ' . wfEscapeShellArg( wfWikiID() ) . ' ' . call_user_func_array( 'wfEscapeShellArg', $this->destClusters ); - $this->slavePipes = $this->slaveProcs = array(); + $this->slavePipes = $this->slaveProcs = []; for ( $i = 0; $i < $this->numProcs; $i++ ) { - $pipes = false; - $spec = array( - array( 'pipe', 'r' ), - array( 'file', 'php://stdout', 'w' ), - array( 'file', 'php://stderr', 'w' ) - ); + $pipes = []; + $spec = [ + [ 'pipe', 'r' ], + [ 'file', 'php://stdout', 'w' ], + [ 'file', 'php://stderr', 'w' ] + ]; MediaWiki\suppressWarnings(); $proc = proc_open( "$cmd --slave-id $i", $spec, $pipes ); MediaWiki\restoreWarnings(); @@ -271,7 +272,7 @@ class RecompressTracked { function dispatch( /*...*/ ) { $args = func_get_args(); $pipes = $this->slavePipes; - $numPipes = stream_select( $x = array(), $pipes, $y = array(), 3600 ); + $numPipes = stream_select( $x = [], $pipes, $y = [], 3600 ); if ( !$numPipes ) { $this->critical( "Error waiting to write to slaves. Aborting" ); exit( 1 ); @@ -313,7 +314,7 @@ class RecompressTracked { $numPages = $dbr->selectField( 'blob_tracking', 'COUNT(DISTINCT bt_page)', # A condition is required so that this query uses the index - array( 'bt_moved' => 0 ), + [ 'bt_moved' => 0 ], __METHOD__ ); } @@ -324,26 +325,26 @@ class RecompressTracked { } while ( true ) { $res = $dbr->select( 'blob_tracking', - array( 'bt_page' ), - array( + [ 'bt_page' ], + [ 'bt_moved' => 0, 'bt_page > ' . $dbr->addQuotes( $startId ) - ), + ], __METHOD__, - array( + [ 'DISTINCT', 'ORDER BY' => 'bt_page', 'LIMIT' => $this->batchSize, - ) + ] ); if ( !$res->numRows() ) { break; } foreach ( $res as $row ) { + $startId = $row->bt_page; $this->dispatch( 'doPage', $row->bt_page ); $i++; } - $startId = $row->bt_page; $this->report( 'pages', $i, $numPages ); } $this->report( 'pages', $i, $numPages ); @@ -381,7 +382,7 @@ class RecompressTracked { } else { $numOrphans = $dbr->selectField( 'blob_tracking', 'COUNT(DISTINCT bt_text_id)', - array( 'bt_moved' => 0, 'bt_page' => 0 ), + [ 'bt_moved' => 0, 'bt_page' => 0 ], __METHOD__ ); if ( !$numOrphans ) { return; @@ -395,24 +396,25 @@ class RecompressTracked { while ( true ) { $res = $dbr->select( 'blob_tracking', - array( 'bt_text_id' ), - array( + [ 'bt_text_id' ], + [ 'bt_moved' => 0, 'bt_page' => 0, 'bt_text_id > ' . $dbr->addQuotes( $startId ) - ), + ], __METHOD__, - array( + [ 'DISTINCT', 'ORDER BY' => 'bt_text_id', 'LIMIT' => $this->batchSize - ) + ] ); if ( !$res->numRows() ) { break; } - $ids = array(); + $ids = []; foreach ( $res as $row ) { + $startId = $row->bt_text_id; $ids[] = $row->bt_text_id; $i++; } @@ -423,15 +425,14 @@ class RecompressTracked { $args = array_slice( $ids, 0, $this->orphanBatchSize ); $ids = array_slice( $ids, $this->orphanBatchSize ); array_unshift( $args, 'doOrphanList' ); - call_user_func_array( array( $this, 'dispatch' ), $args ); + call_user_func_array( [ $this, 'dispatch' ], $args ); } if ( count( $ids ) ) { $args = $ids; array_unshift( $args, 'doOrphanList' ); - call_user_func_array( array( $this, 'dispatch' ), $args ); + call_user_func_array( [ $this, 'dispatch' ], $args ); } - $startId = $row->bt_text_id; $this->report( 'orphans', $i, $numOrphans ); } $this->report( 'orphans', $i, $numOrphans ); @@ -483,7 +484,7 @@ class RecompressTracked { // Finish any incomplete transactions if ( !$this->copyOnly ) { - $this->finishIncompleteMoves( array( 'bt_page' => $pageId ) ); + $this->finishIncompleteMoves( [ 'bt_page' => $pageId ] ); $this->syncDBs(); } @@ -492,20 +493,20 @@ class RecompressTracked { while ( true ) { $res = $dbr->select( - array( 'blob_tracking', 'text' ), + [ 'blob_tracking', 'text' ], '*', - array( + [ 'bt_page' => $pageId, 'bt_text_id > ' . $dbr->addQuotes( $startId ), 'bt_moved' => 0, 'bt_new_url IS NULL', 'bt_text_id=old_id', - ), + ], __METHOD__, - array( + [ 'ORDER BY' => 'bt_text_id', 'LIMIT' => $this->batchSize - ) + ] ); if ( !$res->numRows() ) { break; @@ -513,6 +514,7 @@ class RecompressTracked { $lastTextId = 0; foreach ( $res as $row ) { + $startId = $row->bt_text_id; if ( $lastTextId == $row->bt_text_id ) { // Duplicate (null edit) continue; @@ -533,7 +535,6 @@ class RecompressTracked { wfWaitForSlaves(); } } - $startId = $row->bt_text_id; } $this->debug( "$titleText: committing blob with " . $trx->getSize() . " items" ); @@ -561,18 +562,18 @@ class RecompressTracked { $dbw = wfGetDB( DB_MASTER ); $dbw->begin( __METHOD__ ); $dbw->update( 'text', - array( // set + [ // set 'old_text' => $url, 'old_flags' => 'external,utf-8', - ), - array( // where + ], + [ // where 'old_id' => $textId - ), + ], __METHOD__ ); $dbw->update( 'blob_tracking', - array( 'bt_moved' => 1 ), - array( 'bt_text_id' => $textId ), + [ 'bt_moved' => 1 ], + [ 'bt_text_id' => $textId ], __METHOD__ ); $dbw->commit( __METHOD__ ); @@ -592,31 +593,31 @@ class RecompressTracked { $dbr = wfGetDB( DB_SLAVE ); $startId = 0; - $conds = array_merge( $conds, array( + $conds = array_merge( $conds, [ 'bt_moved' => 0, 'bt_new_url IS NOT NULL' - ) ); + ] ); while ( true ) { $res = $dbr->select( 'blob_tracking', '*', - array_merge( $conds, array( 'bt_text_id > ' . $dbr->addQuotes( $startId ) ) ), + array_merge( $conds, [ 'bt_text_id > ' . $dbr->addQuotes( $startId ) ] ), __METHOD__, - array( + [ 'ORDER BY' => 'bt_text_id', 'LIMIT' => $this->batchSize, - ) + ] ); if ( !$res->numRows() ) { break; } $this->debug( 'Incomplete: ' . $res->numRows() . ' rows' ); foreach ( $res as $row ) { + $startId = $row->bt_text_id; $this->moveTextRow( $row->bt_text_id, $row->bt_new_url ); if ( $row->bt_text_id % 10 == 0 ) { wfWaitForSlaves(); } } - $startId = $row->bt_text_id; } } @@ -652,22 +653,22 @@ class RecompressTracked { function doOrphanList( $textIds ) { // Finish incomplete moves if ( !$this->copyOnly ) { - $this->finishIncompleteMoves( array( 'bt_text_id' => $textIds ) ); + $this->finishIncompleteMoves( [ 'bt_text_id' => $textIds ] ); $this->syncDBs(); } $trx = new CgzCopyTransaction( $this, $this->orphanBlobClass ); $res = wfGetDB( DB_SLAVE )->select( - array( 'text', 'blob_tracking' ), - array( 'old_id', 'old_text', 'old_flags' ), - array( + [ 'text', 'blob_tracking' ], + [ 'old_id', 'old_text', 'old_flags' ], + [ 'old_id' => $textIds, 'bt_text_id=old_id', 'bt_moved' => 0, - ), + ], __METHOD__, - array( 'DISTINCT' ) + [ 'DISTINCT' ] ); foreach ( $res as $row ) { @@ -693,8 +694,10 @@ class RecompressTracked { * Class to represent a recompression operation for a single CGZ blob */ class CgzCopyTransaction { + /** @var RecompressTracked */ public $parent; public $blobClass; + /** @var ConcatenatedGzipHistoryBlob */ public $cgz; public $referrers; @@ -706,7 +709,7 @@ class CgzCopyTransaction { function __construct( $parent, $blobClass ) { $this->blobClass = $blobClass; $this->cgz = false; - $this->texts = array(); + $this->texts = []; $this->parent = $parent; } @@ -739,7 +742,7 @@ class CgzCopyTransaction { function recompress() { $class = $this->blobClass; $this->cgz = new $class; - $this->referrers = array(); + $this->referrers = []; foreach ( $this->texts as $textId => $text ) { $hash = $this->cgz->addItem( $text ); $this->referrers[$textId] = $hash; @@ -757,19 +760,20 @@ class CgzCopyTransaction { return; } - // Check to see if the target text_ids have been moved already. - // - // We originally read from the slave, so this can happen when a single - // text_id is shared between multiple pages. It's rare, but possible - // if a delete/move/undelete cycle splits up a null edit. - // - // We do a locking read to prevent closer-run race conditions. + /* Check to see if the target text_ids have been moved already. + * + * We originally read from the slave, so this can happen when a single + * text_id is shared between multiple pages. It's rare, but possible + * if a delete/move/undelete cycle splits up a null edit. + * + * We do a locking read to prevent closer-run race conditions. + */ $dbw = wfGetDB( DB_MASTER ); $dbw->begin( __METHOD__ ); $res = $dbw->select( 'blob_tracking', - array( 'bt_text_id', 'bt_moved' ), - array( 'bt_text_id' => array_keys( $this->referrers ) ), - __METHOD__, array( 'FOR UPDATE' ) ); + [ 'bt_text_id', 'bt_moved' ], + [ 'bt_text_id' => array_keys( $this->referrers ) ], + __METHOD__, [ 'FOR UPDATE' ] ); $dirty = false; foreach ( $res as $row ) { if ( $row->bt_moved ) { @@ -786,7 +790,8 @@ class CgzCopyTransaction { // All have been moved already if ( $originalCount > 1 ) { // This is suspcious, make noise - $this->critical( "Warning: concurrent operation detected, are there two conflicting " . + $this->parent->critical( + "Warning: concurrent operation detected, are there two conflicting " . "processes running, doing the same job?" ); } @@ -807,11 +812,11 @@ class CgzCopyTransaction { foreach ( $this->referrers as $textId => $hash ) { $url = $baseUrl . '/' . $hash; $dbw->update( 'blob_tracking', - array( 'bt_new_url' => $url ), - array( + [ 'bt_new_url' => $url ], + [ 'bt_text_id' => $textId, 'bt_moved' => 0, # Check for concurrent conflicting update - ), + ], __METHOD__ ); }