Skip to content
bmildren edited this page Jan 27, 2016 · 1 revision

Architecture of MHA

When a master crashes, MHA recovers rest slaves as below.

http://4.bp.blogspot.com/-AIInutsrkAk/TiF5kAcIzQI/AAAAAAAAAFg/jW1SnzM8T_E/s600/mha_recovery_procedure.png

Fig: Steps for recovery

Basic algorithms are described in the slides presented at the MySQL Conference and Expo 2011, especially from page no.13 to no.34.

In relay log files on slaves, master's binary log positions are written at "end_log_pos" sections (example). By comparing the latest end_log_pos between slaves, we can identify which relay log events are not sent to each slave. MHA internally recovers slaves (fixes consistency issues) by using this mechanism. In addition to basic algorithms covered in the slides at the MySQL Conf 2011, MHA does some optimizations and enhancements, such as generating differential relay logs very quickly (indenpendent from relay log file size), making recovery work with row based formats, etc.

MHA Components

MHA consists of MHA Manager and MHA Node as below.

http://1.bp.blogspot.com/-wCKF5uopGNI/TiF4dA2df6I/AAAAAAAAAFY/AHScjL84JF4/s600/components_of_mha.png

Fig: MHA components

MHA Manager has manager programs such as monitoring MySQL master, controlling master failover, etc.

MHA Node has failover helper scripts such as parsing MySQL binary/relay logs, identifying relay log position from which relay logs should be applied to other slaves, applying events to the target slave, etc. MHA Node runs on each MySQL server.

When MHA Manager does failover, MHA manager connects MHA Node via SSH and executes MHA Node commands when needed.

Custom Extensions

MHA has a couple of extention points. For example, MHA can call any custom script to update master's ip address (updating global catalog database that manages master's ip address, updating virtual ip, etc). This is because how to manage IP address depends on users' environments and MHA does not want to force one approach.

Current extension points are as below. MHA Manager package includes sample scripts.

Clone this wiki locally