数据库
首页 > 数据库> > Redis源码分析--Sentinel(5)故障转移状态机md

Redis源码分析--Sentinel(5)故障转移状态机md

作者:互联网

故障转移状态机:

一、状态机函数sentinelFailoverStateMachine:

​ 终于进入故障转移,先看一下状态机函数:

void sentinelFailoverStateMachine(sentinelRedisInstance *ri) {
    redisAssert(ri->flags & SRI_MASTER);

    /* 如果机器不在故障转移状态,直接退出 */
    if (!(ri->flags & SRI_FAILOVER_IN_PROGRESS)) return;

    switch(ri->failover_state) {
        case SENTINEL_FAILOVER_STATE_WAIT_START:
            /* 判断本sentinel是否为leader */
            sentinelFailoverWaitStart(ri);
            break;
        case SENTINEL_FAILOVER_STATE_SELECT_SLAVE:
            /* 选择从服务器作为新的主服务器 */
            sentinelFailoverSelectSlave(ri);
            break;
        case SENTINEL_FAILOVER_STATE_SEND_SLAVEOF_NOONE:
            /* 向被选中的从服务器发送SLAVEOF no one */
            sentinelFailoverSendSlaveOfNoOne(ri);
            break;
        case SENTINEL_FAILOVER_STATE_WAIT_PROMOTION:
            /* 观察被选中的从服务器是否被升级为主服务器 */
            sentinelFailoverWaitPromotion(ri);
            break;
        case SENTINEL_FAILOVER_STATE_RECONF_SLAVES:
            /* 让原来的slave跟随新的master 
             * ri是当前master,新的master是ri->promoted_slave */
            sentinelFailoverReconfNextSlave(ri);
            break;
    }
}

标签:case,md,FAILOVER,状态机,STATE,源码,break,SENTINEL,ri
来源: https://www.cnblogs.com/macguz/p/15865720.html