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

Code before:
    if (!countKeysInSlot(hashslot)) return 0;

    /* We may lose a slot during the pause. We need to track this
     * state so that we don't assert in propagateNow(). */
    server.server_del_keys_in_slot = 1;
    unsigned int j = 0;
    int before_execution_nesting = server.execution_nesting;

    kvstoreHashtableIterator *kvs_di = NULL;
    void *next;
    kvs_di = kvstoreGetHashtableSafeIterator(server.db->keys, hashslot);
    while (kvstoreHashtableIteratorNext(kvs_di, &next)) {
        robj *valkey = next;
        enterExecutionUnit(1, 0);
        sds sdskey = objectGetKey(valkey);
        robj *key = createStringObject(sdskey, sdslen(sdskey));
        if (lazy) {
            dbAsyncDelete(&server.db[0], key);
        } else {
            dbSyncDelete(&server.db[0], key);
        }
        dbDelete(&server.db[0], key);
        propagateDeletion(&server.db[0], key, lazy);
        signalModifiedKey(NULL, &server.db[0], key);
        /* The keys are not actually logically deleted from the database, just moved to another node.
         * The modules needs to know that these keys are no longer available locally, so just send the
         * keyspace notification to the modules, but not to clients. */
        moduleNotifyKeyspaceEvent(NOTIFY_GENERIC, "del", key, server.db[0].id);
        exitExecutionUnit();
        postExecutionUnitOperations();
        decrRefCount(key);
        j++;
        server.dirty++;
    }
    kvstoreReleaseHashtableIterator(kvs_di);

    server.server_del_keys_in_slot = 0;
    serverAssert(server.execution_nesting == before_execution_nesting);
    return j;
}

/* Get the count of the channels for a given slot. */
unsigned int countChannelsInSlot(unsigned int hashslot) {
    return kvstoreHashtableSize(server.pubsubshard_channels, hashslot);
}

clusterNode *getMyClusterNode(void) {
    return server.cluster->myself;
}

int clusterManualFailoverTimeLimit(void) {

Review comment (suggestion):
This code comment about keyspace notifications:

```
        /* The keys are not actually logically deleted from the database, just moved to another node.
         * The modules needs to know that these keys are no longer available locally, so just send the
         * keyspace notification to the modules, but not to clients. */
```

`delKeysInSlot` is used for slot migrations, which are considered not deleting the keys but just migrating them to another node.

This is not necessarily the case for CLUSTER FLUSHSLOT. I think we should treat CLUSTER FLUSHSLOT more like FLUSHDB. For FLUSHDB, what are the keyspace notifications sent? A lot of DEL events or one FLUSHDB event?

Maybe we shouldn't use `delKeysInSlot` here, or use some extra argument or flag to indicate if it's a migration or if we're just deleting the keys.

Code after:
    addReplyBulkCBuffer(c, node->name, CLUSTER_NAMELEN);
    reply_count++;

    if (node->tcp_port) {
        addReplyBulkCString(c, "port");
        addReplyLongLong(c, node->tcp_port);
        reply_count++;
    }

    if (node->tls_port) {
        addReplyBulkCString(c, "tls-port");
        addReplyLongLong(c, node->tls_port);
        reply_count++;
    }

    addReplyBulkCString(c, "ip");
    addReplyBulkCString(c, clusterNodeIp(node, c));
    reply_count++;

    addReplyBulkCString(c, "endpoint");
    addReplyBulkCString(c, clusterNodePreferredEndpoint(node, c));
    reply_count++;

    if (sdslen(node->hostname) != 0) {
        addReplyBulkCString(c, "hostname");
        addReplyBulkCBuffer(c, node->hostname, sdslen(node->hostname));
        reply_count++;
    }

    long long node_offset = getNodeReplicationOffset(node);

    addReplyBulkCString(c, "role");
    addReplyBulkCString(c, nodeIsReplica(node) ? "replica" : "master");
    reply_count++;

    addReplyBulkCString(c, "replication-offset");
    addReplyLongLong(c, node_offset);
    reply_count++;

    addReplyBulkCString(c, "health");
    const char *health_msg = NULL;
    if (nodeFailed(node)) {
        health_msg = "fail";
    } else if (nodeIsReplica(node) && node_offset == 0) {
        health_msg = "loading";
    } else {
        health_msg = "online";
    }
    addReplyBulkCString(c, health_msg);
    reply_count++;