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

Code before:
    } else if (flags & CLUSTER_TODO_HANDLE_FAILOVER) {
        /* Handle failover as soon as possible so that won't have a 100ms
         * as it was handled only in clusterCron. This is needed when it
         * is likely that we can start the election or there is already
         * the quorum from primaries in order to react fast. */
        if (nodeIsReplica(myself) &&
            !(server.cluster_module_flags & CLUSTER_MODULE_FLAG_NO_FAILOVER)) {
            clusterHandleReplicaFailover();
        }
    }

    if (flags & CLUSTER_TODO_HANDLE_SLOT_MIGRATION) {
        clusterSlotMigrationCron();
    }

    /* Save the config, possibly using fsync. */
    if (flags & CLUSTER_TODO_SAVE_CONFIG) {
        int fsync = flags & CLUSTER_TODO_FSYNC_CONFIG;
        clusterSaveConfigOrDie(fsync);
    }

    if (flags & CLUSTER_TODO_BROADCAST_ALL) {
        /* Broadcast a pong to all known nodes. This is useful when something changes
         * in the configuration and we want to make the cluster aware it before the
         * regular ping. */
        clusterBroadcastPong(CLUSTER_BROADCAST_ALL);
    }
}

void clusterDoBeforeSleep(int flags) {
    /* Clear the cache if there are config changes here. */
    if (flags & CLUSTER_TODO_SAVE_CONFIG) clearCachedClusterSlotsResponse();

    server.cluster->todo_before_sleep |= flags;
}

/* -----------------------------------------------------------------------------
 * Slots management
 * -------------------------------------------------------------------------- */

/* Test bit 'pos' in a generic bitmap. Return 1 if the bit is set,
 * otherwise 0. */
int bitmapTestBit(unsigned char *bitmap, int pos) {
    off_t byte = pos / 8;
    int bit = pos & 7;
    return (bitmap[byte] & (1 << bit)) != 0;
}

/* Set the bit at position 'pos' in a bitmap. */
void bitmapSetBit(unsigned char *bitmap, int pos) {
    off_t byte = pos / 8;

Review comment (suggestion):
@enjoy-binbin, so we got rid of the server config and will automatically fall back on the "diskless nodes.conf" option? this needs a release note and documentation at the minimum but I don't think we should enable this by default before we have more operational experience to reason about restarting from a super stale nodes.conf file or multi nodes having stale nodes.conf files to various degrees. Cc @valkey-io/core-team 

Code after:
    if (flags & CLUSTER_TODO_HANDLE_MANUALFAILOVER) {
        /* Handle manual failover as soon as possible so that won't have a 100ms
         * as it was handled only in clusterCron */
        if (nodeIsReplica(myself)) {
            clusterHandleManualFailover();
            if (!(server.cluster_module_flags & CLUSTER_MODULE_FLAG_NO_FAILOVER)) clusterHandleReplicaFailover();
        }
    } else if (flags & CLUSTER_TODO_HANDLE_FAILOVER) {
        /* Handle failover as soon as possible so that won't have a 100ms
         * as it was handled only in clusterCron. This is needed when it
         * is likely that we can start the election or there is already
         * the quorum from primaries in order to react fast. */
        if (nodeIsReplica(myself) &&
            !(server.cluster_module_flags & CLUSTER_MODULE_FLAG_NO_FAILOVER)) {
            clusterHandleReplicaFailover();
        }
    }

    if (flags & CLUSTER_TODO_HANDLE_SLOT_MIGRATION) {
        clusterSlotMigrationCron();
    }

    /* Save the config, possibly using fsync. */
    if (flags & CLUSTER_TODO_SAVE_CONFIG) {
        int fsync = flags & CLUSTER_TODO_FSYNC_CONFIG;
        clusterSaveConfigOrLog(fsync);
    }

    if (flags & CLUSTER_TODO_BROADCAST_ALL) {
        /* Broadcast a pong to all known nodes. This is useful when something changes
         * in the configuration and we want to make the cluster aware it before the
         * regular ping. */
        clusterBroadcastPong(CLUSTER_BROADCAST_ALL);
    }
}

void clusterDoBeforeSleep(int flags) {
    /* Clear the cache if there are config changes here. */
    if (flags & CLUSTER_TODO_SAVE_CONFIG) clearCachedClusterSlotsResponse();

    server.cluster->todo_before_sleep |= flags;
}

/* -----------------------------------------------------------------------------
 * Slots management
 * -------------------------------------------------------------------------- */

/* Test bit 'pos' in a generic bitmap. Return 1 if the bit is set,
 * otherwise 0. */
int bitmapTestBit(unsigned char *bitmap, int pos) {
    off_t byte = pos / 8;