// File: /workspace/github_c_makefile_star2_O2/nilyang[P]redis-tdd-annotation/src/cluster.c
// Function: verifyClusterConfigWithData
int verifyClusterConfigWithData(void) {
    int j;
    int update_config = 0;

    /* If this node is a slave, don't perform the check at all as we
     * completely depend on the replication stream. */
    // 不对从节点进行检查
    if (nodeIsSlave(myself)) return REDIS_OK;

    /* Make sure we only have keys in DB0. */
    // 确保只有 0 号数据库有数据
    for (j = 1; j < server.dbnum; j++) {
        if (dictSize(server.db[j].dict)) return REDIS_ERR;
    }

    /* Check that all the slots we see populated memory have a corresponding
     * entry in the cluster table. Otherwise fix the table. */
    // 检查槽表是否都有相应的节点，如果不是的话，进行修复
    for (j = 0; j < REDIS_CLUSTER_SLOTS; j++) {
        if (!countKeysInSlot(j)) continue; /* No keys in this slot. */
        /* Check if we are assigned to this slot or if we are importing it.
         * In both cases check the next slot as the configuration makes
         * sense. */
        // 跳过正在导入的槽
        if (server.cluster->slots[j] == myself ||
            server.cluster->importing_slots_from[j] != NULL) continue;

        /* If we are here data and cluster config don't agree, and we have
         * slot 'j' populated even if we are not importing it, nor we are
         * assigned to this slot. Fix this condition. */

        update_config++;
        /* Case A: slot is unassigned. Take responsability for it. */
        if (server.cluster->slots[j] == NULL) {
            // 处理未被接受的槽
            redisLog(REDIS_WARNING, "I've keys about slot %d that is "
                                    "unassigned. Taking responsability "
                                    "for it.",j);
            clusterAddSlot(myself,j);
        } else {
            // 如果一个槽已经被其他节点接管
            // 那么将槽中的资料发送给对方
            redisLog(REDIS_WARNING, "I've keys about slot %d that is "
                                    "already assigned to a different node. "
                                    "Setting it in importing state.",j);
            server.cluster->importing_slots_from[j] = server.cluster->slots[j];
        }
    }

    // 保存 nodes.conf 文件
    if (update_config) clusterSaveConfigOrDie(1);

    return REDIS_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x8bb90(%rip), %rax     # 0xdb628
xorl %ebx, %ebx
testb $0x2, 0x30(%rax)
jne 0x4fb97
leaq 0x774fd(%rip), %r12     # 0xc6fa8
movslq 0x480(%r12), %rax
movq 0x10(%r12), %rcx
addq $0x40, %rcx
xorl %edx, %edx
pushq $-0x1
popq %rbx
incq %rdx
cmpq %rax, %rdx
jge 0x4fadf
movq (%rcx), %rsi
addq $0x40, %rcx
movq 0x28(%rsi), %rdi
addq 0x48(%rsi), %rdi
je 0x4fac1
jmp 0x4fb97
leaq 0x42cdd(%rip), %rbx     # 0x927c3
pushq $0x3
popq %rbp
leaq 0x42d1d(%rip), %r14     # 0x9280d
xorl %r15d, %r15d
xorl %r13d, %r13d
cmpq $0x4000, %r15           # imm = 0x4000
je 0x4fb88
movl %r15d, %edi
callq 0x31376
testl %eax, %eax
je 0x4fb80
movq 0x7d0(%r12), %rcx
movq 0x40028(%rcx,%r15,8), %rax
cmpq 0x8bb02(%rip), %rax     # 0xdb628
je 0x4fb80
cmpq $0x0, 0x20028(%rcx,%r15,8)
jne 0x4fb80
incl %r13d
movl %ebp, %edi
testq %rax, %rax
je 0x4fb64
movq %r14, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x22613
movq 0x7d0(%r12), %rax
movq 0x40028(%rax,%r15,8), %rcx
movq %rcx, 0x20028(%rax,%r15,8)
jmp 0x4fb80
movq %rbx, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x22613
movq 0x8bab0(%rip), %rdi     # 0xdb628
movl %r15d, %esi
callq 0x4c00b
incq %r15
jmp 0x4faf6
xorl %ebx, %ebx
testl %r13d, %r13d
je 0x4fb97
pushq $0x1
popq %rdi
callq 0x4c218
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq