mysqlops.py 文件源码

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

项目:ops 作者: xiaomatech 项目源码 文件源码
def start_replication(instance, thread_type=REPLICATION_THREAD_ALL):
    """ Start replication, if not running

    Args:
    instance - A hostAddr object
    thread - Which thread to start. 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'] != 'Yes' and
            ss['Slave_SQL_Running'] != 'Yes' and
            thread_type == REPLICATION_THREAD_ALL):
        cmd = 'START SLAVE'
    elif ss['Slave_IO_Running'] != 'Yes' and thread_type != REPLICATION_THREAD_SQL:
        cmd = 'START SLAVE IO_THREAD'
    elif ss['Slave_SQL_Running'] != 'Yes' and thread_type != REPLICATION_THREAD_IO:
        cmd = 'START SLAVE SQL_THREAD'
    else:
        log.info('Replication already running')
        return

    warnings.filterwarnings('ignore', category=MySQLdb.Warning)
    log.info(cmd)
    cursor.execute(cmd)
    warnings.resetwarnings()
    time.sleep(1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号