Differential D20350 Diff 48586 src/aphront/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php
Changeset View
Changeset View
Standalone View
Standalone View
src/aphront/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php
Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | private function establishConnection() { | ||||
$profiler = PhutilServiceProfiler::getInstance(); | $profiler = PhutilServiceProfiler::getInstance(); | ||||
$call_id = $profiler->beginServiceCall( | $call_id = $profiler->beginServiceCall( | ||||
array( | array( | ||||
'type' => 'connect', | 'type' => 'connect', | ||||
'host' => $host, | 'host' => $host, | ||||
'database' => $database, | 'database' => $database, | ||||
)); | )); | ||||
$retries = max(1, $this->getConfiguration('retries', 3)); | // If we receive these errors, we'll retry the connection up to the | ||||
while ($retries--) { | // retry limit. For other errors, we'll fail immediately. | ||||
$retry_codes = array( | |||||
// "Connection Timeout" | |||||
2002 => true, | |||||
// "Unable to Connect" | |||||
2003 => true, | |||||
); | |||||
$max_retries = max(1, $this->getConfiguration('retries', 3)); | |||||
for ($attempt = 1; $attempt <= $max_retries; $attempt++) { | |||||
try { | try { | ||||
$conn = $this->connect(); | $conn = $this->connect(); | ||||
$profiler->endServiceCall($call_id, array()); | $profiler->endServiceCall($call_id, array()); | ||||
break; | break; | ||||
} catch (AphrontQueryException $ex) { | } catch (AphrontQueryException $ex) { | ||||
if ($retries && $ex->getCode() == 2003) { | $code = $ex->getCode(); | ||||
$class = get_class($ex); | if (($attempt < $max_retries) && isset($retry_codes[$code])) { | ||||
$message = $ex->getMessage(); | $message = pht( | ||||
phlog(pht('Retrying (%d) after %s: %s', $retries, $class, $message)); | 'Retrying database connection to "%s" after connection '. | ||||
'failure (attempt %d; "%s"; error #%d): %s', | |||||
$host, | |||||
$attempt, | |||||
get_class($ex), | |||||
$code, | |||||
$ex->getMessage()); | |||||
phlog($message); | |||||
} else { | } else { | ||||
$profiler->endServiceCall($call_id, array()); | $profiler->endServiceCall($call_id, array()); | ||||
throw $ex; | throw $ex; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
$this->connection = $conn; | $this->connection = $conn; | ||||
▲ Show 20 Lines • Show All 271 Lines • Show Last 20 Lines |