Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/cluster/PhabricatorDatabaseRef.php
| Show All 34 Lines | final class PhabricatorDatabaseRef | ||||
| private $healthRecord; | private $healthRecord; | ||||
| private $didFailToConnect; | private $didFailToConnect; | ||||
| private $isDefaultPartition; | private $isDefaultPartition; | ||||
| private $applicationMap = array(); | private $applicationMap = array(); | ||||
| private $masterRef; | private $masterRef; | ||||
| private $replicaRefs = array(); | private $replicaRefs = array(); | ||||
| private $usePersistentConnections; | |||||
| public function setHost($host) { | public function setHost($host) { | ||||
| $this->host = $host; | $this->host = $host; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getHost() { | public function getHost() { | ||||
| return $this->host; | return $this->host; | ||||
| ▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | public function setIsDefaultPartition($is_default_partition) { | ||||
| $this->isDefaultPartition = $is_default_partition; | $this->isDefaultPartition = $is_default_partition; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getIsDefaultPartition() { | public function getIsDefaultPartition() { | ||||
| return $this->isDefaultPartition; | return $this->isDefaultPartition; | ||||
| } | } | ||||
| public function setUsePersistentConnections($use_persistent_connections) { | |||||
| $this->usePersistentConnections = $use_persistent_connections; | |||||
| return $this; | |||||
| } | |||||
| public function getUsePersistentConnections() { | |||||
| return $this->usePersistentConnections; | |||||
| } | |||||
| public function setApplicationMap(array $application_map) { | public function setApplicationMap(array $application_map) { | ||||
| $this->applicationMap = $application_map; | $this->applicationMap = $application_map; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getApplicationMap() { | public function getApplicationMap() { | ||||
| return $this->applicationMap; | return $this->applicationMap; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 395 Lines • ▼ Show 20 Lines | public static function newIndividualRef() { | ||||
| return id(new self()) | return id(new self()) | ||||
| ->setUser($default_user) | ->setUser($default_user) | ||||
| ->setPass($default_pass) | ->setPass($default_pass) | ||||
| ->setHost($default_host) | ->setHost($default_host) | ||||
| ->setPort($default_port) | ->setPort($default_port) | ||||
| ->setIsIndividual(true) | ->setIsIndividual(true) | ||||
| ->setIsMaster(true) | ->setIsMaster(true) | ||||
| ->setIsDefaultPartition(true); | ->setIsDefaultPartition(true) | ||||
| ->setUsePersistentConnections(false); | |||||
| } | } | ||||
| public static function getAllReplicaDatabaseRefs() { | public static function getAllReplicaDatabaseRefs() { | ||||
| $refs = self::getClusterRefs(); | $refs = self::getClusterRefs(); | ||||
| if (!$refs) { | if (!$refs) { | ||||
| return array(); | return array(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | private function newConnection(array $options) { | ||||
| $spec = $options + array( | $spec = $options + array( | ||||
| 'user' => $this->getUser(), | 'user' => $this->getUser(), | ||||
| 'pass' => $this->getPass(), | 'pass' => $this->getPass(), | ||||
| 'host' => $this->getHost(), | 'host' => $this->getHost(), | ||||
| 'port' => $this->getPort(), | 'port' => $this->getPort(), | ||||
| 'database' => null, | 'database' => null, | ||||
| 'retries' => $default_retries, | 'retries' => $default_retries, | ||||
| 'timeout' => $default_timeout, | 'timeout' => $default_timeout, | ||||
| 'persistent' => $this->getUsePersistentConnections(), | |||||
| ); | ); | ||||
| return self::newRawConnection($spec); | $is_cli = (php_sapi_name() == 'cli'); | ||||
| $use_persistent = false; | |||||
| if (!empty($spec['persistent']) && !$is_cli) { | |||||
| $use_persistent = true; | |||||
| } | |||||
| unset($spec['persistent']); | |||||
| $connection = self::newRawConnection($spec); | |||||
| // If configured, use persistent connections. See T11672 for details. | |||||
| if ($use_persistent) { | |||||
| $connection->setPersistent($use_persistent); | |||||
| } | |||||
| // Unless this is a script running from the CLI, prevent any query from | |||||
| // running for more than 30 seconds. See T10849 for details. | |||||
| if (!$is_cli) { | |||||
| $connection->setQueryTimeout(30); | |||||
| } | |||||
| return $connection; | |||||
| } | } | ||||
| public static function newRawConnection(array $options) { | public static function newRawConnection(array $options) { | ||||
| if (extension_loaded('mysqli')) { | if (extension_loaded('mysqli')) { | ||||
| return new AphrontMySQLiDatabaseConnection($options); | return new AphrontMySQLiDatabaseConnection($options); | ||||
| } else { | } else { | ||||
| return new AphrontMySQLDatabaseConnection($options); | return new AphrontMySQLDatabaseConnection($options); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||