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

Code before:
 * with read-only commands to keys that are served by the replica's primary. */
void readonlyCommand(client *c) {
    c->flag.readonly = 1;
    addReply(c, shared.ok);
}

/* The READWRITE command just clears the READONLY command state. */
void readwriteCommand(client *c) {
    c->flag.readonly = 0;
    addReply(c, shared.ok);
}

/* Resets transient cluster stats that we expose via INFO or other means that we want
 * to reset via CONFIG RESETSTAT. The function is also used in order to
 * initialize these fields in clusterInit() at server startup. */
void resetClusterStats(void) {
    if (!server.cluster_enabled) return;

    clusterSlotStatResetAll();

    if (server.cluster) {
        for (int i = 0; i < CLUSTERMSG_TYPE_COUNT; i++) {
            server.cluster->stats_bus_messages_sent[i] = 0;
            server.cluster->stats_bus_messages_received[i] = 0;
        }
    }
}


void clusterCommandFlushslot(client *c) {
    int slot;
    int lazy = server.lazyfree_lazy_user_flush;
    if ((slot = getSlotOrReply(c, c->argv[2])) == -1) return;
    if (c->argc == 4) {
        if (!strcasecmp(c->argv[3]->ptr, "async")) {
            lazy = 1;
        } else if (!strcasecmp(c->argv[3]->ptr, "sync")) {
            lazy = 0;
        } else {
            addReplyErrorObject(c, shared.syntaxerr);
            return;
        }
    }
    delKeysInSlot(slot, lazy, false, true);
    addReply(c, shared.ok);
}


Review comment (suggestion):
i don't think we need this server.cluster check, the structure should be ready in this moment. Also clusterSlotStatResetAll don't check it.
```
void clusterSlotStatResetAll(void) {
    memset(server.cluster->slot_stats, 0, sizeof(server.cluster->slot_stats));
}
```

Code after:
 * with read-only commands to keys that are served by the replica's primary. */
void readonlyCommand(client *c) {
    c->flag.readonly = 1;
    addReply(c, shared.ok);
}

/* The READWRITE command just clears the READONLY command state. */
void readwriteCommand(client *c) {
    c->flag.readonly = 0;
    addReply(c, shared.ok);
}

/* Resets transient cluster stats that we expose via INFO or other means that we want
 * to reset via CONFIG RESETSTAT. The function is also used in order to
 * initialize these fields in clusterInit() at server startup. */
void resetClusterStats(void) {
    if (!server.cluster_enabled) return;

    clusterSlotStatResetAll();

    memset(server.cluster->stats_bus_messages_sent, 0, sizeof(server.cluster->stats_bus_messages_sent));
    memset(server.cluster->stats_bus_messages_received, 0, sizeof(server.cluster->stats_bus_messages_received));
    server.cluster->stat_cluster_links_buffer_limit_exceeded = 0;
}


void clusterCommandFlushslot(client *c) {
    int slot;
    int lazy = server.lazyfree_lazy_user_flush;
    if ((slot = getSlotOrReply(c, c->argv[2])) == -1) return;
    if (c->argc == 4) {
        if (!strcasecmp(c->argv[3]->ptr, "async")) {
            lazy = 1;
        } else if (!strcasecmp(c->argv[3]->ptr, "sync")) {
            lazy = 0;
        } else {
            addReplyErrorObject(c, shared.syntaxerr);
            return;
        }
    }
    delKeysInSlot(slot, lazy, false, true);
    addReply(c, shared.ok);
}