private function newClusterConnection($application, $database, $mode)
 {
     $master = PhabricatorDatabaseRef::getMasterDatabaseRefForApplication($application);
     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::getReplicaDatabaseRefForApplication($application);
     if ($replica) {
         $connection = $replica->newApplicationConnection($database);
         $connection->setReadOnly(true);
         if ($replica->isReachable($connection)) {
             return $connection;
         }
     }
     if (!$master && !$replica) {
         $this->raiseUnconfigured($database);
     }
     $this->raiseUnreachable($database);
 }