From: Aaron Schulz Date: Wed, 23 Jan 2019 19:32:18 +0000 (-0800) Subject: rdbms: make safeWaitForMasterPos() handle master connection failure X-Git-Tag: 1.34.0-rc.0~2715 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=7f3483e51495a9fc8b2dbfc95b02afbb9b9f5bc9;p=lhc%2Fweb%2Fwiklou.git rdbms: make safeWaitForMasterPos() handle master connection failure Previously, in such cases where a master connection was needed and could not be acquired, a fatal error would occur. Instead, throw a DBReplicationWaitError exception. Also removed a redundant documentation block for the method. Change-Id: Ide3015d57673df0876daf265a0182fe41004052d --- diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php b/includes/libs/rdbms/loadbalancer/LoadBalancer.php index f2e4e3d7d1..9e4b15ff79 100644 --- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php @@ -1842,12 +1842,6 @@ class LoadBalancer implements ILoadBalancer { } } - /** - * @param IDatabase $conn - * @param DBMasterPos|bool $pos - * @param int|null $timeout - * @return bool - */ public function safeWaitForMasterPos( IDatabase $conn, $pos = false, $timeout = null ) { $timeout = max( 1, $timeout ?: $this->waitTimeout ); @@ -1862,6 +1856,12 @@ class LoadBalancer implements ILoadBalancer { $pos = $masterConn->getMasterPos(); } else { $masterConn = $this->openConnection( $this->getWriterIndex(), self::DOMAIN_ANY ); + if ( !$masterConn ) { + throw new DBReplicationWaitError( + null, + "Could not obtain a master database connection to get the position" + ); + } $pos = $masterConn->getMasterPos(); $this->closeConnection( $masterConn ); }