Change-Id: Iab671b66a4a4da33c780b6d78752c484ec329254
* @param int $i Server index
* @param string|bool $domain Domain ID, or false for the current domain
* @return IDatabase|bool Returns false on errors
* @param int $i Server index
* @param string|bool $domain Domain ID, or false for the current domain
* @return IDatabase|bool Returns false on errors
+ * @throws DBAccessError
*/
public function openConnection( $i, $domain = false );
*/
public function openConnection( $i, $domain = false );
+ /**
+ * @see ILoadBalancer::getConnection()
+ *
+ * @param int $i
+ * @param array $groups
+ * @param bool $domain
+ * @return Database
+ * @throws DBConnectionError
+ */
public function getConnection( $i, $groups = [], $domain = false ) {
if ( $i === null || $i === false ) {
throw new InvalidArgumentException( 'Attempt to call ' . __METHOD__ .
public function getConnection( $i, $groups = [], $domain = false ) {
if ( $i === null || $i === false ) {
throw new InvalidArgumentException( 'Attempt to call ' . __METHOD__ .
# Couldn't find a working server in getReaderIndex()?
if ( $i === false ) {
$this->mLastError = 'No working replica DB server: ' . $this->mLastError;
# Couldn't find a working server in getReaderIndex()?
if ( $i === false ) {
$this->mLastError = 'No working replica DB server: ' . $this->mLastError;
-
- return $this->reportConnectionError();
+ // Throw an exception
+ $this->reportConnectionError();
+ return null; // not reached
}
}
# Now we have an explicit index into the servers array
$conn = $this->openConnection( $i, $domain );
if ( !$conn ) {
}
}
# Now we have an explicit index into the servers array
$conn = $this->openConnection( $i, $domain );
if ( !$conn ) {
- return $this->reportConnectionError();
+ // Throw an exception
+ $this->reportConnectionError();
+ return null; // not reached
}
# Profile any new connections that happen
}
# Profile any new connections that happen
return new DBConnRef( $this, [ $db, $groups, $domain ] );
}
return new DBConnRef( $this, [ $db, $groups, $domain ] );
}
+ /**
+ * @see ILoadBalancer::openConnection()
+ *
+ * @param int $i
+ * @param bool $domain
+ * @return bool|Database
+ * @throws DBAccessError
+ */
public function openConnection( $i, $domain = false ) {
if ( $this->localDomain->equals( $domain ) || $domain === $this->localDomainIdAlias ) {
$domain = false; // local connection requested
public function openConnection( $i, $domain = false ) {
if ( $this->localDomain->equals( $domain ) || $domain === $this->localDomainIdAlias ) {
$domain = false; // local connection requested
*
* @param int $i Server index
* @param string $domain Domain ID to open
*
* @param int $i Server index
* @param string $domain Domain ID to open
*/
private function openForeignConnection( $i, $domain ) {
$domainInstance = DatabaseDomain::newFromId( $domain );
*/
private function openForeignConnection( $i, $domain ) {
$domainInstance = DatabaseDomain::newFromId( $domain );
*
* @param array $server
* @param string|bool $dbNameOverride Use "" to not select any database
*
* @param array $server
* @param string|bool $dbNameOverride Use "" to not select any database
* @throws DBAccessError
* @throws InvalidArgumentException
*/
* @throws DBAccessError
* @throws InvalidArgumentException
*/
/**
* @throws DBConnectionError
/**
* @throws DBConnectionError
*/
private function reportConnectionError() {
*/
private function reportConnectionError() {
- $conn = $this->mErrorConnection; // The connection which caused the error
+ $conn = $this->mErrorConnection; // the connection which caused the error
$context = [
'method' => __METHOD__,
'last_error' => $this->mLastError,
$context = [
'method' => __METHOD__,
'last_error' => $this->mLastError,
// throws DBConnectionError
$conn->reportConnectionError( "{$this->mLastError} ({$context['db_server']})" );
}
// throws DBConnectionError
$conn->reportConnectionError( "{$this->mLastError} ({$context['db_server']})" );
}
-
- return false; /* not reached */
}
public function getWriterIndex() {
}
public function getWriterIndex() {