Google Cloud SQL如何进行故障转移? [英] How failover works on Google Cloud SQL?

查看:113
本文介绍了Google Cloud SQL如何进行故障转移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算将一个PHP应用程序(从Googel Cloud Platform之外的服务器)连接到Google Cloud SQL。我想知道如何设计应用程序以正确地故障转移数据库。



根据 manual b
$ b


主站故障切换到您的故障切换
副本,任何现有的到该实例的连接都将关闭。但是,
您的应用程序可以使用相同的连接字符串或IP
地址重新连接;您不需要在故障转移后更新您的应用程序。


看起来一切都在幕后自动发生,但如果IP地址数据库出现或超时? 解决方案

Google不会透露这里后端是用来提供数据库服务的,但我的假设是:




  • 它使用将流量路由到主连接器的虚拟IP,因此,当主站发生故障时,备份将开始通告虚拟IP,这会导致您的TCP连接失败。 / li>


该注释表示如果中的 mysqli.reconnect 必须启用php.ini 以允许您的PHP代码在发生故障时自动连接到备份MySQL连接器。 在这里阅读



如果启用了mysqli.reconnect,那么您不必担心任何操作。



编辑:回答有关SQL Transaction的问题 - 当然,如果SQL事务代码没有写在预防措施中,连接可能在事务中的任何时候断开连接,那么这将是一团糟,这种情况必须在代码中处理。当启用自动提交并且您不在事务中时,简单的自动重新连接可以解决几乎所有其他情况。


I intend to connect a PHP app (from a server outside Googel Cloud Platform) to Google Cloud SQL. I want to know how can I design the app to failover its database properly.

According to the manual:

When a zonal outage occurs and your master fails over to your failover replica, any existing connections to the instance are closed. However, your application can reconnect using the same connection string or IP address; you do not need to update your application after a failover.

It appears everything is happenning automatically behind the scenes but what if the IP address of the database is out or times out?

解决方案

Google doesn't reveal here what back-end is using to provide database service but my assumption is:

  • It is using a virtual IP that are routing traffic to master connector, therefore when master fails the backup would start to advertise the virtual IP, this would cause your TCP connection fails.

The comment means if your mysqli.reconnect in php.ini must be enabled to allow your PHP code automatically connect to the backup MySQL connector when failure occurs. read here

If your mysqli.reconnect is enabled then you don't have to worry about anything.

Edit: in reply to question raised regarding SQL Transaction -- Of course it will be a mess if the SQL transaction code is not written with a precaution that connection may disconnect at any time during transaction, such scenario must be handled in code. and when auto-commit is enabled and you are not within a transaction a simple auto-reconnect would solve almost any other scenario.

这篇关于Google Cloud SQL如何进行故障转移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆