Aaron Schulz has uploaded a new change for review. https://gerrit.wikimedia.org/r/308361
Change subject: Rename some DB/LB variables to be more consistent ...................................................................... Rename some DB/LB variables to be more consistent Change-Id: I21de9c972402144159b7b2fc824533f8cefb03e7 --- M includes/db/Database.php M includes/db/loadbalancer/LoadBalancer.php 2 files changed, 25 insertions(+), 24 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/61/308361/1 diff --git a/includes/db/Database.php b/includes/db/Database.php index 5b0f230..786d5f9 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -128,7 +128,7 @@ */ 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. @@ -1028,20 +1028,21 @@ * @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; } @@ -2911,7 +2912,7 @@ // 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'] ); } /** @@ -3206,7 +3207,7 @@ */ public function getTransactionLagStatus() { return $this->mTrxLevel - ? [ 'lag' => $this->mTrxSlaveLag, 'since' => $this->trxTimestamp() ] + ? [ 'lag' => $this->mTrxReplicaLag, 'since' => $this->trxTimestamp() ] : null; } diff --git a/includes/db/loadbalancer/LoadBalancer.php b/includes/db/loadbalancer/LoadBalancer.php index 36df466..7ca0b33 100644 --- a/includes/db/loadbalancer/LoadBalancer.php +++ b/includes/db/loadbalancer/LoadBalancer.php @@ -61,9 +61,9 @@ /** @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 */ @@ -280,7 +280,7 @@ # 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; @@ -289,7 +289,7 @@ # meets our criteria $currentLoads = $nonErrorLoads; while ( count( $currentLoads ) ) { - if ( $this->mAllowLagged || $laggedSlaveMode ) { + if ( $this->mAllowLagged || $laggedReplicaMode ) { $i = ArrayUtils::pickRandom( $currentLoads ); } else { $i = false; @@ -309,7 +309,7 @@ # 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; } } @@ -350,8 +350,8 @@ } 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(); @@ -360,8 +360,8 @@ 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 ); @@ -385,7 +385,7 @@ if ( $i > 0 ) { if ( !$this->doWait( $i ) ) { $this->mServers[$i]['slave pos'] = $this->getAnyOpenConnection( $i )->getSlavePos(); - $this->laggedSlaveMode = true; + $this->laggedReplicaMode = true; } } } @@ -1431,19 +1431,19 @@ */ 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; } /** @@ -1452,7 +1452,7 @@ * @since 1.27 */ public function laggedSlaveUsed() { - return $this->laggedSlaveMode; + return $this->laggedReplicaMode; } /** @@ -1466,7 +1466,7 @@ 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 { -- To view, visit https://gerrit.wikimedia.org/r/308361 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I21de9c972402144159b7b2fc824533f8cefb03e7 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits