def pre_check(): global error_code # ##################先预检,判断当前复制拓补是否为一主两从,两个从库是否存在slave线程(SQL,IO任一)停止的情况########### (master_host_N, master_port_N, new_master_io_file, new_master_io_pos, new_master_sql_file, new_master_sql_pos) = print_slave_status(new_master) (master_host_S, master_port_S, slave_io_file, slave_io_pos, slave_sql_file, slave_sql_pos) = print_slave_status(slave) (io_thread_running_n, sql_thread_running_n) = print_rep_info(new_master) (io_thread_running_s, sql_thread_running_s) = print_rep_info(slave) print('########################预检模块开始###########################') if master_host_N == master_host_S and master_port_N == master_port_S \ and io_thread_running_n == 'Yes' and io_thread_running_n == 'Yes' \ and io_thread_running_s == 'Yes' and io_thread_running_s == 'Yes': print('复制链路正确,slave线程全部running') print('master_port_N:', master_port_N, 'master_port_S:', master_port_S) else: error_code = 'pre_check' raise Exception
def after_change(): global error_code try: time.sleep(3) slave = pymysql.Connect(host=slave_host, port=slave_port, user=opreate_user, passwd=opreate_password) # ###游标 cursor_slave = slave.cursor() (master_host_S, master_port_S, a, b, c, d) = print_slave_status(slave) (io_thread_running_s, sql_thread_running_s) = print_rep_info(slave) if master_port_S == new_master_host and master_port_S == new_master_port \ and io_thread_running_s == 'Yes' and io_thread_running_s == 'Yes': print('change OK,slave running!!!') except Exception: error_code = 'after_change' raise Exception
user=opreate_user, passwd=opreate_password) slave = pymysql.Connect(host=slave_host, port=slave_port, user=opreate_user, passwd=opreate_password) master = pymysql.Connect(host=master_host, port=master_port, user=opreate_user, passwd=opreate_password) (master_host_N, master_port_N, new_master_io_file, new_master_io_pos, new_master_sql_file, new_master_sql_pos) = print_slave_status(new_master) (master_host_S, master_port_S, slave_io_file, slave_io_pos, slave_sql_file, slave_sql_pos) = print_slave_status(slave) (io_thread_running_n, sql_thread_running_n) = print_rep_info(new_master) (io_thread_running_s, sql_thread_running_s) = print_rep_info(slave) # 预检模块 def pre_check(): global error_code # ##################先预检,判断当前复制拓补是否为一主两从,两个从库是否存在slave线程(SQL,IO任一)停止的情况########### (master_host_N, master_port_N, new_master_io_file, new_master_io_pos, new_master_sql_file, new_master_sql_pos) = print_slave_status(new_master) (master_host_S, master_port_S, slave_io_file, slave_io_pos, slave_sql_file, slave_sql_pos) = print_slave_status(slave) (io_thread_running_n, sql_thread_running_n) = print_rep_info(new_master) (io_thread_running_s, sql_thread_running_s) = print_rep_info(slave) print('########################预检模块开始###########################')