From 8acdb8d0c2cf8520de3329efb5970f96e130acfc Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 3 Sep 2016 07:13:47 -0700 Subject: [PATCH] Make replication DB-related comments/messages more uniform Change-Id: If04254aad085c05d2a6b6588b4c9b55a1736110d --- includes/db/ChronologyProtector.php | 4 +- includes/db/Database.php | 6 +-- includes/db/DatabaseMysqlBase.php | 8 +-- includes/db/DatabaseUtility.php | 2 +- includes/db/IDatabase.php | 12 ++--- includes/db/loadbalancer/LBFactory.php | 14 ++--- includes/db/loadbalancer/LoadBalancer.php | 64 +++++++++++------------ 7 files changed, 55 insertions(+), 55 deletions(-) diff --git a/includes/db/ChronologyProtector.php b/includes/db/ChronologyProtector.php index 2539b87f72..b4619f3004 100644 --- a/includes/db/ChronologyProtector.php +++ b/includes/db/ChronologyProtector.php @@ -79,9 +79,9 @@ class ChronologyProtector { * Initialise a LoadBalancer to give it appropriate chronology protection. * * If the stash has a previous master position recorded, this will try to - * make sure that the next query to a slave of that master will see changes up + * make sure that the next query to a replica DB of that master will see changes up * to that position by delaying execution. The delay may timeout and allow stale - * data if no non-lagged slaves are available. + * data if no non-lagged replica DBs are available. * * @param LoadBalancer $lb * @return void diff --git a/includes/db/Database.php b/includes/db/Database.php index 0a660d9478..5b0f2303d5 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -2908,7 +2908,7 @@ abstract class DatabaseBase implements IDatabase { $this->mTrxWriteAdjQueryCount = 0; $this->mTrxWriteCallers = []; // First SELECT after BEGIN will establish the snapshot in REPEATABLE-READ. - // Get an estimate of the slave lag before then, treating estimate staleness + // Get an estimate of the replica DB lag before then, treating estimate staleness // as lag itself just to be safe $status = $this->getApproximateLagStatus(); $this->mTrxSlaveLag = $status['lag'] + ( microtime( true ) - $status['since'] ); @@ -3194,7 +3194,7 @@ abstract class DatabaseBase implements IDatabase { } /** - * Get the slave lag when the current transaction started + * Get the replica DB lag when the current transaction started * * This is useful when transactions might use snapshot isolation * (e.g. REPEATABLE-READ in innodb), so the "real" lag of that data @@ -3211,7 +3211,7 @@ abstract class DatabaseBase implements IDatabase { } /** - * Get a slave lag estimate for this server + * Get a replica DB lag estimate for this server * * @return array ('lag': seconds or false on error, 'since': UNIX timestamp of estimate) * @since 1.27 diff --git a/includes/db/DatabaseMysqlBase.php b/includes/db/DatabaseMysqlBase.php index 93814d206b..3c383e3dd2 100644 --- a/includes/db/DatabaseMysqlBase.php +++ b/includes/db/DatabaseMysqlBase.php @@ -32,9 +32,9 @@ abstract class DatabaseMysqlBase extends Database { /** @var MysqlMasterPos */ protected $lastKnownSlavePos; - /** @var string Method to detect slave lag */ + /** @var string Method to detect replica DB lag */ protected $lagDetectionMethod; - /** @var array Method to detect slave lag */ + /** @var array Method to detect replica DB lag */ protected $lagDetectionOptions = []; /** @var bool bool Whether to use GTID methods */ protected $useGTIDs = false; @@ -695,7 +695,7 @@ abstract class DatabaseMysqlBase extends Database { $key = $cache->makeGlobalKey( 'mysql', 'master-info', - // Using one key for all cluster slaves is preferable + // Using one key for all cluster replica DBs is preferable $this->getLBInfo( 'clusterMasterHost' ) ?: $this->getServer() ); @@ -797,7 +797,7 @@ abstract class DatabaseMysqlBase extends Database { if ( $status === null ) { // T126436: jobs programmed to wait on master positions might be referencing binlogs // with an old master hostname. Such calls make MASTER_POS_WAIT() return null. Try - // to detect this and treat the slave as having reached the position; a proper master + // to detect this and treat the replica DB as having reached the position; a proper master // switchover already requires that the new master be caught up before the switch. $slavePos = $this->getSlavePos(); if ( $slavePos && !$slavePos->channelsMatch( $pos ) ) { diff --git a/includes/db/DatabaseUtility.php b/includes/db/DatabaseUtility.php index b6c37ee7b6..aeaa27f50c 100644 --- a/includes/db/DatabaseUtility.php +++ b/includes/db/DatabaseUtility.php @@ -314,7 +314,7 @@ class LikeMatch { } /** - * An object representing a master or slave position in a replicated setup. + * An object representing a master or replica DB position in a replicated setup. * * The implementation details of this opaque type are up to the database subclass. */ diff --git a/includes/db/IDatabase.php b/includes/db/IDatabase.php index 5f543c3e7d..fa24144be6 100644 --- a/includes/db/IDatabase.php +++ b/includes/db/IDatabase.php @@ -1235,20 +1235,20 @@ interface IDatabase { public function wasReadOnlyError(); /** - * Wait for the slave to catch up to a given master position + * Wait for the replica DB to catch up to a given master position * * @param DBMasterPos $pos * @param int $timeout The maximum number of seconds to wait for synchronisation - * @return int|null Zero if the slave was past that position already, + * @return int|null Zero if the replica DB was past that position already, * greater than zero if we waited for some period of time, less than * zero if it timed out, and null on error */ public function masterPosWait( DBMasterPos $pos, $timeout ); /** - * Get the replication position of this slave + * Get the replication position of this replica DB * - * @return DBMasterPos|bool False if this is not a slave. + * @return DBMasterPos|bool False if this is not a replica DB. */ public function getSlavePos(); @@ -1515,7 +1515,7 @@ interface IDatabase { public function ping( &$rtt = null ); /** - * Get slave lag. Currently supported only by MySQL. + * Get replica DB lag. Currently supported only by MySQL. * * Note that this function will generate a fatal error on many * installations. Most callers should use LoadBalancer::safeGetLag() @@ -1526,7 +1526,7 @@ interface IDatabase { public function getLag(); /** - * Get the slave lag when the current transaction started + * Get the replica DB lag when the current transaction started * or a general lag estimate if not transaction is active * * This is useful when transactions might use snapshot isolation diff --git a/includes/db/loadbalancer/LBFactory.php b/includes/db/loadbalancer/LBFactory.php index 6b5161b0b1..9f8f919dd4 100644 --- a/includes/db/loadbalancer/LBFactory.php +++ b/includes/db/loadbalancer/LBFactory.php @@ -261,7 +261,7 @@ abstract class LBFactory implements DestructibleService { /** * Commit on all connections. Done for two reasons: * 1. To commit changes to the masters. - * 2. To release the snapshot on all connections, master and slave. + * 2. To release the snapshot on all connections, master and replica DB. * @param string $fname Caller name * @param array $options Options map: * - maxWriteDuration: abort if more than this much time was spent in write queries @@ -356,7 +356,7 @@ abstract class LBFactory implements DestructibleService { } /** - * Detemine if any lagged slave connection was used + * Detemine if any lagged replica DB connection was used * @since 1.27 * @return bool */ @@ -383,10 +383,10 @@ abstract class LBFactory implements DestructibleService { } /** - * Waits for the slave DBs to catch up to the current master position + * Waits for the replica DBs to catch up to the current master position * * Use this when updating very large numbers of rows, as in maintenance scripts, - * to avoid causing too much lag. Of course, this is a no-op if there are no slaves. + * to avoid causing too much lag. Of course, this is a no-op if there are no replica DBs. * * By default this waits on all DB clusters actually used in this request. * This makes sense when lag being waiting on is caused by the code that does this check. @@ -440,7 +440,7 @@ abstract class LBFactory implements DestructibleService { $masterPositions = array_fill( 0, count( $lbs ), false ); foreach ( $lbs as $i => $lb ) { if ( $lb->getServerCount() <= 1 ) { - // Bug 27975 - Don't try to wait for slaves if there are none + // Bug 27975 - Don't try to wait for replica DBs if there are none // Prevents permission error when getting master position continue; } elseif ( $opts['ifWritesSince'] @@ -464,7 +464,7 @@ abstract class LBFactory implements DestructibleService { if ( $failed ) { throw new DBReplicationWaitError( - "Could not wait for slaves to catch up to " . + "Could not wait for replica DBs to catch up to " . implode( ', ', $failed ) ); } @@ -570,7 +570,7 @@ abstract class LBFactory implements DestructibleService { // Write them to the stash $unsavedPositions = $cp->shutdown(); // If the positions failed to write to the stash, at least wait on local datacenter - // slaves to catch up before responding. Even if there are several DCs, this increases + // replica DBs to catch up before responding. Even if there are several DCs, this increases // the chance that the user will see their own changes immediately afterwards. As long // as the sticky DC cookie applies (same domain), this is not even an issue. $this->forEachLB( function ( LoadBalancer $lb ) use ( $unsavedPositions ) { diff --git a/includes/db/loadbalancer/LoadBalancer.php b/includes/db/loadbalancer/LoadBalancer.php index 8db1085568..36df46607d 100644 --- a/includes/db/loadbalancer/LoadBalancer.php +++ b/includes/db/loadbalancer/LoadBalancer.php @@ -36,9 +36,9 @@ class LoadBalancer { private $mLoads; /** @var array[] Map of (group => server index => weight) */ private $mGroupLoads; - /** @var bool Whether to disregard slave lag as a factor in slave selection */ + /** @var bool Whether to disregard replica DB lag as a factor in replica DB selection */ private $mAllowLagged; - /** @var integer Seconds to spend waiting on slave lag to resolve */ + /** @var integer Seconds to spend waiting on replica DB lag to resolve */ private $mWaitTimeout; /** @var array LBFactory information */ private $mParentInfo; @@ -56,13 +56,13 @@ class LoadBalancer { /** @var bool|DatabaseBase Database connection that caused a problem */ private $mErrorConnection; - /** @var integer The generic (not query grouped) slave index (of $mServers) */ + /** @var integer The generic (not query grouped) replica DB index (of $mServers) */ private $mReadIndex; /** @var bool|DBMasterPos False if not set */ private $mWaitForPos; - /** @var bool Whether the generic reader fell back to a lagged slave */ + /** @var bool Whether the generic reader fell back to a lagged replica DB */ private $laggedSlaveMode = false; - /** @var bool Whether the generic reader fell back to a lagged slave */ + /** @var bool Whether the generic reader fell back to a lagged replica DB */ private $slavesDownMode = false; /** @var string The last DB selection or connection error */ private $mLastError = 'Unknown error'; @@ -79,7 +79,7 @@ class LoadBalancer { const CONN_HELD_WARN_THRESHOLD = 10; /** @var integer Default 'max lag' when unspecified */ const MAX_LAG = 10; - /** @var integer Max time to wait for a slave to catch up (e.g. ChronologyProtector) */ + /** @var integer Max time to wait for a replica DB to catch up (e.g. ChronologyProtector) */ const POS_WAIT_TIMEOUT = 10; /** @var integer Seconds to cache master server read-only status */ const TTL_CACHE_READONLY = 5; @@ -211,16 +211,16 @@ class LoadBalancer { } } - # Find out if all the slaves with non-zero load are lagged + # Find out if all the replica DBs with non-zero load are lagged $sum = 0; foreach ( $loads as $load ) { $sum += $load; } if ( $sum == 0 ) { - # No appropriate DB servers except maybe the master and some slaves with zero load + # No appropriate DB servers except maybe the master and some replica DBs with zero load # Do NOT use the master # Instead, this function will return false, triggering read-only mode, - # and a lagged slave will be used instead. + # and a lagged replica DB will be used instead. return false; } @@ -233,7 +233,7 @@ class LoadBalancer { } /** - * Get the index of the reader connection, which may be a slave + * Get the index of the reader connection, which may be a replica DB * This takes into account load ratios and lag times. It should * always return a consistent index during a given invocation * @@ -306,8 +306,8 @@ class LoadBalancer { $i = $this->getRandomNonLagged( $currentLoads, $wiki ); } if ( $i === false && count( $currentLoads ) != 0 ) { - # All slaves lagged. Switch to read-only mode - wfDebugLog( 'replication', "All slaves lagged. Switch to read-only mode" ); + # All replica DBs lagged. Switch to read-only mode + wfDebugLog( 'replication', "All replica DBs lagged. Switch to read-only mode" ); $i = ArrayUtils::pickRandom( $currentLoads ); $laggedSlaveMode = true; } @@ -350,7 +350,7 @@ class LoadBalancer { } if ( $i !== false ) { - # Slave connection successful + # replica DB connection successful # Wait for the session master pos for a short time if ( $this->mWaitForPos && $i > 0 ) { if ( !$this->doWait( $i ) ) { @@ -359,7 +359,7 @@ class LoadBalancer { } if ( $this->mReadIndex <= 0 && $this->mLoads[$i] > 0 && $group === false ) { $this->mReadIndex = $i; - # Record if the generic reader index is in "lagged slave" mode + # Record if the generic reader index is in "lagged replica DB" mode if ( $laggedSlaveMode ) { $this->laggedSlaveMode = true; } @@ -391,7 +391,7 @@ class LoadBalancer { } /** - * Set the master wait position and wait for a "generic" slave to catch up to it + * Set the master wait position and wait for a "generic" replica DB to catch up to it * * This can be used a faster proxy for waitForAll() * @@ -405,9 +405,9 @@ class LoadBalancer { $i = $this->mReadIndex; if ( $i <= 0 ) { - // Pick a generic slave if there isn't one yet + // Pick a generic replica DB if there isn't one yet $readLoads = $this->mLoads; - unset( $readLoads[$this->getWriterIndex()] ); // slaves only + unset( $readLoads[$this->getWriterIndex()] ); // replica DBs only $readLoads = array_filter( $readLoads ); // with non-zero load $i = ArrayUtils::pickRandom( $readLoads ); } @@ -422,7 +422,7 @@ class LoadBalancer { } /** - * Set the master wait position and wait for ALL slaves to catch up to it + * Set the master wait position and wait for ALL replica DBs to catch up to it * @param DBMasterPos $pos * @param int $timeout Max seconds to wait; default is mWaitTimeout * @return bool Success (able to connect and no timeouts reached) @@ -459,7 +459,7 @@ class LoadBalancer { } /** - * Wait for a given slave to catch up to the master pos stored in $this + * Wait for a given replica DB to catch up to the master pos stored in $this * @param int $index Server index * @param bool $open Check the server even if a new connection has to be made * @param int $timeout Max seconds to wait; default is mWaitTimeout @@ -475,7 +475,7 @@ class LoadBalancer { $knownReachedPos = $this->srvCache->get( $key ); if ( $knownReachedPos && $knownReachedPos->hasReached( $this->mWaitForPos ) ) { wfDebugLog( 'replication', __METHOD__ . - ": slave $server known to be caught up (pos >= $knownReachedPos).\n" ); + ": replica DB $server known to be caught up (pos >= $knownReachedPos).\n" ); return true; } @@ -499,12 +499,12 @@ class LoadBalancer { } } - wfDebugLog( 'replication', __METHOD__ . ": Waiting for slave $server to catch up...\n" ); + wfDebugLog( 'replication', __METHOD__ . ": Waiting for replica DB $server to catch up...\n" ); $timeout = $timeout ?: $this->mWaitTimeout; $result = $conn->masterPosWait( $this->mWaitForPos, $timeout ); if ( $result == -1 || is_null( $result ) ) { - // Timed out waiting for slave, use master instead + // Timed out waiting for replica DB, use master instead $msg = __METHOD__ . ": Timed out waiting on $server pos {$this->mWaitForPos}"; wfDebugLog( 'replication', "$msg\n" ); wfDebugLog( 'DBPerformance', "$msg:\n" . wfBacktrace( true ) ); @@ -573,7 +573,7 @@ class LoadBalancer { : $this->getReaderIndex( false, $wiki ); # Couldn't find a working server in getReaderIndex()? if ( $i === false ) { - $this->mLastError = 'No working slave server: ' . $this->mLastError; + $this->mLastError = 'No working replica DB server: ' . $this->mLastError; return $this->reportConnectionError(); } @@ -996,8 +996,8 @@ class LoadBalancer { * @return mixed */ public function getMasterPos() { - # If this entire request was served from a slave without opening a connection to the - # master (however unlikely that may be), then we can fetch the position from the slave. + # If this entire request was served from a replica DB without opening a connection to the + # master (however unlikely that may be), then we can fetch the position from the replica DB. $masterConn = $this->getAnyOpenConnection( 0 ); if ( !$masterConn ) { $serverCount = count( $this->mServers ); @@ -1468,10 +1468,10 @@ class LoadBalancer { } elseif ( $this->getLaggedSlaveMode( $wiki ) ) { if ( $this->slavesDownMode ) { return 'The database has been automatically locked ' . - 'until the slave database servers become available'; + 'until the replica database servers become available'; } else { return 'The database has been automatically locked ' . - 'while the slave database servers catch up to the master.'; + 'while the replica database servers catch up to the master.'; } } elseif ( $this->masterRunningReadOnly( $wiki, $conn ) ) { return 'The database master is running in read-only mode.'; @@ -1591,10 +1591,10 @@ class LoadBalancer { } /** - * Get the hostname and lag time of the most-lagged slave + * Get the hostname and lag time of the most-lagged replica DB * * This is useful for maintenance scripts that need to throttle their updates. - * May attempt to open connections to slaves on the default DB. If there is + * May attempt to open connections to replica DBs on the default DB. If there is * no lag, the maximum lag will be reported as -1. * * @param bool|string $wiki Wiki ID, or false for the default database @@ -1663,11 +1663,11 @@ class LoadBalancer { } /** - * Wait for a slave DB to reach a specified master position + * Wait for a replica DB to reach a specified master position * * This will connect to the master to get an accurate position if $pos is not given * - * @param IDatabase $conn Slave DB + * @param IDatabase $conn Replica DB * @param DBMasterPos|bool $pos Master position; default: current position * @param integer $timeout Timeout in seconds * @return bool Success @@ -1675,7 +1675,7 @@ class LoadBalancer { */ public function safeWaitForMasterPos( IDatabase $conn, $pos = false, $timeout = 10 ) { if ( $this->getServerCount() == 1 || !$conn->getLBInfo( 'slave' ) ) { - return true; // server is not a slave DB + return true; // server is not a replica DB } $pos = $pos ?: $this->getConnection( DB_MASTER )->getMasterPos(); -- 2.20.1