/**
* 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
}
/**
- * Detemine if any lagged slave connection was used
+ * Detemine if any lagged replica DB connection was used
* @since 1.27
* @return bool
*/
}
/**
- * 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.
$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']
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 )
);
}
// 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 ) {
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;
/** @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';
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;
}
}
- # 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;
}
}
/**
- * 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
*
$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;
}
}
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 ) ) {
}
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;
}
}
/**
- * 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()
*
$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 );
}
}
/**
- * 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)
}
/**
- * 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
$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;
}
}
}
- 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 ) );
: $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();
}
* @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 );
} 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.';
}
/**
- * 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
}
/**
- * 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
*/
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();