Repository: valkey-io/valkey
File: src/cluster_legacy.c (C)

Code before:
    dictReleaseIterator(di);
}

sds genClusterInfoString(void) {
    sds info = sdsempty();
    char *statestr[] = {"ok", "fail"};
    int slots_assigned = 0, slots_ok = 0, slots_pfail = 0, slots_fail = 0;
    int j;

    for (j = 0; j < CLUSTER_SLOTS; j++) {
        clusterNode *n = server.cluster->slots[j];

        if (n == NULL) continue;
        slots_assigned++;
        if (nodeFailed(n)) {
            slots_fail++;
        } else if (nodeTimedOut(n)) {
            slots_pfail++;
        } else {
            slots_ok++;
        }
    }

    dictIterator *di = dictGetIterator(server.cluster->nodes);
    dictEntry *de;
    u_int nodes_pfail = 0, nodes_fail = 0;
    while ((de = dictNext(di)) != NULL) {
        clusterNode *node = dictGetVal(de);
        if (nodeTimedOut(node)) {
            nodes_pfail++;
        }
        if (nodeFailed(node)) {
            nodes_fail++;
        }
    }
    dictReleaseIterator(di);

    if (nodes_pfail + nodes_fail > dictSize(server.cluster->nodes)) {
        serverLog(LL_WARNING, "Aggregated count of nodes marked as PFAIL and FAIL exceeds the total count of nodes."
                              "PFAIL nodes: %u, FAIL nodes: %u",
                  nodes_pfail, nodes_fail);
    }

    info = sdscatprintf(info,
                        "cluster_state:%s\r\n"
                        "cluster_slots_assigned:%d\r\n"
                        "cluster_slots_ok:%d\r\n"
                        "cluster_slots_pfail:%d\r\n"
                        "cluster_slots_fail:%d\r\n"
                        "cluster_nodes_pfail:%u\r\n"
                        "cluster_nodes_fail:%u\r\n"

Review comment (bug):
`u_int`? I haven't seen that before. A non-standard alias of unsigned int?

```suggestion
    unsigned nodes_pfail = 0, nodes_fail = 0;
```

Code after:
    dictReleaseIterator(di);
}

sds genClusterInfoString(void) {
    sds info = sdsempty();
    char *statestr[] = {"ok", "fail"};
    int slots_assigned = 0, slots_ok = 0, slots_pfail = 0, slots_fail = 0;
    int j;

    for (j = 0; j < CLUSTER_SLOTS; j++) {
        clusterNode *n = server.cluster->slots[j];

        if (n == NULL) continue;
        slots_assigned++;
        if (nodeFailed(n)) {
            slots_fail++;
        } else if (nodeTimedOut(n)) {
            slots_pfail++;
        } else {
            slots_ok++;
        }
    }

    dictIterator *di = dictGetIterator(server.cluster->nodes);
    dictEntry *de;
    unsigned nodes_pfail = 0, nodes_fail = 0, voting_nodes_pfail = 0, voting_nodes_fail = 0;
    while ((de = dictNext(di)) != NULL) {
        clusterNode *node = dictGetVal(de);
        if (nodeTimedOut(node)) {
            nodes_pfail++;
            if (clusterNodeIsVotingPrimary(node)) {
                voting_nodes_pfail++;
            }
        }
        if (nodeFailed(node)) {
            nodes_fail++;
            if (clusterNodeIsVotingPrimary(node)) {
                voting_nodes_fail++;
            }
        }
    }
    dictReleaseIterator(di);

    info = sdscatprintf(info,
                        "cluster_state:%s\r\n"
                        "cluster_slots_assigned:%d\r\n"
                        "cluster_slots_ok:%d\r\n"
                        "cluster_slots_pfail:%d\r\n"
                        "cluster_slots_fail:%d\r\n"
                        "cluster_nodes_pfail:%u\r\n"
                        "cluster_nodes_fail:%u\r\n"