MySQL for the Internet of Things

(Steven Felgate) #1

ChapTEr 8 ■ DEmonsTraTion of high availabiliTy TEChniquEs


a slave to the topology after the new master takes over. It should be noted here that this is not possible unless
you set up the master like a slave (with report-host, report-port, and master-into-repository). You can
see the results at the end of the listing where the utility prints out a health report for the new topology. Here
you see the original master (on port 13001) is now a slave.


Failover


Failover is a situation where the master has failed in some manner and you need to automatically
reconfigure the topology to recover the master role. Prior to the use of GTIDs, automatic failover was
problematic at best and unreliable for all but the simplest of cases.
To perform failover with GTIDs, we choose the best slave (the one with the least missing events and
the hardware that matches the master best) and make it a slave of every other slave (also called slave
promotion). We call this slave the candidate slave. The GTID mechanism will ensure only those events that
have not been executed on the candidate slave are applied. In this way, the candidate slave becomes the
most up-to-date and therefore a replacement for the master.
Once again, you can use MySQL Utilities to watch the master and automatically promote one of the
slaves to the new master. The mysqlfailover command-line tool performs automatic failover by executing
the previous sequence of events and takes care of redirecting the remaining slaves to the new master.
Figures 8-1 through 8-3 show a series of screenshots taken of the utility. The first shows the utility in
monitoring mode.


Figure 8-1. Automatic failover with mysqlfailover (before failover)


Notice the utility displays a number of statistics including the current health report of all the servers in
the topology. The utility works by checking the state of the master at a specified interval. In this example,
I used an interval of 30 seconds. To simulate the master failing, I killed the master process. Figure 8-2 shows
the utility detecting the failure and executing automatic failover.

Free download pdf