From 3345ff697b764de7fb8f2d66b8e374c871035bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 5 Jul 2021 16:31:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/Connection.php | 7 +++++-- System/Pool/ClientsPool.php | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Database/Connection.php b/Database/Connection.php index 380d53d9..4e0e5a39 100644 --- a/Database/Connection.php +++ b/Database/Connection.php @@ -194,6 +194,9 @@ class Connection extends Component if (empty($this->slaveConfig) || Db::transactionsActive()) { return $this->masterInstance(); } + if ($this->slaveConfig['cds'] == $this->cds) { + return $this->masterInstance(); + } return $this->connections()->get($this->slaveConfig, false); } @@ -298,9 +301,9 @@ class Connection extends Component /** * @param $dbname * @param $sql - * @return array|string|string[]|null + * @return array|string|null */ - private function selectMatch($dbname, $sql) + private function selectMatch($dbname, $sql): array|string|null { return preg_replace('/FROM\s+(\w+)\s+/', 'FROM `' . $dbname . '`.$1 ', $sql); } diff --git a/System/Pool/ClientsPool.php b/System/Pool/ClientsPool.php index 94687995..e8b6c5bf 100644 --- a/System/Pool/ClientsPool.php +++ b/System/Pool/ClientsPool.php @@ -92,7 +92,8 @@ class ClientsPool extends Component $this->flush($channel, $min); } $num[$key] += $channel->length(); - if (str_starts_with($key, 'Mysql') && (Snowflake::isWorker() || Snowflake::isTask())) { + if (str_starts_with($key, 'Mysql') && (Snowflake::isWorker() || Snowflake::isTask()) + && $channel->length() > 0) { $this->debug('Worker #' . env('worker') . ' use client -> ' . $key . ':' . $total); } $total += $channel->length();