// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/sentinel.c
// Function: sentinelFailoverWaitStart
void sentinelFailoverWaitStart(sentinelRedisInstance *ri) {
    char *leader;
    int isleader;

    /* Check if we are the leader for the failover epoch. */
    // 获取给定纪元的领头 Sentinel
    leader = sentinelGetLeader(ri, ri->failover_epoch);
    // 本 Sentinel 是否为领头 Sentinel ？
    isleader = leader && strcasecmp(leader,server.runid) == 0;
    sdsfree(leader);

    /* If I'm not the leader, and it is not a forced failover via
     * SENTINEL FAILOVER, then I can't continue with the failover. */
    // 如果本 Sentinel 不是领头，并且这次故障迁移不是一次强制故障迁移操作
    // 那么本 Sentinel 不做动作
    if (!isleader && !(ri->flags & SRI_FORCE_FAILOVER)) {
        int election_timeout = SENTINEL_ELECTION_TIMEOUT;

        /* The election timeout is the MIN between SENTINEL_ELECTION_TIMEOUT
         * and the configured failover timeout. */
        // 当选的时长（类似于任期）是 SENTINEL_ELECTION_TIMEOUT
        // 和 Sentinel 设置的故障迁移时长之间的较小那个值
        if (election_timeout > ri->failover_timeout)
            election_timeout = ri->failover_timeout;

        /* Abort the failover if I'm not the leader after some time. */
        // Sentinel 的当选时间已过，取消故障转移计划
        if (mstime() - ri->failover_start_time > election_timeout) {
            sentinelEvent(REDIS_WARNING,"-failover-abort-not-elected",ri,"%@");
            // 取消故障转移
            sentinelAbortFailover(ri);
        }
        return;
    }

    // 本 Sentinel 作为领头，开始执行故障迁移操作...

    sentinelEvent(REDIS_WARNING,"+elected-leader",ri,"%@");

    // 进入选择从服务器状态
    ri->failover_state = SENTINEL_FAILOVER_STATE_SELECT_SLAVE;
    ri->failover_state_change_time = mstime();

    sentinelEvent(REDIS_WARNING,"+failover-state-select-slave",ri,"%@");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x128(%rax), %rsi
callq 0x7ff10
movq %rax, -0x10(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x10(%rbp)
movb %al, -0x19(%rbp)
je 0x803ed
movq -0x10(%rbp), %rdi
leaq 0x9351d(%rip), %rsi     # 0x1138f8
addq $0x58, %rsi
callq 0x1f2f0
cmpl $0x0, %eax
sete %al
movb %al, -0x19(%rbp)
movb -0x19(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2c160
cmpl $0x0, -0x14(%rbp)
jne 0x8047f
movq -0x8(%rbp), %rax
movl (%rax), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
jne 0x8047f
movl $0x2710, -0x18(%rbp)    # imm = 0x2710
movslq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x148(%rcx), %rax
jle 0x8043d
movq -0x8(%rbp), %rax
movq 0x148(%rax), %rax
movl %eax, -0x18(%rbp)
callq 0x252e0
movq -0x8(%rbp), %rcx
subq 0x140(%rcx), %rax
movslq -0x18(%rbp), %rcx
cmpq %rcx, %rax
jle 0x8047d
movq -0x8(%rbp), %rdx
movl $0x3, %edi
leaq 0x69960(%rip), %rsi     # 0xe9dc6
leaq 0x68bc5(%rip), %rcx     # 0xe9032
movb $0x0, %al
callq 0x79b10
movq -0x8(%rbp), %rdi
callq 0x804f0
jmp 0x804dc
movq -0x8(%rbp), %rdx
movl $0x3, %edi
leaq 0x69953(%rip), %rsi     # 0xe9de2
leaq 0x68b9c(%rip), %rcx     # 0xe9032
movb $0x0, %al
callq 0x79b10
movq -0x8(%rbp), %rax
movl $0x2, 0x130(%rax)
callq 0x252e0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x138(%rax)
movq -0x8(%rbp), %rdx
movl $0x3, %edi
leaq 0x69924(%rip), %rsi     # 0xe9df2
leaq 0x68b5d(%rip), %rcx     # 0xe9032
movb $0x0, %al
callq 0x79b10
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)