Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/cluster/PhabricatorDatabaseRef.php
Show First 20 Lines • Show All 233 Lines • ▼ Show 20 Lines | final class PhabricatorDatabaseRef | ||||
public static function queryAll() { | public static function queryAll() { | ||||
$refs = self::loadAll(); | $refs = self::loadAll(); | ||||
foreach ($refs as $ref) { | foreach ($refs as $ref) { | ||||
if ($ref->getDisabled()) { | if ($ref->getDisabled()) { | ||||
continue; | continue; | ||||
} | } | ||||
$conn = $ref->newConnection(); | $conn = $ref->newManagementConnection(); | ||||
$t_start = microtime(true); | $t_start = microtime(true); | ||||
try { | try { | ||||
$replica_status = queryfx_one($conn, 'SHOW SLAVE STATUS'); | $replica_status = queryfx_one($conn, 'SHOW SLAVE STATUS'); | ||||
$ref->setConnectionStatus(self::STATUS_OKAY); | $ref->setConnectionStatus(self::STATUS_OKAY); | ||||
} catch (AphrontAccessDeniedQueryException $ex) { | } catch (AphrontAccessDeniedQueryException $ex) { | ||||
$ref->setConnectionStatus(self::STATUS_REPLICATION_CLIENT); | $ref->setConnectionStatus(self::STATUS_REPLICATION_CLIENT); | ||||
$ref->setConnectionMessage( | $ref->setConnectionMessage( | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | foreach ($refs as $ref) { | ||||
'risk!')); | 'risk!')); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return $refs; | return $refs; | ||||
} | } | ||||
protected function newConnection() { | public function newManagementConnection() { | ||||
return PhabricatorEnv::newObjectFromConfig( | return $this->newConnection( | ||||
'mysql.implementation', | |||||
array( | array( | ||||
'retries' => 0, | |||||
'timeout' => 3, | |||||
)); | |||||
} | |||||
public function newApplicationConnection($database) { | |||||
return $this->newConnection( | |||||
array( | array( | ||||
'database' => $database, | |||||
)); | |||||
} | |||||
public static function getMasterDatabaseRef() { | |||||
$refs = self::loadAll(); | |||||
if (!$refs) { | |||||
$conf = PhabricatorEnv::newObjectFromConfig( | |||||
'mysql.configuration-provider', | |||||
array(null, 'w', null)); | |||||
return id(new self()) | |||||
->setHost($conf->getHost()) | |||||
->setPort($conf->getPort()) | |||||
->setUser($conf->getUser()) | |||||
->setPass($conf->getPassword()) | |||||
->setIsMaster(true); | |||||
} | |||||
$master = null; | |||||
foreach ($refs as $ref) { | |||||
if ($ref->getDisabled()) { | |||||
continue; | |||||
} | |||||
if ($ref->getIsMaster()) { | |||||
return $ref; | |||||
} | |||||
} | |||||
return null; | |||||
} | |||||
private function newConnection(array $options) { | |||||
$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' => 0, | 'retries' => 3, | ||||
), | 'timeout' => 15, | ||||
); | |||||
// TODO: Remove this once the MySQL connector has proper support | |||||
Lint: TODO Comment: This comment has a TODO. | |||||
// for it, see T6710. | |||||
ini_set('mysql.connect_timeout', $spec['timeout']); | |||||
return PhabricatorEnv::newObjectFromConfig( | |||||
'mysql.implementation', | |||||
array( | |||||
$spec, | |||||
)); | )); | ||||
} | } | ||||
} | } |
This comment has a TODO.