Mysql – Slave DB promoted as Master DB when Master DB is down. New data added on the new master while old master is down

failoverMySQL

I am currently setting up a call center system (Vicidial) having a Master DB and a Slave DB.
When the Master would go down, I have made a script on the SlaveDB that would execute "stop slave" on the slave mysql service and make it as a new master by pointing the other servers (Web, Dialer, Archive) to the slave as their new Master database server.

When the master is up again, I would run another script on the SlaveDB that would point the servers back to the original MasterDB and would let the slave DB become slave again to the original MasterDB by executing "start slave".

My question is ~
If there are new data added on the New Master while the original master is down, how do I replicate this data to the original master when it goes back up before I start demoting the new master to slave again?

Answers and advice/constructive criticisms will be much appreciated.

P.S. I am a newbie in Databases and scripting.

Thanks in advance!

Best Answer

As @jkavalik said with your current setup the only option you have is to recreate the master as the slave of the new master and do a switchback if necessary.

Keep in mind that you will have some data loss because you can have some unreplicated transactions on the failed master unless you enable semi-sync replication.

Sidenote: you don't have to write your own scripts for moving/promoting slaves if you don't want to. There are plenty of open source solutions which can do this for you. For example you can give a try to orchestrator. I used this in production setup with over 4000 servers.

Jetpants is also a popular toolset developed by Tumblr which can also handle cloning and many other common tasks.

But there are also other solutions if you are not satisfied with these.

Further down the road

If you want to have better HA and/or more automated way of operation you can look at the following solution. (this list is not complete only some pointers to give you a start)

Percona XtraDB cluster

With XtraDB cluster you can ensure consistency and have true HA with even under 100ms failover time (depending on your failover technology).

MySQL Fabric

It's Oracle's in house HA solution. Requires client libraries so make sure your application can handle it properly.

MySQL MMM

One of the old player on the MySQL HA market but worth to mention.

I hope this helps.