[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Add some missing reuseConnection() to LoadBalancer
jenkins-bot has submitted this change and it was merged. Change subject: Add some missing reuseConnection() to LoadBalancer .. Add some missing reuseConnection() to LoadBalancer Change-Id: I99099f909e7759c061d44ad4e1ed049e038a4d7d --- M includes/libs/rdbms/loadbalancer/LoadBalancer.php 1 file changed, 22 insertions(+), 12 deletions(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php b/includes/libs/rdbms/loadbalancer/LoadBalancer.php index 7ba21ac..9c07043 100644 --- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php @@ -1303,6 +1303,9 @@ try { $dbw = $conn ?: $this->getConnection( DB_MASTER, [], $domain ); $readOnly = (int)$dbw->serverIsReadOnly(); + if ( !$conn ) { + $this->reuseConnection( $dbw ); + } } catch ( DBError $e ) { $readOnly = 0; } @@ -1411,7 +1414,7 @@ } public function safeGetLag( IDatabase $conn ) { - if ( $this->getServerCount() == 1 ) { + if ( $this->getServerCount() <= 1 ) { return 0; } else { return $conn->getLag(); @@ -1419,23 +1422,30 @@ } public function safeWaitForMasterPos( IDatabase $conn, $pos = false, $timeout = 10 ) { - if ( $this->getServerCount() == 1 || !$conn->getLBInfo( 'replica' ) ) { + if ( $this->getServerCount() <= 1 || !$conn->getLBInfo( 'replica' ) ) { return true; // server is not a replica DB } - $pos = $pos ?: $this->getConnection( DB_MASTER )->getMasterPos(); - if ( !( $pos instanceof DBMasterPos ) ) { - return false; // something is misconfigured + if ( !$pos ) { + // Get the current master position + $dbw = $this->getConnection( DB_MASTER ); + $pos = $dbw->getMasterPos(); + $this->reuseConnection( $dbw ); } - $result = $conn->masterPosWait( $pos, $timeout ); - if ( $result == -1 || is_null( $result ) ) { - $msg = __METHOD__ . ": Timed out waiting on {$conn->getServer()} pos {$pos}"; - $this->replLogger->warning( "$msg" ); - $ok = false; + if ( $pos instanceof DBMasterPos ) { + $result = $conn->masterPosWait( $pos, $timeout ); + if ( $result == -1 || is_null( $result ) ) { + $msg = __METHOD__ . ": Timed out waiting on {$conn->getServer()} pos {$pos}"; + $this->replLogger->warning( "$msg" ); + $ok = false; + } else { + $this->replLogger->info( __METHOD__ . ": Done" ); + $ok = true; + } } else { - $this->replLogger->info( __METHOD__ . ": Done" ); - $ok = true; + $ok = false; // something is misconfigured + $this->replLogger->error( "Could not get master pos for {$conn->getServer()}." ); } return $ok; -- To view, visit https://gerrit.wikimedia.org/r/311930 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I99099f909e7759c061d44ad4e1ed049e038a4d7d Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aaron Schulz Gerrit-Reviewer: Legoktm Gerrit-Reviewer: jenkins-bot <> ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Add some missing reuseConnection() to LoadBalancer
Aaron Schulz has uploaded a new change for review. https://gerrit.wikimedia.org/r/311930 Change subject: Add some missing reuseConnection() to LoadBalancer .. Add some missing reuseConnection() to LoadBalancer Change-Id: I99099f909e7759c061d44ad4e1ed049e038a4d7d --- M includes/libs/rdbms/loadbalancer/LoadBalancer.php 1 file changed, 22 insertions(+), 12 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/30/311930/1 diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php b/includes/libs/rdbms/loadbalancer/LoadBalancer.php index 7ba21ac..449ff16 100644 --- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php @@ -1303,6 +1303,9 @@ try { $dbw = $conn ?: $this->getConnection( DB_MASTER, [], $domain ); $readOnly = (int)$dbw->serverIsReadOnly(); + if ( !$conn ) { + $this->reuseConnection( $dbw ); + } } catch ( DBError $e ) { $readOnly = 0; } @@ -1411,7 +1414,7 @@ } public function safeGetLag( IDatabase $conn ) { - if ( $this->getServerCount() == 1 ) { + if ( $this->getServerCount() <= 1 ) { return 0; } else { return $conn->getLag(); @@ -1419,23 +1422,30 @@ } public function safeWaitForMasterPos( IDatabase $conn, $pos = false, $timeout = 10 ) { - if ( $this->getServerCount() == 1 || !$conn->getLBInfo( 'replica' ) ) { + if ( $this->getServerCount() <= 1 || !$conn->getLBInfo( 'replica' ) ) { return true; // server is not a replica DB } - $pos = $pos ?: $this->getConnection( DB_MASTER )->getMasterPos(); - if ( !( $pos instanceof DBMasterPos ) ) { - return false; // something is misconfigured + if ( !$pos ) { + // Get the current master position + $dbw = $this->getConnection( DB_MASTER ); + $pos = $dbw->getMasterPos();; + $this->reuseConnection( $dbw ); } - $result = $conn->masterPosWait( $pos, $timeout ); - if ( $result == -1 || is_null( $result ) ) { - $msg = __METHOD__ . ": Timed out waiting on {$conn->getServer()} pos {$pos}"; - $this->replLogger->warning( "$msg" ); - $ok = false; + if ( $pos instanceof DBMasterPos ) { + $result = $conn->masterPosWait( $pos, $timeout ); + if ( $result == -1 || is_null( $result ) ) { + $msg = __METHOD__ . ": Timed out waiting on {$conn->getServer()} pos {$pos}"; + $this->replLogger->warning( "$msg" ); + $ok = false; + } else { + $this->replLogger->info( __METHOD__ . ": Done" ); + $ok = true; + } } else { - $this->replLogger->info( __METHOD__ . ": Done" ); - $ok = true; + $ok = false; // something is misconfigured + $this->replLogger->error( "Could not get master pos for {$conn->getServer()}." ); } return $ok; -- To view, visit https://gerrit.wikimedia.org/r/311930 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I99099f909e7759c061d44ad4e1ed049e038a4d7d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aaron Schulz ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits