mysqlops.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:ops 作者: xiaomatech 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号