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

Code before:
             * a different shard, this is likely due to a client triggered slot
             * migration. Don't reconfigure this node to migrate to the new shard
             * in this case. */
            serverLog(LL_NOTICE,
                      "My last slot was migrated to node %.40s (%s) in shard %.40s. I am now an empty primary.",
                      sender->name, sender->human_nodename, sender->shard_id);
            /* We may still have dirty slots when we became a empty primary due to
             * a bad migration.
             *
             * In order to maintain a consistent state between keys and slots
             * we need to remove all the keys from the slots we lost. */
            delete_dirty_slots = 1;
        }
    } else if (dirty_slots_count) {
        /* If we are here, we received an update message which removed
         * ownership for certain slots we still have keys about, but still
         * we are serving some slots, so this primary node was not demoted to
         * a replica.
         *
         * In order to maintain a consistent state between keys and slots
         * we need to remove all the keys from the slots we lost. */
        delete_dirty_slots = 1;
    }

    if (delete_dirty_slots) {
        for (j = 0; j < dirty_slots_count; j++) {
            serverLog(LL_NOTICE, "Deleting keys in dirty slot %d on node %.40s (%s) in shard %.40s", dirty_slots[j],
                      myself->name, myself->human_nodename, myself->shard_id);
            delKeysInSlot(dirty_slots[j]);
        }
    }
}

/* Cluster ping extensions.
 *
 * The ping/pong/meet messages support arbitrary extensions to add additional
 * metadata to the messages that are sent between the various nodes in the
 * cluster. The extensions take the form:
 * [ Header length + type (8 bytes) ]
 * [ Extension information (Arbitrary length, but must be 8 byte padded) ]
 */


/* Returns the length of a given extension */
static uint32_t getPingExtLength(clusterMsgPingExt *ext) {
    return ntohl(ext->length);
}

/* Returns the initial position of ping extensions. May return an invalid
 * address if there are no ping extensions. */
static clusterMsgPingExt *getInitialPingExt(clusterMsg *hdr, int count) {

Review comment (suggestion):
```suggestion
        for (int j = 0; j < dirty_slots_count; j++) {
```

Code after:
             * a different shard, this is likely due to a client triggered slot
             * migration. Don't reconfigure this node to migrate to the new shard
             * in this case. */
            serverLog(LL_NOTICE,
                      "My last slot was migrated to node %.40s (%s) in shard %.40s. I am now an empty primary.",
                      sender->name, sender->human_nodename, sender->shard_id);
            /* We may still have dirty slots when we became a empty primary due to
             * a bad migration.
             *
             * In order to maintain a consistent state between keys and slots
             * we need to remove all the keys from the slots we lost. */
            delete_dirty_slots = 1;
        }
    } else if (dirty_slots_count) {
        /* If we are here, we received an update message which removed
         * ownership for certain slots we still have keys about, but still
         * we are serving some slots, so this primary node was not demoted to
         * a replica.
         *
         * In order to maintain a consistent state between keys and slots
         * we need to remove all the keys from the slots we lost. */
        delete_dirty_slots = 1;
    }

    if (delete_dirty_slots) {
        for (int j = 0; j < dirty_slots_count; j++) {
            serverLog(LL_NOTICE, "Deleting keys in dirty slot %d on node %.40s (%s) in shard %.40s", dirty_slots[j],
                      myself->name, myself->human_nodename, myself->shard_id);
            delKeysInSlot(dirty_slots[j]);
        }
    }
}

/* Cluster ping extensions.
 *
 * The ping/pong/meet messages support arbitrary extensions to add additional
 * metadata to the messages that are sent between the various nodes in the
 * cluster. The extensions take the form:
 * [ Header length + type (8 bytes) ]
 * [ Extension information (Arbitrary length, but must be 8 byte padded) ]
 */


/* Returns the length of a given extension */
static uint32_t getPingExtLength(clusterMsgPingExt *ext) {
    return ntohl(ext->length);
}

/* Returns the initial position of ping extensions. May return an invalid
 * address if there are no ping extensions. */
static clusterMsgPingExt *getInitialPingExt(clusterMsg *hdr, int count) {