*/
private $mTrxTimestamp = null;
/** @var float Lag estimate at the time of BEGIN */
- private $mTrxSlaveLag = null;
+ private $mTrxReplicaLag = null;
/**
* Remembers the function name given for starting the most recent transaction via begin().
* Used to provide additional context for error reporting.
* @param float $runtime Total runtime, including RTT
*/
private function updateTrxWriteQueryTime( $sql, $runtime ) {
- $indicativeOfSlaveRuntime = true;
+ // Whether this is indicative of replica DB runtime (except for RBR or ws_repl)
+ $indicativeOfReplicaRuntime = true;
if ( $runtime > self::SLOW_WRITE_SEC ) {
$verb = $this->getQueryVerb( $sql );
// insert(), upsert(), replace() are fast unless bulky in size or blocked on locks
if ( $verb === 'INSERT' ) {
- $indicativeOfSlaveRuntime = $this->affectedRows() > self::SMALL_WRITE_ROWS;
+ $indicativeOfReplicaRuntime = $this->affectedRows() > self::SMALL_WRITE_ROWS;
} elseif ( $verb === 'REPLACE' ) {
- $indicativeOfSlaveRuntime = $this->affectedRows() > self::SMALL_WRITE_ROWS / 2;
+ $indicativeOfReplicaRuntime = $this->affectedRows() > self::SMALL_WRITE_ROWS / 2;
}
}
$this->mTrxWriteDuration += $runtime;
$this->mTrxWriteQueryCount += 1;
- if ( $indicativeOfSlaveRuntime ) {
+ if ( $indicativeOfReplicaRuntime ) {
$this->mTrxWriteAdjDuration += $runtime;
$this->mTrxWriteAdjQueryCount += 1;
}
// 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'] );
+ $this->mTrxReplicaLag = $status['lag'] + ( microtime( true ) - $status['since'] );
}
/**
*/
public function getTransactionLagStatus() {
return $this->mTrxLevel
- ? [ 'lag' => $this->mTrxSlaveLag, 'since' => $this->trxTimestamp() ]
+ ? [ 'lag' => $this->mTrxReplicaLag, 'since' => $this->trxTimestamp() ]
: null;
}
/** @var bool|DBMasterPos False if not set */
private $mWaitForPos;
/** @var bool Whether the generic reader fell back to a lagged replica DB */
- private $laggedSlaveMode = false;
+ private $laggedReplicaMode = false;
/** @var bool Whether the generic reader fell back to a lagged replica DB */
- private $slavesDownMode = false;
+ private $allReplicasDownMode = false;
/** @var string The last DB selection or connection error */
private $mLastError = 'Unknown error';
/** @var string|bool Reason the LB is read-only or false if not */
# Scale the configured load ratios according to the dynamic load (if the load monitor supports it)
$this->getLoadMonitor()->scaleLoads( $nonErrorLoads, $group, $wiki );
- $laggedSlaveMode = false;
+ $laggedReplicaMode = false;
# No server found yet
$i = false;
# meets our criteria
$currentLoads = $nonErrorLoads;
while ( count( $currentLoads ) ) {
- if ( $this->mAllowLagged || $laggedSlaveMode ) {
+ if ( $this->mAllowLagged || $laggedReplicaMode ) {
$i = ArrayUtils::pickRandom( $currentLoads );
} else {
$i = false;
# 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;
+ $laggedReplicaMode = true;
}
}
}
if ( $i !== false ) {
- # replica DB connection successful
- # Wait for the session master pos for a short time
+ # Replica DB connection successful.
+ # Wait for the session master pos for a short time.
if ( $this->mWaitForPos && $i > 0 ) {
if ( !$this->doWait( $i ) ) {
$this->mServers[$i]['slave pos'] = $conn->getSlavePos();
if ( $this->mReadIndex <= 0 && $this->mLoads[$i] > 0 && $group === false ) {
$this->mReadIndex = $i;
# Record if the generic reader index is in "lagged replica DB" mode
- if ( $laggedSlaveMode ) {
- $this->laggedSlaveMode = true;
+ if ( $laggedReplicaMode ) {
+ $this->laggedReplicaMode = true;
}
}
$serverName = $this->getServerName( $i );
if ( $i > 0 ) {
if ( !$this->doWait( $i ) ) {
$this->mServers[$i]['slave pos'] = $this->getAnyOpenConnection( $i )->getSlavePos();
- $this->laggedSlaveMode = true;
+ $this->laggedReplicaMode = true;
}
}
}
*/
public function getLaggedSlaveMode( $wiki = false ) {
// No-op if there is only one DB (also avoids recursion)
- if ( !$this->laggedSlaveMode && $this->getServerCount() > 1 ) {
+ if ( !$this->laggedReplicaMode && $this->getServerCount() > 1 ) {
try {
- // See if laggedSlaveMode gets set
+ // See if laggedReplicaMode gets set
$conn = $this->getConnection( DB_SLAVE, false, $wiki );
$this->reuseConnection( $conn );
} catch ( DBConnectionError $e ) {
// Avoid expensive re-connect attempts and failures
- $this->slavesDownMode = true;
- $this->laggedSlaveMode = true;
+ $this->allReplicasDownMode = true;
+ $this->laggedReplicaMode = true;
}
}
- return $this->laggedSlaveMode;
+ return $this->laggedReplicaMode;
}
/**
* @since 1.27
*/
public function laggedSlaveUsed() {
- return $this->laggedSlaveMode;
+ return $this->laggedReplicaMode;
}
/**
if ( $this->readOnlyReason !== false ) {
return $this->readOnlyReason;
} elseif ( $this->getLaggedSlaveMode( $wiki ) ) {
- if ( $this->slavesDownMode ) {
+ if ( $this->allReplicasDownMode ) {
return 'The database has been automatically locked ' .
'until the replica database servers become available';
} else {