private function newClusterConnection($database, $mode) { $master = PhabricatorDatabaseRef::getMasterDatabaseRef(); if ($master && !$master->isSevered()) { $connection = $master->newApplicationConnection($database); if ($master->isReachable($connection)) { return $connection; } else { if ($mode == 'w') { $this->raiseImpossibleWrite($database); } PhabricatorEnv::setReadOnly(true, PhabricatorEnv::READONLY_UNREACHABLE); } } $replica = PhabricatorDatabaseRef::getReplicaDatabaseRef(); if (!$replica) { throw new Exception(pht('No valid databases are configured!')); } $connection = $replica->newApplicationConnection($database); $connection->setReadOnly(true); if ($replica->isReachable($connection)) { return $connection; } $this->raiseUnreachable($database); }