MyCAT for MySQL HA
MyCAT is middleware at the proxy layer. The high availability (HA) of the MyCAT system involves the HA of MyCAT itself and that of MySQL at the back end. The MySQL HA solution can be used to ensure the availability of the back-end MySQL service connected to MyCAT. In most cases, you are advised to use the standard MySQL primary-secondary replication HA configuration and use MyCAT to implement automatic primary/secondary switchover of back-end MySQL nodes.
In the figure above, writeHost indicates the primary node, and readHost indicates the secondary node. MyCAT periodically detects heartbeats of all writeHosts and readHosts in a dataHost. If multiple writeHosts are configured in a dataHost and the first writeHost fails, MyCAT automatically switches to the next available writeHost after the heartbeat detection fails for three times (default), and records the index of the current writeHost in the conf/dnindex.properties file. MyCAT only distributes SQL statements. The proactive synchronization of data sources depends on the functions of the MySQL database. If data consistency is strongly required, you are advised to set switchType to 2. After the first MySQL writeHost recovers, it functions as a secondary node in MyCAT and primary-secondary synchronization is reconfigured.