Wednesday, June 28, 2017

How failover works on Google Cloud SQL?

Leave a Comment

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?

1 Answers

Answers 1

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.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment