I'm mysql newbie.
when it comes to fail-over, which slave should be promoted to the new master?
For example, A is master, B and C are slaves, and A does async replication to B and C.
At some point of time, B receives more data from A than C, A crashes.
If we promote C to new master, and changes B's master to C, then what happens to B? It truncates its data to match C?
Obviously, B is the best new master candidate, but my question is, how to determine this fact?
From the MySQL documentation, there two ways to set up a master-slave architecture. The traditional way, using the log files to replicate transactions and the new version (5.6+) using GTIDs (global transaction identifiers).
If you choose to use GTIDs to make the failover handling you will use the mysqlfailover utility. The utility handles fails of master in one of three ways defined by the database administrator:
The traditional way requires that you implement your own script to database management and is better explained here.
The
Relay_Master_Log_File
andExec_Master_Log_Pos
inSHOW SLAVE STATUS
is used to determine the best slave as new master: the bigger values win.Without GTID, I think we must first sync other slaves with the best slave we chose. The obvious sync source is the relay logs. On each slave, determine the differences of relay log from the best slave, download those files and replay the SQL statements. Once all slaves catch up, the slaves could
CHANGE MASTER TO
the best slave. TheMASTER_LOG_FILE
andMASTER_LOG_POS
would be the tail of the last binlog on the best slave.With GTID, it's very simple: just
CHANGE MASTER TO
withMASTER_AUTO_POSITION=1
.