From 3b45608c78f1eb1975cf178c1070827ca1deee94 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 10 Aug 2016 11:54:27 -0700 Subject: [PATCH] Fix misleading error message when only cluster database masters are configured Summary: Fixes T11446. We can raise the misleading error: > No valid databases are configured! ...when a valid master is configured but unreachable. Instead, more carefully raise either "nothing is configured" or "nothing is reachable". Test Plan: Configured only a master, artificially severed it, got "nothing is reachable" instead of "nothing is configured". Reviewers: chad Reviewed By: chad Maniphest Tasks: T11446 Differential Revision: https://secure.phabricator.com/D16386 --- .../storage/lisk/PhabricatorLiskDAO.php | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php b/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php index 99f1bcb864..21fabed8a8 100644 --- a/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php +++ b/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php @@ -122,15 +122,16 @@ abstract class PhabricatorLiskDAO extends LiskDAO { } $replica = PhabricatorDatabaseRef::getReplicaDatabaseRef(); - if (!$replica) { - throw new Exception( - pht('No valid databases are configured!')); + if ($replica) { + $connection = $replica->newApplicationConnection($database); + $connection->setReadOnly(true); + if ($replica->isReachable($connection)) { + return $connection; + } } - $connection = $replica->newApplicationConnection($database); - $connection->setReadOnly(true); - if ($replica->isReachable($connection)) { - return $connection; + if (!$master && !$replica) { + $this->raiseUnconfigured($database); } $this->raiseUnreachable($database); @@ -153,10 +154,18 @@ abstract class PhabricatorLiskDAO extends LiskDAO { $database)); } + private function raiseUnconfigured($database) { + throw new Exception( + pht( + 'Unable to establish a connection to any database host '. + '(while trying "%s"). No masters or replicas are configured.', + $database)); + } + private function raiseUnreachable($database) { throw new PhabricatorClusterStrandedException( pht( - 'Unable to establish a connection to ANY database host '. + 'Unable to establish a connection to any database host '. '(while trying "%s"). All masters and replicas are completely '. 'unreachable.', $database));