Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/storage/lisk/PhabricatorLiskDAO.php
| Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | public static function getStorageNamespace() { | ||||
| return $namespace; | return $namespace; | ||||
| } | } | ||||
| /** | /** | ||||
| * @task config | * @task config | ||||
| */ | */ | ||||
| protected function establishLiveConnection($mode) { | protected function establishLiveConnection($mode) { | ||||
| $namespace = self::getStorageNamespace(); | $namespace = self::getStorageNamespace(); | ||||
| $database = $namespace.'_'.$this->getApplicationName(); | |||||
| $conf = PhabricatorEnv::newObjectFromConfig( | |||||
| 'mysql.configuration-provider', | |||||
| array($this, $mode, $namespace)); | |||||
| $is_readonly = PhabricatorEnv::isReadOnly(); | $is_readonly = PhabricatorEnv::isReadOnly(); | ||||
| if ($is_readonly && ($mode != 'r')) { | if ($is_readonly && ($mode != 'r')) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Attempting to establish write-mode connection from a read-only '. | 'Attempting to establish write-mode connection from a read-only '. | ||||
| 'page (to database "%s").', | 'page (to database "%s").', | ||||
| $conf->getDatabase())); | $database)); | ||||
| } | } | ||||
| $connection = PhabricatorEnv::newObjectFromConfig( | $refs = PhabricatorDatabaseRef::loadAll(); | ||||
| if ($refs) { | |||||
| $connection = $this->newClusterConnection($database); | |||||
| } else { | |||||
| $connection = $this->newBasicConnection($database, $mode, $namespace); | |||||
| } | |||||
| // TODO: This should be testing if the mode is "r", but that would proably | |||||
| // break a lot of things. Perform a more narrow test for readonly mode | |||||
| // until we have greater certainty that this works correctly most of the | |||||
| // time. | |||||
| if ($is_readonly) { | |||||
| $connection->setReadOnly(true); | |||||
| } | |||||
| return $connection; | |||||
| } | |||||
| private function newBasicConnection($database, $mode, $namespace) { | |||||
| $conf = PhabricatorEnv::newObjectFromConfig( | |||||
| 'mysql.configuration-provider', | |||||
| array($this, $mode, $namespace)); | |||||
| return PhabricatorEnv::newObjectFromConfig( | |||||
| 'mysql.implementation', | 'mysql.implementation', | ||||
| array( | array( | ||||
| array( | array( | ||||
| 'user' => $conf->getUser(), | 'user' => $conf->getUser(), | ||||
| 'pass' => $conf->getPassword(), | 'pass' => $conf->getPassword(), | ||||
| 'host' => $conf->getHost(), | 'host' => $conf->getHost(), | ||||
| 'port' => $conf->getPort(), | 'port' => $conf->getPort(), | ||||
| 'database' => $conf->getDatabase(), | 'database' => $database, | ||||
| 'retries' => 3, | 'retries' => 3, | ||||
| ), | ), | ||||
| )); | )); | ||||
| } | |||||
| // TODO: This should be testing if the mode is "r", but that would proably | private function newClusterConnection($database) { | ||||
| // break a lot of things. Perform a more narrow test for readonly mode | $master = PhabricatorDatabaseRef::getMasterDatabaseRef(); | ||||
| // until we have greater certainty that this works correctly most of the | |||||
| // time. | if (!$master) { | ||||
| if ($is_readonly) { | // TODO: Implicitly degrade to read-only mode. | ||||
| $connection->setReadOnly(true); | throw new Exception(pht('No master in database cluster config!')); | ||||
| } | } | ||||
| return $connection; | return $master->newApplicationConnection($database); | ||||
| } | } | ||||
| /** | /** | ||||
| * @task config | * @task config | ||||
| */ | */ | ||||
| public function getTableName() { | public function getTableName() { | ||||
| $str = 'phabricator'; | $str = 'phabricator'; | ||||
| $len = strlen($str); | $len = strlen($str); | ||||
| $class = strtolower(get_class($this)); | $class = strtolower(get_class($this)); | ||||
| ▲ Show 20 Lines • Show All 163 Lines • Show Last 20 Lines | |||||