// File: /workspace/github_c_makefile_star2_O3/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 %r12
pushq %rbx
movq 0x8a7cf(%rip), %rax     # 0xde628
xorl %ebx, %ebx
testb $0x2, 0x30(%rax)
jne 0x53f5c
leaq 0x7613c(%rip), %r12     # 0xc9fa8
movslq 0x480(%r12), %rax
cmpq $0x1, %rax
jle 0x53ea3
movq 0x10(%r12), %rcx
shlq $0x6, %rax
movl $0x40, %edx
movq (%rcx,%rdx), %rsi
movq 0x28(%rsi), %rdi
addq 0x48(%rsi), %rdi
jne 0x53f57
addq $0x40, %rdx
cmpq %rdx, %rax
jne 0x53e88
leaq 0x48959(%rip), %rbx     # 0x9c803
leaq 0x4899c(%rip), %r14     # 0x9c84d
xorl %r15d, %r15d
xorl %ebp, %ebp
movl %r15d, %edi
callq 0x334b8
testl %eax, %eax
je 0x53f35
movq 0x7d0(%r12), %rcx
movq 0x40028(%rcx,%r15,8), %rax
cmpq 0x8a74f(%rip), %rax     # 0xde628
je 0x53f35
cmpq $0x0, 0x20028(%rcx,%r15,8)
jne 0x53f35
incl %ebp
movl $0x3, %edi
testq %rax, %rax
je 0x53f19
movq %r14, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x23223
movq 0x7d0(%r12), %rax
movq 0x40028(%rax,%r15,8), %rcx
movq %rcx, 0x20028(%rax,%r15,8)
jmp 0x53f35
movq %rbx, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x23223
movq 0x8a6fb(%rip), %rdi     # 0xde628
movl %r15d, %esi
callq 0x4ff93
incq %r15
cmpq $0x4000, %r15           # imm = 0x4000
jne 0x53eb6
xorl %ebx, %ebx
testl %ebp, %ebp
je 0x53f5c
movl $0x1, %edi
callq 0x501ce
jmp 0x53f5c
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq