From c0a9ab0f6d988c25f3e474358a9d90b93f639b6b Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 5 Sep 2016 13:14:41 -0700 Subject: [PATCH] Change "slave" => "replica DB" in /maintenance Change-Id: Ibd3d617901130378a935402326cd4eefbb382c9e --- autoload.php | 2 +- maintenance/Maintenance.php | 4 +- maintenance/fixUserRegistration.php | 2 +- maintenance/generateSitemap.php | 2 +- maintenance/getReplicaServer.php | 55 ++++++++++++++++++++++ maintenance/getSlaveServer.php | 56 +---------------------- maintenance/importImages.php | 4 +- maintenance/initEditCount.php | 4 +- maintenance/populateFilearchiveSha1.php | 2 +- maintenance/resetUserTokens.php | 2 +- maintenance/runBatchedQuery.php | 6 +-- maintenance/showSiteStats.php | 2 +- maintenance/sql.php | 39 ++++++++-------- maintenance/storage/recompressTracked.php | 18 ++++---- maintenance/storage/trackBlobs.php | 2 +- maintenance/updateCollation.php | 4 +- maintenance/updateSpecialPages.php | 4 +- maintenance/userOptions.inc | 4 +- 18 files changed, 108 insertions(+), 104 deletions(-) create mode 100644 maintenance/getReplicaServer.php diff --git a/autoload.php b/autoload.php index 39102fd358..57fae03f72 100644 --- a/autoload.php +++ b/autoload.php @@ -509,7 +509,7 @@ $wgAutoloadLocalClasses = [ 'GenericArrayObject' => __DIR__ . '/includes/libs/GenericArrayObject.php', 'GetConfiguration' => __DIR__ . '/maintenance/getConfiguration.php', 'GetLagTimes' => __DIR__ . '/maintenance/getLagTimes.php', - 'GetSlaveServer' => __DIR__ . '/maintenance/getSlaveServer.php', + 'GetSlaveServer' => __DIR__ . '/maintenance/getReplicaServer.php', 'GetTextMaint' => __DIR__ . '/maintenance/getText.php', 'GitInfo' => __DIR__ . '/includes/GitInfo.php', 'GlobalDependency' => __DIR__ . '/includes/cache/CacheDependency.php', diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index ab316c0632..f42a35cfdc 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -1223,14 +1223,14 @@ abstract class Maintenance { } /** - * Commit the transcation on a DB handle and wait for slaves to catch up + * Commit the transcation on a DB handle and wait for replica DBs to catch up * * This method makes it clear that commit() is called from a maintenance script, * which has outermost scope. This is safe, unlike $dbw->commit() called in other places. * * @param IDatabase $dbw * @param string $fname Caller name - * @return bool Whether the slave wait succeeded + * @return bool Whether the replica DB wait succeeded * @since 1.27 */ protected function commitTransaction( IDatabase $dbw, $fname ) { diff --git a/maintenance/fixUserRegistration.php b/maintenance/fixUserRegistration.php index f4674cb294..37fd44fb2e 100644 --- a/maintenance/fixUserRegistration.php +++ b/maintenance/fixUserRegistration.php @@ -80,7 +80,7 @@ class FixUserRegistration extends Maintenance { $this->output( "Could not find registration for #$id NULL\n" ); } } - $this->output( "Waiting for slaves..." ); + $this->output( "Waiting for replica DBs..." ); wfWaitForSlaves(); $this->output( " done.\n" ); } while ( $res->numRows() >= $this->mBatchSize ); diff --git a/maintenance/generateSitemap.php b/maintenance/generateSitemap.php index f5cc6f6539..ff7ed457ac 100644 --- a/maintenance/generateSitemap.php +++ b/maintenance/generateSitemap.php @@ -113,7 +113,7 @@ class GenerateSitemap extends Maintenance { public $timestamp; /** - * A database slave object + * A database replica DB object * * @var object */ diff --git a/maintenance/getReplicaServer.php b/maintenance/getReplicaServer.php new file mode 100644 index 0000000000..b3e7377372 --- /dev/null +++ b/maintenance/getReplicaServer.php @@ -0,0 +1,55 @@ +addOption( "group", "Query group to check specifically" ); + $this->addDescription( 'Report the hostname of a replica DB server' ); + } + + public function execute() { + global $wgAllDBsAreLocalhost; + if ( $wgAllDBsAreLocalhost ) { + $host = 'localhost'; + } elseif ( $this->hasOption( 'group' ) ) { + $db = $this->getDB( DB_SLAVE, $this->getOption( 'group' ) ); + $host = $db->getServer(); + } else { + $lb = wfGetLB(); + $i = $lb->getReaderIndex(); + $host = $lb->getServerName( $i ); + } + $this->output( "$host\n" ); + } +} + +$maintClass = "GetSlaveServer"; +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/getSlaveServer.php b/maintenance/getSlaveServer.php index 81228cc575..2160928b5e 100644 --- a/maintenance/getSlaveServer.php +++ b/maintenance/getSlaveServer.php @@ -1,55 +1,3 @@ addOption( "group", "Query group to check specifically" ); - $this->addDescription( 'Report the hostname of a slave server' ); - } - - public function execute() { - global $wgAllDBsAreLocalhost; - if ( $wgAllDBsAreLocalhost ) { - $host = 'localhost'; - } elseif ( $this->hasOption( 'group' ) ) { - $db = $this->getDB( DB_SLAVE, $this->getOption( 'group' ) ); - $host = $db->getServer(); - } else { - $lb = wfGetLB(); - $i = $lb->getReaderIndex(); - $host = $lb->getServerName( $i ); - } - $this->output( "$host\n" ); - } -} - -$maintClass = "GetSlaveServer"; -require_once RUN_MAINTENANCE_IF_MAIN; +// B/C alias +require_once ( __DIR__ . '/getReplicaServer.php' ); diff --git a/maintenance/importImages.php b/maintenance/importImages.php index c653a5f06d..ac700ef010 100644 --- a/maintenance/importImages.php +++ b/maintenance/importImages.php @@ -297,8 +297,8 @@ if ( $count > 0 ) { if ( $doProtect ) { # Protect the file - echo "\nWaiting for slaves...\n"; - // Wait for slaves. + echo "\nWaiting for replica DBs...\n"; + // Wait for replica DBs. sleep( 2.0 ); # Why this sleep? wfWaitForSlaves(); diff --git a/maintenance/initEditCount.php b/maintenance/initEditCount.php index 50a40180a5..a19ad9b2cf 100644 --- a/maintenance/initEditCount.php +++ b/maintenance/initEditCount.php @@ -29,8 +29,8 @@ class InitEditCount extends Maintenance { parent::__construct(); $this->addOption( 'quick', 'Force the update to be done in a single query' ); $this->addOption( 'background', 'Force replication-friendly mode; may be inefficient but - avoids locking tables or lagging slaves with large updates; - calculates counts on a slave if possible. + avoids locking tables or lagging replica DBs with large updates; + calculates counts on a replica DB if possible. Background mode will be automatically used if multiple servers are listed in the load balancer, usually indicating a replication environment.' ); diff --git a/maintenance/populateFilearchiveSha1.php b/maintenance/populateFilearchiveSha1.php index 942f3f2b90..7557a42ff4 100644 --- a/maintenance/populateFilearchiveSha1.php +++ b/maintenance/populateFilearchiveSha1.php @@ -91,7 +91,7 @@ class PopulateFilearchiveSha1 extends LoggedUpdateMaintenance { break; } - // print status and let slaves catch up + // print status and let replica DBs catch up $this->output( sprintf( "id %d done (up to %d), %5.3f%% \r", $lastId, $endId, $lastId / $endId * 100 ) ); wfWaitForSlaves(); diff --git a/maintenance/resetUserTokens.php b/maintenance/resetUserTokens.php index 131a569d6c..df3f6d765d 100644 --- a/maintenance/resetUserTokens.php +++ b/maintenance/resetUserTokens.php @@ -67,7 +67,7 @@ class ResetUserTokens extends Maintenance { wfCountDown( 5 ); } - // We list user by user_id from one of the slave database + // We list user by user_id from one of the replica DBs $dbr = $this->getDB( DB_SLAVE ); $where = []; diff --git a/maintenance/runBatchedQuery.php b/maintenance/runBatchedQuery.php index 2feae02eca..a5e7a2fa88 100644 --- a/maintenance/runBatchedQuery.php +++ b/maintenance/runBatchedQuery.php @@ -1,6 +1,6 @@ addDescription( - "Run a query repeatedly until it affects 0 rows, and wait for slaves in between.\n" . + "Run a query repeatedly until it affects 0 rows, and wait for replica DBs in between.\n" . "NOTE: You need to set a LIMIT clause yourself." ); } diff --git a/maintenance/showSiteStats.php b/maintenance/showSiteStats.php index 1d3e43a1e9..205dfdd6ee 100644 --- a/maintenance/showSiteStats.php +++ b/maintenance/showSiteStats.php @@ -52,7 +52,7 @@ class ShowSiteStats extends Maintenance { 'ss_images' => 'Number of images', ]; - // Get cached stats from slave database + // Get cached stats from a replica DB $dbr = $this->getDB( DB_SLAVE ); $stats = $dbr->selectRow( 'site_stats', '*', '', __METHOD__ ); diff --git a/maintenance/sql.php b/maintenance/sql.php index 1aceaced52..bf50f6598a 100644 --- a/maintenance/sql.php +++ b/maintenance/sql.php @@ -34,10 +34,13 @@ class MwSql extends Maintenance { parent::__construct(); $this->addDescription( 'Send SQL queries to a MediaWiki database. ' . 'Takes a file name containing SQL as argument or runs interactively.' ); - $this->addOption( 'query', 'Run a single query instead of running interactively', false, true ); + $this->addOption( 'query', + 'Run a single query instead of running interactively', false, true ); $this->addOption( 'cluster', 'Use an external cluster by name', false, true ); - $this->addOption( 'wikidb', 'The database wiki ID to use if not the current one', false, true ); - $this->addOption( 'slave', 'Use a slave server (either "any" or by name)', false, true ); + $this->addOption( 'wikidb', + 'The database wiki ID to use if not the current one', false, true ); + $this->addOption( 'replicadb', + 'Replica DB server to use instead of the master DB (can be "any")', false, true ); } public function execute() { @@ -50,30 +53,28 @@ class MwSql extends Maintenance { $lb = wfGetLB( $wiki ); } // Figure out which server to use - if ( $this->hasOption( 'slave' ) ) { - $server = $this->getOption( 'slave' ); - if ( $server === 'any' ) { - $index = DB_SLAVE; - } else { - $index = null; - $serverCount = $lb->getServerCount(); - for ( $i = 0; $i < $serverCount; ++$i ) { - if ( $lb->getServerName( $i ) === $server ) { - $index = $i; - break; - } - } - if ( $index === null ) { - $this->error( "No slave server configured with the name '$server'.", 1 ); + $replicaDB = $this->getOption( 'replicadb', $this->getOption( 'slave', '' ) ); + if ( $replicaDB === 'any' ) { + $index = DB_SLAVE; + } elseif ( $replicaDB != '' ) { + $index = null; + $serverCount = $lb->getServerCount(); + for ( $i = 0; $i < $serverCount; ++$i ) { + if ( $lb->getServerName( $i ) === $replicaDB ) { + $index = $i; + break; } } + if ( $index === null ) { + $this->error( "No replica DB server configured with the name '$server'.", 1 ); + } } else { $index = DB_MASTER; } // 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 ) { - $this->error( "The server selected ({$db->getServer()}) is not a slave.", 1 ); + $this->error( "The server selected ({$db->getServer()}) is not a replica DB.", 1 ); } if ( $this->hasArg( 0 ) ) { diff --git a/maintenance/storage/recompressTracked.php b/maintenance/storage/recompressTracked.php index 292a25dc95..8f717dec46 100644 --- a/maintenance/storage/recompressTracked.php +++ b/maintenance/storage/recompressTracked.php @@ -148,8 +148,8 @@ class RecompressTracked { } /** - * 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() { @@ -239,7 +239,7 @@ class RecompressTracked { $proc = proc_open( "$cmd --slave-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; @@ -252,7 +252,7 @@ class RecompressTracked { * Gracefully terminate the child processes */ function killSlaveProcs() { - $this->info( "Waiting for slave processes to finish..." ); + $this->info( "Waiting for replica DB processes to finish..." ); for ( $i = 0; $i < $this->numProcs; $i++ ) { $this->dispatchToSlave( $i, 'quit' ); } @@ -266,15 +266,15 @@ 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; $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++ ) { @@ -291,7 +291,7 @@ class RecompressTracked { } /** - * Dispatch a command to a specified slave + * Dispatch a command to a specified replica DB * @param int $slaveId * @param array|string $args */ @@ -762,7 +762,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. * diff --git a/maintenance/storage/trackBlobs.php b/maintenance/storage/trackBlobs.php index 214f5b1ebd..9da4699a25 100644 --- a/maintenance/storage/trackBlobs.php +++ b/maintenance/storage/trackBlobs.php @@ -219,7 +219,7 @@ class TrackBlobs { * 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 ); $pos = $dbw->getMasterPos(); diff --git a/maintenance/updateCollation.php b/maintenance/updateCollation.php index 922cc87213..6b10498c6b 100644 --- a/maintenance/updateCollation.php +++ b/maintenance/updateCollation.php @@ -34,7 +34,7 @@ require_once __DIR__ . '/Maintenance.php'; */ class UpdateCollation extends Maintenance { const BATCH_SIZE = 100; // Number of rows to process in one batch - const SYNC_INTERVAL = 5; // Wait for slaves after this many batches + const SYNC_INTERVAL = 5; // Wait for replica DBs after this many batches public $sizeHistogram = []; @@ -220,7 +220,7 @@ TEXT $this->output( "$count done.\n" ); if ( !$dryRun && ++$batchCount % self::SYNC_INTERVAL == 0 ) { - $this->output( "Waiting for slaves ... " ); + $this->output( "Waiting for replica DBs ... " ); wfWaitForSlaves(); $this->output( "done\n" ); } diff --git a/maintenance/updateSpecialPages.php b/maintenance/updateSpecialPages.php index 8b24b90cb8..5ea3828214 100644 --- a/maintenance/updateSpecialPages.php +++ b/maintenance/updateSpecialPages.php @@ -109,7 +109,7 @@ class UpdateSpecialPages extends Maintenance { } while ( !wfGetLB()->pingAll() ); $this->output( "Reconnected\n\n" ); } - # Wait for the slave to catch up + # Wait for the replica DB to catch up wfWaitForSlaves(); } else { $this->output( "cheap, skipped\n" ); @@ -153,7 +153,7 @@ class UpdateSpecialPages extends Maintenance { $this->output( $minutes . 'm ' ); } $this->output( sprintf( "%.2fs\n", $seconds ) ); - # Wait for the slave to catch up + # Wait for the replica DB to catch up wfWaitForSlaves(); } } diff --git a/maintenance/userOptions.inc b/maintenance/userOptions.inc index 4b0a817b5b..a09d7ba76f 100644 --- a/maintenance/userOptions.inc +++ b/maintenance/userOptions.inc @@ -140,7 +140,7 @@ class UserOptions { $ret = []; $defaultOptions = User::getDefaultOptions(); - // We list user by user_id from one of the slave database + // We list user by user_id from one of the replica DBs $dbr = wfGetDB( DB_SLAVE ); $result = $dbr->select( 'user', [ 'user_id' ], @@ -194,7 +194,7 @@ class UserOptions { private function CHANGER() { $this->warn(); - // We list user by user_id from one of the slave database + // We list user by user_id from one of the replica DBs $dbr = wfGetDB( DB_SLAVE ); $result = $dbr->select( 'user', [ 'user_id' ], -- 2.20.1