// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/cluster.c
// Function: clusterInit
void clusterInit(void) {
    int saveconf = 0;

    // 初始化配置
    server.cluster = zmalloc(sizeof(clusterState));
    server.cluster->myself = NULL;
    server.cluster->currentEpoch = 0;
    server.cluster->state = REDIS_CLUSTER_FAIL;
    server.cluster->size = 1;
    server.cluster->todo_before_sleep = 0;
    server.cluster->nodes = dictCreate(&clusterNodesDictType,NULL);
    server.cluster->nodes_black_list =
        dictCreate(&clusterNodesBlackListDictType,NULL);
    server.cluster->failover_auth_time = 0;
    server.cluster->failover_auth_count = 0;
    server.cluster->failover_auth_rank = 0;
    server.cluster->failover_auth_epoch = 0;
    server.cluster->lastVoteEpoch = 0;
    server.cluster->stats_bus_messages_sent = 0;
    server.cluster->stats_bus_messages_received = 0;
    memset(server.cluster->slots,0, sizeof(server.cluster->slots));
    clusterCloseAllSlots();

    /* Lock the cluster config file to make sure every node uses
     * its own nodes.conf. */
    if (clusterLockConfig(server.cluster_configfile) == REDIS_ERR)
        exit(1);

    /* Load or create a new nodes configuration. */
    if (clusterLoadConfig(server.cluster_configfile) == REDIS_ERR) {
        /* No configuration found. We will just use the random name provided
         * by the createClusterNode() function. */
        myself = server.cluster->myself =
            createClusterNode(NULL,REDIS_NODE_MYSELF|REDIS_NODE_MASTER);
        redisLog(REDIS_NOTICE,"No cluster configuration found, I'm %.40s",
            myself->name);
        clusterAddNode(myself);
        saveconf = 1;
    }

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

    /* We need a listening TCP port for our cluster messaging needs. */
    // 监听 TCP 端口
    server.cfd_count = 0;

    /* Port sanity check II
     * The other handshake port check is triggered too late to stop
     * us from trying to use a too-high cluster port number. */
    if (server.port > (65535-REDIS_CLUSTER_PORT_INCR)) {
        redisLog(REDIS_WARNING, "Redis port number too high. "
                   "Cluster communication port is 10,000 port "
                   "numbers higher than your Redis port. "
                   "Your Redis port number must be "
                   "lower than 55535.");
        exit(1);
    }

    if (listenToPort(server.port+REDIS_CLUSTER_PORT_INCR,
        server.cfd,&server.cfd_count) == REDIS_ERR)
    {
        exit(1);
    } else {
        int j;

        for (j = 0; j < server.cfd_count; j++) {
            // 关联监听事件处理器
            if (aeCreateFileEvent(server.el, server.cfd[j], AE_READABLE,
                clusterAcceptHandler, NULL) == AE_ERR)
                    redisPanic("Unrecoverable error creating Redis Cluster "
                                "file event.");
        }
    }

    /* The slots -> keys map is a sorted set. Init it. */
    // slots -> keys 映射是一个有序集合
    server.cluster->slots_to_keys = zslCreate();
    resetManualFailover();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl $0x0, -0x4(%rbp)
movl $0x60090, %edi          # imm = 0x60090
callq 0x2e130
movq %rax, %rcx
leaq 0xaa785(%rip), %rax     # 0x1138f8
movq %rcx, 0x7d0(%rax)
leaq 0xaa777(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movq $0x0, (%rax)
leaq 0xaa762(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movq $0x0, 0x8(%rax)
leaq 0xaa74c(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movl $0x1, 0x10(%rax)
leaq 0xaa737(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movl $0x1, 0x14(%rax)
leaq 0xaa722(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movl $0x0, 0x60078(%rax)
leaq 0xa9812(%rip), %rdi     # 0x112a00
xorl %eax, %eax
movl %eax, %esi
callq 0x231a0
movq %rax, %rcx
leaq 0xaa6f7(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movq %rcx, 0x18(%rax)
leaq 0xa981d(%rip), %rdi     # 0x112a30
xorl %eax, %eax
movl %eax, %esi
callq 0x231a0
movq %rax, %rcx
leaq 0xaa6d2(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movq %rcx, 0x20(%rax)
leaq 0xaa6c0(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movq $0x0, 0x60030(%rax)
leaq 0xaa6a7(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movl $0x0, 0x60038(%rax)
leaq 0xaa68f(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movl $0x0, 0x60040(%rax)
leaq 0xaa677(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movq $0x0, 0x60048(%rax)
leaq 0xaa65e(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movq $0x0, 0x60070(%rax)
leaq 0xaa645(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movq $0x0, 0x60080(%rax)
leaq 0xaa62c(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movq $0x0, 0x60088(%rax)
leaq 0xaa613(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rdi
addq $0x40028, %rdi          # imm = 0x40028
xorl %esi, %esi
movl $0x20000, %edx          # imm = 0x20000
callq 0x1f110
callq 0x694d0
leaq 0xaa5ed(%rip), %rax     # 0x1138f8
movq 0x7c8(%rax), %rdi
callq 0x69060
cmpl $-0x1, %eax
jne 0x69326
movl $0x1, %edi
callq 0x1f2c0
leaq 0xaa5cb(%rip), %rax     # 0x1138f8
movq 0x7c8(%rax), %rdi
callq 0x67fd0
cmpl $-0x1, %eax
jne 0x69395
xorl %eax, %eax
movl %eax, %edi
movl $0x11, %esi
callq 0x68a20
leaq 0xaa5a5(%rip), %rcx     # 0x1138f8
movq 0x7d0(%rcx), %rcx
movq %rax, (%rcx)
movq %rax, 0xbec14(%rip)     # 0x127f78
movq 0xbec0d(%rip), %rdx     # 0x127f78
addq $0x8, %rdx
movl $0x2, %edi
leaq 0x7cb44(%rip), %rsi     # 0xe5ebf
movb $0x0, %al
callq 0x24fb0
movq 0xbebef(%rip), %rdi     # 0x127f78
callq 0x68bb0
movl $0x1, -0x4(%rbp)
cmpl $0x0, -0x4(%rbp)
je 0x693a5
movl $0x1, %edi
callq 0x69020
leaq 0xaa54c(%rip), %rax     # 0x1138f8
movl $0x0, 0x1ac(%rax)
leaq 0xaa53b(%rip), %rax     # 0x1138f8
cmpl $0xd8ef, 0x88(%rax)     # imm = 0xD8EF
jle 0x693e6
movl $0x3, %edi
leaq 0x7cb14(%rip), %rsi     # 0xe5ee9
movb $0x0, %al
callq 0x24fb0
movl $0x1, %edi
callq 0x1f2c0
leaq 0xaa50b(%rip), %rax     # 0x1138f8
movl 0x88(%rax), %edi
addl $0x2710, %edi           # imm = 0x2710
leaq 0xaa4f8(%rip), %rdx     # 0x1138f8
movq %rdx, %rsi
addq $0x16c, %rsi            # imm = 0x16C
addq $0x1ac, %rdx            # imm = 0x1AC
callq 0x27a90
cmpl $-0x1, %eax
jne 0x69425
movl $0x1, %edi
callq 0x1f2c0
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
leaq 0xaa4c2(%rip), %rcx     # 0x1138f8
cmpl 0x1ac(%rcx), %eax
jge 0x694a5
leaq 0xaa4b3(%rip), %rax     # 0x1138f8
movq 0x28(%rax), %rdi
movslq -0x8(%rbp), %rcx
leaq 0xaa4a4(%rip), %rax     # 0x1138f8
movl 0x16c(%rax,%rcx,4), %esi
movl $0x1, %edx
leaq 0xb9(%rip), %rcx        # 0x69520
xorl %eax, %eax
movl %eax, %r8d
callq 0x20a80
cmpl $-0x1, %eax
jne 0x69498
leaq 0x7cb08(%rip), %rdi     # 0xe5f85
leaq 0x7c821(%rip), %rsi     # 0xe5ca5
movl $0x204, %edx            # imm = 0x204
callq 0x63d40
movl $0x1, %edi
callq 0x1f3b0
jmp 0x6949a
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x6942c
jmp 0x694a7
callq 0x4d060
movq %rax, %rcx
leaq 0xaa442(%rip), %rax     # 0x1138f8
movq 0x7d0(%rax), %rax
movq %rcx, 0x60028(%rax)
callq 0x69650
addq $0x10, %rsp
popq %rbp
retq
nop