Change "slave" => "replica DB" in /maintenance
authorAaron Schulz <aschulz@wikimedia.org>
Mon, 5 Sep 2016 20:14:41 +0000 (13:14 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 6 Sep 2016 00:13:08 +0000 (00:13 +0000)
Change-Id: Ibd3d617901130378a935402326cd4eefbb382c9e

18 files changed:
autoload.php
maintenance/Maintenance.php
maintenance/fixUserRegistration.php
maintenance/generateSitemap.php
maintenance/getReplicaServer.php [new file with mode: 0644]
maintenance/getSlaveServer.php
maintenance/importImages.php
maintenance/initEditCount.php
maintenance/populateFilearchiveSha1.php
maintenance/resetUserTokens.php
maintenance/runBatchedQuery.php
maintenance/showSiteStats.php
maintenance/sql.php
maintenance/storage/recompressTracked.php
maintenance/storage/trackBlobs.php
maintenance/updateCollation.php
maintenance/updateSpecialPages.php
maintenance/userOptions.inc

index 39102fd..57fae03 100644 (file)
@@ -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',
index ab316c0..f42a35c 100644 (file)
@@ -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 ) {
index f4674cb..37fd44f 100644 (file)
@@ -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 );
index f5cc6f6..ff7ed45 100644 (file)
@@ -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 (file)
index 0000000..b3e7377
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+/**
+ * Reports the hostname of a replica DB server.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Maintenance
+ */
+
+require_once __DIR__ . '/Maintenance.php';
+
+/**
+ * Maintenance script that reports the hostname of a replica DB server.
+ *
+ * @ingroup Maintenance
+ */
+class GetSlaveServer extends Maintenance {
+       public function __construct() {
+               parent::__construct();
+               $this->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;
index 81228cc..2160928 100644 (file)
@@ -1,55 +1,3 @@
 <?php
-/**
- * Reports the hostname of a slave server.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- * @ingroup Maintenance
- */
-
-require_once __DIR__ . '/Maintenance.php';
-
-/**
- * Maintenance script that reports the hostname of a slave server.
- *
- * @ingroup Maintenance
- */
-class GetSlaveServer extends Maintenance {
-       public function __construct() {
-               parent::__construct();
-               $this->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' );
index c653a5f..ac700ef 100644 (file)
@@ -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();
 
index 50a4018..a19ad9b 100644 (file)
@@ -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.' );
index 942f3f2..7557a42 100644 (file)
@@ -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();
index 131a569..df3f6d7 100644 (file)
@@ -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 = [];
index 2feae02..a5e7a2f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Run a database query in batches and wait for slaves. This is used on large
+ * Run a database query in batches and wait for replica DBs. This is used on large
  * wikis to prevent replication lag from going through the roof when executing
  * large write queries.
  *
@@ -26,7 +26,7 @@
 require_once __DIR__ . '/Maintenance.php';
 
 /**
- * Maintenance script to run a database query in batches and wait for slaves.
+ * Maintenance script to run a database query in batches and wait for replica DBs.
  *
  * @ingroup Maintenance
  */
@@ -34,7 +34,7 @@ class BatchedQueryRunner extends Maintenance {
        public function __construct() {
                parent::__construct();
                $this->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." );
        }
 
index 1d3e43a..205dfdd 100644 (file)
@@ -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__ );
 
index 1aceace..bf50f65 100644 (file)
@@ -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 ) ) {
index 292a25d..8f717de 100644 (file)
@@ -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.
                 *
index 214f5b1..9da4699 100644 (file)
@@ -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();
index 922cc87..6b10498 100644 (file)
@@ -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" );
                        }
index 8b24b90..5ea3828 100644 (file)
@@ -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();
                        }
                }
index 4b0a817..a09d7ba 100644 (file)
@@ -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' ],