AWS Aurora自动扩展组db shutdown导致mysql服务器消失问题

问题描述 投票:0回答:1

我正在使用AWS Aurora和自动扩展组来添加/删除基于CPU的数据库从属。一天几次,我得到“一般错误:2006 MySQL服务器已经消失”。我已经将此问题缩小到这样一个事实,即当从自动缩放组中删除数据库时,会抛出此异常。我在local.xml文件中使用只读集群端点作为核心读取选项。

关于如何解决此问题的任何想法,以便一旦确定数据库不再存在,连接会自动尝试重新连接?

我正在使用Magento 1.9.2.4

mysql amazon-web-services magento-1.9 amazon-rds-aurora
1个回答
0
投票

所以这是我目前的解决方案。我制作了lib / Varien / Db / Adapter / Pdo / Mysql.php的副本并创建了一个新文件app / code / local / Varien / Db / Adapter / Pdo / Mysql.php。

我修改了查询功能。

更改:

$result = parent::query($sql, $bind);

至:


$tries = 0;
do {
    $retry = false;
    try {
        $result = parent::query($sql, $bind);
    } catch (Exception $e) {
        // Check to reconnect
        if($tries < 3 && stristr($e->getMessage(), '2006 MySQL server has gone away')) {
            $retry = true;
            $tries++;
            $this->_connection = null;  // Kill the current connection to the scaled out db
            $this->_connect(); // Reconnect to an available db
        } else {
            throw $e;
        }
    }
} while ($retry);
© www.soinside.com 2019 - 2024. All rights reserved.