// File: /workspace/github_c_makefile_star2_O1/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 0x8a222(%rip), %rax     # 0xde628
xorl %ebx, %ebx
testb $0x2, 0x30(%rax)
jne 0x54509
leaq 0x75b8f(%rip), %r12     # 0xc9fa8
movslq 0x480(%r12), %rax
cmpq $0x1, %rax
jle 0x54450
movq 0x10(%r12), %rcx
shlq $0x6, %rax
movl $0x40, %edx
movq (%rcx,%rdx), %rsi
movq 0x28(%rsi), %rdi
addq 0x48(%rsi), %rdi
jne 0x54504
addq $0x40, %rdx
cmpq %rdx, %rax
jne 0x54435
leaq 0x4836c(%rip), %rbx     # 0x9c7c3
leaq 0x483af(%rip), %r14     # 0x9c80d
xorl %r15d, %r15d
xorl %ebp, %ebp
movl %r15d, %edi
callq 0x33030
testl %eax, %eax
je 0x544e2
movq 0x7d0(%r12), %rcx
movq 0x40028(%rcx,%r15,8), %rax
cmpq 0x8a1a2(%rip), %rax     # 0xde628
je 0x544e2
cmpq $0x0, 0x20028(%rcx,%r15,8)
jne 0x544e2
incl %ebp
movl $0x3, %edi
testq %rax, %rax
je 0x544c6
movq %r14, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x23064
movq 0x7d0(%r12), %rax
movq 0x40028(%rax,%r15,8), %rcx
movq %rcx, 0x20028(%rax,%r15,8)
jmp 0x544e2
movq %rbx, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x23064
movq 0x8a14e(%rip), %rdi     # 0xde628
movl %r15d, %esi
callq 0x50552
incq %r15
cmpq $0x4000, %r15           # imm = 0x4000
jne 0x54463
xorl %ebx, %ebx
testl %ebp, %ebp
je 0x54509
movl $0x1, %edi
callq 0x50787
jmp 0x54509
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq