yoshinorim / mha4mysql-manager

Development tree of Master High Availability Manager and tools for MySQL (MHA), Manager part
http://code.google.com/p/mysql-master-ha/
GNU General Public License v2.0
1.47k stars 501 forks source link

fix online_switch_mysql caused data inconsistency #86

Closed kobehaha closed 6 years ago

kobehaha commented 6 years ago

Our company use mha for mysql HA solution , but we find online_switch_mysql node will missing data for new master , some data is keep in origin master, cousing new master slave replication error. And we find the result is that when switch_mysql , mha will lock tables , but it it not read_only, when unlocking tables does, origin master will continuous excute sql which is bolocked by lock tables, So If I set read_only before locking tables, all works well.

yoshinorim commented 6 years ago

MHA has an extension called master_ip_online_change_script (https://github.com/yoshinorim/mha4mysql-manager/wiki/Parameters#master_ip_online_change_script), so that you can do whatever to refuse to update on source master there. The script is called before executing FLUSH TABLES WITH READ LOCK section. So by executing SET GLOBAL read_only=1 in the script, you can refuse all updates (except from SUPER users), without losing consistency.

You can also skip calling expensive FLUSH TABLES WITH READ LOCK, by passing --skip_lock_all_tables from masterha_master_switch.

kobehaha commented 6 years ago

Thanks for you reply, it is my fault to ignore this feature about MHA. But I keep my point , I also think setting READ ONLY is necessary before origin master executing FLASH TABLES WITH READ LOCK.This is better to reduce other operation.