Question

I have a MySQL master-slave replication. Recently a server where mysql master is hosted - was rebooted due to some issues (not related with mysql). After the server got up I was totally unaware of the fact that the synchronization with slaves was broken (master log file name changed). We updated the master database structure, plus a lot of data changed. After ~24 hours we realized that slaves dont have the new data structure and new data. Synchronization is broken.

I'm now trying to fix it, but I'm wondering - why can't just slave instance automatically pick up where it was left when the master server was stopped (to whatever reason)? Why is it implemented such way that slave instances totally lose track of what's happening when master server is restarted?

Was it helpful?

Solution

The replica is supposed to recover, either if the replica or the master restarts.

The replica has a file in its data directory called relay-log.info that records the last event the replica processed. Most of the time, this works well, and a replica can resume where it left off.

However, a number of things can go wrong:

  • The relay-log.info can become corrupted if the replica crashes. For this reason, in MySQL 5.6, they now offer the option to store the same information in a crash-safe InnoDB table instead of in a file.

  • The replica can be offline for a long time. If the master purges the binary log file that the replica was reading from when it stopped, the replica can't continue. The replica needs to read a contiguous series of events, or else it can't assure full data replication.

  • The master might corrupt its binary log files if the master crashes. You can reduce this risk by enabling the sync-binlog configuration variable on the master, with the understanding that it decreases performance on the master.

As for "why is it implemented [in] such [a] way," why don't you try implementing a replication system that can recover from crashes, and see how easy it is? :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top