X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2Fstorage%2FrecompressTracked.php;h=c5dd53b111f6b2e963d0cde33e435187d08e8dbe;hb=242df680cee7241c01ef8b8e62dac62b1bad4d6d;hp=292a25dc95b9c486aab08762d2eba9d2951e60f9;hpb=c9bef3d160724e84b9c876615cceddffadef73bc;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/storage/recompressTracked.php b/maintenance/storage/recompressTracked.php index 292a25dc95..c5dd53b111 100644 --- a/maintenance/storage/recompressTracked.php +++ b/maintenance/storage/recompressTracked.php @@ -23,6 +23,7 @@ */ use MediaWiki\Logger\LegacyLogger; +use MediaWiki\MediaWikiServices; $optionsWithArgs = RecompressTracked::getOptionsWithArgs(); require __DIR__ . '/../commandLine.inc'; @@ -60,17 +61,17 @@ class RecompressTracked { public $numProcs = 1; public $numBatches = 0; public $pageBlobClass, $orphanBlobClass; - public $slavePipes, $slaveProcs, $prevSlaveId; + public $replicaPipes, $replicaProcs, $prevReplicaId; public $copyOnly = false; public $isChild = false; - public $slaveId = false; + public $replicaId = false; public $noCount = false; public $debugLog, $infoLog, $criticalLog; public $store; private static $optionsWithArgs = [ 'procs', - 'slave-id', + 'replica-id', 'debug-log', 'info-log', 'critical-log' @@ -81,7 +82,7 @@ class RecompressTracked { 'procs' => 'numProcs', 'copy-only' => 'copyOnly', 'child' => 'isChild', - 'slave-id' => 'slaveId', + 'replica-id' => 'replicaId', 'debug-log' => 'debugLog', 'info-log' => 'infoLog', 'critical-log' => 'criticalLog', @@ -109,8 +110,8 @@ class RecompressTracked { $this->store = new ExternalStoreDB; if ( !$this->isChild ) { $GLOBALS['wgDebugLogPrefix'] = "RCT M: "; - } elseif ( $this->slaveId !== false ) { - $GLOBALS['wgDebugLogPrefix'] = "RCT {$this->slaveId}: "; + } elseif ( $this->replicaId !== false ) { + $GLOBALS['wgDebugLogPrefix'] = "RCT {$this->replicaId}: "; } $this->pageBlobClass = function_exists( 'xdiff_string_bdiff' ) ? 'DiffHistoryBlob' : 'ConcatenatedGzipHistoryBlob'; @@ -140,21 +141,21 @@ class RecompressTracked { function logToFile( $msg, $file ) { $header = '[' . date( 'd\TH:i:s' ) . '] ' . wfHostname() . ' ' . posix_getpid(); - if ( $this->slaveId !== false ) { - $header .= "({$this->slaveId})"; + if ( $this->replicaId !== false ) { + $header .= "({$this->replicaId})"; } $header .= ' ' . wfWikiID(); LegacyLogger::emit( sprintf( "%-50s %s\n", $header, $msg ), $file ); } /** - * Wait until the selected slave has caught up to the master. - * This allows us to use the slave for things that were committed in a + * Wait until the selected replica DB has caught up to the master. + * This allows us to use the replica DB for things that were committed in a * previous part of this batch process. */ function syncDBs() { $dbw = wfGetDB( DB_MASTER ); - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $pos = $dbw->getMasterPos(); $dbr->masterPosWait( $pos, 100000 ); } @@ -179,10 +180,10 @@ class RecompressTracked { } $this->syncDBs(); - $this->startSlaveProcs(); + $this->startReplicaProcs(); $this->doAllPages(); $this->doAllOrphans(); - $this->killSlaveProcs(); + $this->killReplicaProcs(); } /** @@ -190,7 +191,7 @@ class RecompressTracked { * @return bool */ function checkTrackingTable() { - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); if ( !$dbr->tableExists( 'blob_tracking' ) ) { $this->critical( "Error: blob_tracking table does not exist" ); @@ -212,10 +213,10 @@ class RecompressTracked { * This necessary because text recompression is slow: loading, compressing and * writing are all slow. */ - function startSlaveProcs() { + function startReplicaProcs() { $cmd = 'php ' . wfEscapeShellArg( __FILE__ ); foreach ( self::$cmdLineOptionMap as $cmdOption => $classOption ) { - if ( $cmdOption == 'slave-id' ) { + if ( $cmdOption == 'replica-id' ) { continue; } elseif ( in_array( $cmdOption, self::$optionsWithArgs ) && isset( $this->$classOption ) ) { $cmd .= " --$cmdOption " . wfEscapeShellArg( $this->$classOption ); @@ -227,7 +228,7 @@ class RecompressTracked { ' --wiki ' . wfEscapeShellArg( wfWikiID() ) . ' ' . call_user_func_array( 'wfEscapeShellArg', $this->destClusters ); - $this->slavePipes = $this->slaveProcs = []; + $this->replicaPipes = $this->replicaProcs = []; for ( $i = 0; $i < $this->numProcs; $i++ ) { $pipes = []; $spec = [ @@ -236,28 +237,28 @@ class RecompressTracked { [ 'file', 'php://stderr', 'w' ] ]; MediaWiki\suppressWarnings(); - $proc = proc_open( "$cmd --slave-id $i", $spec, $pipes ); + $proc = proc_open( "$cmd --replica-id $i", $spec, $pipes ); MediaWiki\restoreWarnings(); if ( !$proc ) { - $this->critical( "Error opening slave process: $cmd" ); + $this->critical( "Error opening replica DB process: $cmd" ); exit( 1 ); } - $this->slaveProcs[$i] = $proc; - $this->slavePipes[$i] = $pipes[0]; + $this->replicaProcs[$i] = $proc; + $this->replicaPipes[$i] = $pipes[0]; } - $this->prevSlaveId = -1; + $this->prevReplicaId = -1; } /** * Gracefully terminate the child processes */ - function killSlaveProcs() { - $this->info( "Waiting for slave processes to finish..." ); + function killReplicaProcs() { + $this->info( "Waiting for replica DB processes to finish..." ); for ( $i = 0; $i < $this->numProcs; $i++ ) { - $this->dispatchToSlave( $i, 'quit' ); + $this->dispatchToReplica( $i, 'quit' ); } for ( $i = 0; $i < $this->numProcs; $i++ ) { - $status = proc_close( $this->slaveProcs[$i] ); + $status = proc_close( $this->replicaProcs[$i] ); if ( $status ) { $this->critical( "Warning: child #$i exited with status $status" ); } @@ -266,22 +267,22 @@ class RecompressTracked { } /** - * Dispatch a command to the next available slave. - * This may block until a slave finishes its work and becomes available. + * Dispatch a command to the next available replica DB. + * This may block until a replica DB finishes its work and becomes available. */ function dispatch( /*...*/ ) { $args = func_get_args(); - $pipes = $this->slavePipes; + $pipes = $this->replicaPipes; $numPipes = stream_select( $x = [], $pipes, $y = [], 3600 ); if ( !$numPipes ) { - $this->critical( "Error waiting to write to slaves. Aborting" ); + $this->critical( "Error waiting to write to replica DBs. Aborting" ); exit( 1 ); } for ( $i = 0; $i < $this->numProcs; $i++ ) { - $slaveId = ( $i + $this->prevSlaveId + 1 ) % $this->numProcs; - if ( isset( $pipes[$slaveId] ) ) { - $this->prevSlaveId = $slaveId; - $this->dispatchToSlave( $slaveId, $args ); + $replicaId = ( $i + $this->prevReplicaId + 1 ) % $this->numProcs; + if ( isset( $pipes[$replicaId] ) ) { + $this->prevReplicaId = $replicaId; + $this->dispatchToReplica( $replicaId, $args ); return; } @@ -291,21 +292,21 @@ class RecompressTracked { } /** - * Dispatch a command to a specified slave - * @param int $slaveId + * Dispatch a command to a specified replica DB + * @param int $replicaId * @param array|string $args */ - function dispatchToSlave( $slaveId, $args ) { + function dispatchToReplica( $replicaId, $args ) { $args = (array)$args; $cmd = implode( ' ', $args ); - fwrite( $this->slavePipes[$slaveId], "$cmd\n" ); + fwrite( $this->replicaPipes[$replicaId], "$cmd\n" ); } /** * Move all tracked pages to the new clusters */ function doAllPages() { - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $i = 0; $startId = 0; if ( $this->noCount ) { @@ -366,7 +367,7 @@ class RecompressTracked { if ( $current == $end || $this->numBatches >= $this->reportingInterval ) { $this->numBatches = 0; $this->info( "$label: $current / $end" ); - wfWaitForSlaves(); + MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->waitForReplication(); } } @@ -374,7 +375,7 @@ class RecompressTracked { * Move all orphan text to the new clusters */ function doAllOrphans() { - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $startId = 0; $i = 0; if ( $this->noCount ) { @@ -464,7 +465,7 @@ class RecompressTracked { case 'quit': return; } - wfWaitForSlaves(); + MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->waitForReplication(); } } @@ -480,7 +481,7 @@ class RecompressTracked { } else { $titleText = '[deleted]'; } - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); // Finish any incomplete transactions if ( !$this->copyOnly ) { @@ -491,6 +492,7 @@ class RecompressTracked { $startId = 0; $trx = new CgzCopyTransaction( $this, $this->pageBlobClass ); + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); while ( true ) { $res = $dbr->select( [ 'blob_tracking', 'text' ], @@ -532,7 +534,7 @@ class RecompressTracked { $this->debug( "$titleText: committing blob with " . $trx->getSize() . " items" ); $trx->commit(); $trx = new CgzCopyTransaction( $this, $this->pageBlobClass ); - wfWaitForSlaves(); + $lbFactory->waitForReplication(); } } } @@ -590,7 +592,8 @@ class RecompressTracked { * @param array $conds */ function finishIncompleteMoves( $conds ) { - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); $startId = 0; $conds = array_merge( $conds, [ @@ -615,7 +618,7 @@ class RecompressTracked { $startId = $row->bt_text_id; $this->moveTextRow( $row->bt_text_id, $row->bt_new_url ); if ( $row->bt_text_id % 10 == 0 ) { - wfWaitForSlaves(); + $lbFactory->waitForReplication(); } } } @@ -637,7 +640,7 @@ class RecompressTracked { /** * Gets a DB master connection for the given external cluster name * @param string $cluster - * @return DatabaseBase + * @return Database */ function getExtDB( $cluster ) { $lb = wfGetLBFactory()->getExternalLB( $cluster ); @@ -659,7 +662,8 @@ class RecompressTracked { $trx = new CgzCopyTransaction( $this, $this->orphanBlobClass ); - $res = wfGetDB( DB_SLAVE )->select( + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $res = wfGetDB( DB_REPLICA )->select( [ 'text', 'blob_tracking' ], [ 'old_id', 'old_text', 'old_flags' ], [ @@ -682,7 +686,7 @@ class RecompressTracked { $this->debug( "[orphan]: committing blob with " . $trx->getSize() . " rows" ); $trx->commit(); $trx = new CgzCopyTransaction( $this, $this->orphanBlobClass ); - wfWaitForSlaves(); + $lbFactory->waitForReplication(); } } $this->debug( "[orphan]: committing blob with " . $trx->getSize() . " rows" ); @@ -762,7 +766,7 @@ class CgzCopyTransaction { /* 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 + * We originally read from the replica DB, 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. *