// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/sentinel.c
// Function: sentinelSendPeriodicCommands
void sentinelSendPeriodicCommands(sentinelRedisInstance *ri) {
    mstime_t now = mstime();
    mstime_t info_period, ping_period;
    int retval;

    /* Return ASAP if we have already a PING or INFO already pending, or
     * in the case the instance is not properly connected. */
    // 函数不能在网络连接未创建时执行
    if (ri->flags & SRI_DISCONNECTED) return;

    /* For INFO, PING, PUBLISH that are not critical commands to send we
     * also have a limit of SENTINEL_MAX_PENDING_COMMANDS. We don't
     * want to use a lot of memory just because a link is not working
     * properly (note that anyway there is a redundant protection about this,
     * that is, the link will be disconnected and reconnected if a long
     * timeout condition is detected. */
    // 为了避免 sentinel 在实例处于不正常状态时，发送过多命令
    // sentinel 只在待发送命令的数量未超过 SENTINEL_MAX_PENDING_COMMANDS 常量时
    // 才进行命令发送
    if (ri->pending_commands >= SENTINEL_MAX_PENDING_COMMANDS) return;

    /* If this is a slave of a master in O_DOWN condition we start sending
     * it INFO every second, instead of the usual SENTINEL_INFO_PERIOD
     * period. In this state we want to closely monitor slaves in case they
     * are turned into masters by another Sentinel, or by the sysadmin. */
    // 对于从服务器来说， sentinel 默认每 SENTINEL_INFO_PERIOD 秒向它发送一次 INFO 命令
    // 但是，当从服务器的主服务器处于 SDOWN 状态，或者正在执行故障转移时
    // 为了更快速地捕捉从服务器的变动， sentinel 会将发送 INFO 命令的频率该为每秒一次
    if ((ri->flags & SRI_SLAVE) &&
        (ri->master->flags & (SRI_O_DOWN|SRI_FAILOVER_IN_PROGRESS))) {
        info_period = 1000;
    } else {
        info_period = SENTINEL_INFO_PERIOD;
    }

    /* We ping instances every time the last received pong is older than
     * the configured 'down-after-milliseconds' time, but every second
     * anyway if 'down-after-milliseconds' is greater than 1 second. */
    ping_period = ri->down_after_period;
    if (ping_period > SENTINEL_PING_PERIOD) ping_period = SENTINEL_PING_PERIOD;

    // 实例不是 Sentinel （主服务器或者从服务器）
    // 并且以下条件的其中一个成立：
    // 1）SENTINEL 未收到过这个服务器的 INFO 命令回复
    // 2）距离上一次该实例回复 INFO 命令已经超过 info_period 间隔
    // 那么向实例发送 INFO 命令
    if ((ri->flags & SRI_SENTINEL) == 0 &&
        (ri->info_refresh == 0 ||
        (now - ri->info_refresh) > info_period))
    {
        /* Send INFO to masters and slaves, not sentinels. */
        retval = redisAsyncCommand(ri->cc,
            sentinelInfoReplyCallback, NULL, "INFO");
        if (retval == REDIS_OK) ri->pending_commands++;
    } else if ((now - ri->last_pong_time) > ping_period) {
        /* Send PING to all the three kinds of instances. */
        sentinelSendPing(ri);
    } else if ((now - ri->last_pub_time) > SENTINEL_PUBLISH_PERIOD) {
        /* PUBLISH hello messages to all the three kinds of instances. */
        sentinelSendHello(ri);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
callq 0x252e0
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x7e288
jmp 0x7e397
movq -0x8(%rbp), %rax
cmpl $0x64, 0x38(%rax)
jl 0x7e297
jmp 0x7e397
movq -0x8(%rbp), %rax
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x7e2c6
movq -0x8(%rbp), %rax
movq 0xf8(%rax), %rax
movl (%rax), %eax
andl $0xa0, %eax
cmpl $0x0, %eax
je 0x7e2c6
movq $0x3e8, -0x18(%rbp)     # imm = 0x3E8
jmp 0x7e2ce
movq $0x2710, -0x18(%rbp)    # imm = 0x2710
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x3e8, -0x20(%rbp)     # imm = 0x3E8
jle 0x7e2ef
movq $0x3e8, -0x20(%rbp)     # imm = 0x3E8
movq -0x8(%rbp), %rax
movl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x7e359
movq -0x8(%rbp), %rax
cmpq $0x0, 0xa0(%rax)
je 0x7e320
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
subq 0xa0(%rcx), %rax
cmpq -0x18(%rbp), %rax
jle 0x7e359
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
leaq -0x7ff(%rip), %rsi      # 0x7db30
xorl %eax, %eax
movl %eax, %edx
leaq 0x674b1(%rip), %rcx     # 0xe57eb
movb $0x0, %al
callq 0x86730
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x7e357
movq -0x8(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x38(%rax)
jmp 0x7e397
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
subq 0x68(%rcx), %rax
cmpq -0x20(%rbp), %rax
jle 0x7e376
movq -0x8(%rbp), %rdi
callq 0x7cd30
jmp 0x7e395
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
subq 0x70(%rcx), %rax
cmpq $0x7d0, %rax            # imm = 0x7D0
jle 0x7e393
movq -0x8(%rbp), %rdi
callq 0x7e0c0
jmp 0x7e395
jmp 0x7e397
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)