code reading https://code.google.com/p/mysql-master-ha/