Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/cluster/PhabricatorDatabaseRef.php
| Show First 20 Lines • Show All 217 Lines • ▼ Show 20 Lines | return array( | ||||
| self::REPLICATION_NOT_REPLICATING => array( | self::REPLICATION_NOT_REPLICATING => array( | ||||
| 'icon' => 'fa-exclamation-triangle', | 'icon' => 'fa-exclamation-triangle', | ||||
| 'color' => 'red', | 'color' => 'red', | ||||
| 'label' => pht('Not Replicating'), | 'label' => pht('Not Replicating'), | ||||
| ), | ), | ||||
| ); | ); | ||||
| } | } | ||||
| public static function getLiveRefs() { | public static function getClusterRefs() { | ||||
| $cache = PhabricatorCaches::getRequestCache(); | $cache = PhabricatorCaches::getRequestCache(); | ||||
| $refs = $cache->getKey(self::KEY_REFS); | $refs = $cache->getKey(self::KEY_REFS); | ||||
| if (!$refs) { | if (!$refs) { | ||||
| $refs = self::newRefs(); | $refs = self::newRefs(); | ||||
| $cache->setKey(self::KEY_REFS, $refs); | $cache->setKey(self::KEY_REFS, $refs); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 217 Lines • ▼ Show 20 Lines | final class PhabricatorDatabaseRef | ||||
| public function getHealthRecord() { | public function getHealthRecord() { | ||||
| if (!$this->healthRecord) { | if (!$this->healthRecord) { | ||||
| $this->healthRecord = new PhabricatorDatabaseHealthRecord($this); | $this->healthRecord = new PhabricatorDatabaseHealthRecord($this); | ||||
| } | } | ||||
| return $this->healthRecord; | return $this->healthRecord; | ||||
| } | } | ||||
| public static function getActiveDatabaseRefs() { | |||||
| $refs = array(); | |||||
| foreach (self::getMasterDatabaseRefs() as $ref) { | |||||
| $refs[] = $ref; | |||||
| } | |||||
| foreach (self::getReplicaDatabaseRefs() as $ref) { | |||||
| $refs[] = $ref; | |||||
| } | |||||
| return $refs; | |||||
| } | |||||
| public static function getMasterDatabaseRefs() { | public static function getMasterDatabaseRefs() { | ||||
| $refs = self::getLiveRefs(); | $refs = self::getClusterRefs(); | ||||
| if (!$refs) { | if (!$refs) { | ||||
| return array(self::getLiveIndividualRef()); | return array(self::getLiveIndividualRef()); | ||||
| } | } | ||||
| $masters = array(); | $masters = array(); | ||||
| foreach ($refs as $ref) { | foreach ($refs as $ref) { | ||||
| if ($ref->getDisabled()) { | if ($ref->getDisabled()) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if ($ref->getIsMaster()) { | if ($ref->getIsMaster()) { | ||||
| $masters[] = $ref; | $masters[] = $ref; | ||||
| } | } | ||||
| } | } | ||||
| return $masters; | return $masters; | ||||
| } | } | ||||
| public static function getMasterDatabaseRef() { | |||||
| // TODO: Remove this method; it no longer makes sense with application | |||||
| // partitioning. | |||||
| return head(self::getMasterDatabaseRefs()); | |||||
| } | |||||
| public static function getMasterDatabaseRefForDatabase($database) { | public static function getMasterDatabaseRefForDatabase($database) { | ||||
| $masters = self::getMasterDatabaseRefs(); | $masters = self::getMasterDatabaseRefs(); | ||||
| // TODO: Actually implement this. | // TODO: Actually implement this. | ||||
| return head($masters); | return head($masters); | ||||
| } | } | ||||
| public static function newIndividualRef() { | public static function newIndividualRef() { | ||||
| $conf = PhabricatorEnv::newObjectFromConfig( | $conf = PhabricatorEnv::newObjectFromConfig( | ||||
| 'mysql.configuration-provider', | 'mysql.configuration-provider', | ||||
| array(null, 'w', null)); | array(null, 'w', null)); | ||||
| return id(new self()) | return id(new self()) | ||||
| ->setHost($conf->getHost()) | ->setHost($conf->getHost()) | ||||
| ->setPort($conf->getPort()) | ->setPort($conf->getPort()) | ||||
| ->setUser($conf->getUser()) | ->setUser($conf->getUser()) | ||||
| ->setPass($conf->getPassword()) | ->setPass($conf->getPassword()) | ||||
| ->setIsIndividual(true) | ->setIsIndividual(true) | ||||
| ->setIsMaster(true); | ->setIsMaster(true); | ||||
| } | } | ||||
| public static function getReplicaDatabaseRefs() { | public static function getReplicaDatabaseRefs() { | ||||
| $refs = self::getLiveRefs(); | $refs = self::getClusterRefs(); | ||||
| if (!$refs) { | if (!$refs) { | ||||
| return array(); | return array(); | ||||
| } | } | ||||
| $replicas = array(); | $replicas = array(); | ||||
| foreach ($refs as $ref) { | foreach ($refs as $ref) { | ||||
| if ($ref->getDisabled()) { | if ($ref->getDisabled()) { | ||||
| ▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines | |||||