eee
This commit is contained in:
+19
-10
@@ -124,14 +124,14 @@ class Connection extends Component
|
||||
*/
|
||||
protected function checkClientHealth(Pool $pool): void
|
||||
{
|
||||
$pool->flush('mysql.' . $this->cds, $this->pool['min'] ?? 1);
|
||||
$length = $pool->size('mysql.' . $this->cds);
|
||||
$pool->flush($this->getName(), $this->pool['min'] ?? 1);
|
||||
$length = $pool->size($this->getName());
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
try {
|
||||
if (($client = $this->validator($pool)) === false) {
|
||||
break;
|
||||
}
|
||||
$pool->push('mysql.' . $this->cds, $client);
|
||||
$pool->push($this->getName(), $client);
|
||||
} catch (\Throwable $exception) {
|
||||
if (!str_contains($exception->getMessage(), 'Client timeout.')) {
|
||||
$this->logger->error(throwable($exception), [$this->cds]);
|
||||
@@ -141,6 +141,15 @@ class Connection extends Component
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getName(): string
|
||||
{
|
||||
return 'mysql.' . $this->cds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Pool $pool
|
||||
* @return PDO|bool
|
||||
@@ -149,7 +158,7 @@ class Connection extends Component
|
||||
protected function validator(Pool $pool): PDO|bool
|
||||
{
|
||||
/** @var $client PDO */
|
||||
if (($client = $pool->get('mysql.' . $this->cds)) === false) {
|
||||
if (($client = $pool->get($this->getName())) === false) {
|
||||
return false;
|
||||
}
|
||||
if ($client->query('select 1') === false) {
|
||||
@@ -179,7 +188,7 @@ class Connection extends Component
|
||||
*/
|
||||
protected function getNormalClientHealth(): PDO
|
||||
{
|
||||
$data = $this->pool()->get('mysql.' . $this->cds, $this->waite_time);
|
||||
$data = $this->pool()->get($this->getName(), $this->waite_time);
|
||||
if ($data === false) {
|
||||
throw new Exception('Client Waite timeout.');
|
||||
}
|
||||
@@ -305,7 +314,7 @@ class Connection extends Component
|
||||
public function release(PDO $pdo): void
|
||||
{
|
||||
if (!$this->inTransaction()) {
|
||||
$this->pool()->push('mysql.' . $this->cds, $pdo);
|
||||
$this->pool()->push($this->getName(), $pdo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,7 +326,7 @@ class Connection extends Component
|
||||
*/
|
||||
public function clear_connection(): void
|
||||
{
|
||||
$this->pool()->flush('mysql.' . $this->cds, 0);
|
||||
$this->pool()->flush($this->getName(), 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -329,7 +338,7 @@ class Connection extends Component
|
||||
if ($this->timerId > -1) {
|
||||
Timer::clear($this->timerId);
|
||||
}
|
||||
$this->pool()->close('mysql.' . $this->cds);
|
||||
$this->pool()->close($this->getName());
|
||||
}
|
||||
|
||||
|
||||
@@ -360,8 +369,8 @@ class Connection extends Component
|
||||
*/
|
||||
protected function pool(): Pool
|
||||
{
|
||||
if (!$this->connections->hasChannel('mysql.' . $this->cds)) {
|
||||
$this->connections->created('mysql.' . $this->cds, $this->pool['max'] ?? 1, [$this, 'newConnect']);
|
||||
if (!$this->connections->hasChannel($this->getName())) {
|
||||
$this->connections->created($this->getName(), $this->pool['max'] ?? 1, [$this, 'newConnect']);
|
||||
}
|
||||
return $this->connections;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user