def stop_replication(instance, thread_type=REPLICATION_THREAD_ALL):
""" Stop replication, if running
Args:
instance - A hostAddr object
thread - Which thread to stop. Options are in REPLICATION_THREAD_TYPES.
"""
if thread_type not in REPLICATION_THREAD_TYPES:
raise Exception('Invalid input for arg thread: {thread}'
''.format(thread=thread_type))
conn = connect_mysql(instance)
cursor = conn.cursor()
ss = get_slave_status(instance)
if (ss['Slave_IO_Running'] != 'No' and ss['Slave_SQL_Running'] != 'No' and
thread_type == REPLICATION_THREAD_ALL):
cmd = 'STOP SLAVE'
elif ss['Slave_IO_Running'] != 'No' and thread_type != REPLICATION_THREAD_SQL:
cmd = 'STOP SLAVE IO_THREAD'
elif ss['Slave_SQL_Running'] != 'No' and thread_type != REPLICATION_THREAD_IO:
cmd = 'STOP SLAVE SQL_THREAD'
else:
log.info('Replication already stopped')
return
warnings.filterwarnings('ignore', category=MySQLdb.Warning)
log.info(cmd)
cursor.execute(cmd)
warnings.resetwarnings()
评论列表
文章目录