From: Aaron Schulz Date: Tue, 6 Sep 2016 01:30:36 +0000 (-0700) Subject: More replication var cleanups in /maintenance X-Git-Tag: 1.31.0-rc.0~5755 X-Git-Url: https://git.heureux-cyclage.org/?a=commitdiff_plain;h=3d5016569da984050ec105e9d49aece069aebaa4;p=lhc%2Fweb%2Fwiklou.git More replication var cleanups in /maintenance * Fix option check in sql.php * Rename RecompressTracked vars and avoid deprecated method calls Change-Id: Ie04f6e841d68d69c9243a185de1bd13a612b2070 --- diff --git a/maintenance/sql.php b/maintenance/sql.php index 60e6956095..e6a30a38fe 100644 --- a/maintenance/sql.php +++ b/maintenance/sql.php @@ -73,7 +73,7 @@ class MwSql extends Maintenance { } // Get a DB handle (with this wiki's DB selected) from the appropriate load balancer $db = $lb->getConnection( $index, [], $wiki ); - if ( $this->hasOption( 'slave' ) && $db->getLBInfo( 'master' ) !== null ) { + if ( $replicaDB != '' && $db->getLBInfo( 'master' ) !== null ) { $this->error( "The server selected ({$db->getServer()}) is not a replica DB.", 1 ); } diff --git a/maintenance/storage/recompressTracked.php b/maintenance/storage/recompressTracked.php index 0a62103ca7..a0efcb8f66 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,8 +141,8 @@ 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 ); @@ -179,10 +180,10 @@ class RecompressTracked { } $this->syncDBs(); - $this->startSlaveProcs(); + $this->startReplicaProcs(); $this->doAllPages(); $this->doAllOrphans(); - $this->killSlaveProcs(); + $this->killReplicaProcs(); } /** @@ -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 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() { + 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" ); } @@ -271,17 +272,17 @@ class RecompressTracked { */ 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 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; } @@ -292,13 +293,13 @@ class RecompressTracked { /** * Dispatch a command to a specified replica DB - * @param int $slaveId + * @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" ); } /** @@ -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(); } } @@ -464,7 +465,7 @@ class RecompressTracked { case 'quit': return; } - wfWaitForSlaves(); + MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->waitForReplication(); } } @@ -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(); } } } @@ -591,6 +593,7 @@ class RecompressTracked { */ function finishIncompleteMoves( $conds ) { $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(); } } } @@ -659,6 +662,7 @@ class RecompressTracked { $trx = new CgzCopyTransaction( $this, $this->orphanBlobClass ); + $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" );