Commit 8e33412b authored by jan.koester's avatar jan.koester
Browse files

test

parent 86b39cf8
Loading
Loading
Loading
Loading
+23 −9
Original line number Diff line number Diff line
@@ -1186,24 +1186,38 @@ client::cluster_health client::get_cluster_status() {
    health.nodes_online = 0;
    health.overall = node_status::OK;

    for (size_t i = 0; i < nodes_.size(); i++) {
    // Probe all nodes in parallel — avoid sequential 2s waits per dead node
    struct ProbeResult {
        size_t index;
        bool reachable = false;
        status_info info;
        if (get_node_status(i, info)) {
    };
    std::vector<ProbeResult> results(nodes_.size());
    {
        std::vector<std::future<void>> futures;
        for (size_t i = 0; i < nodes_.size(); i++) {
            results[i].index = i;
            futures.push_back(std::async(std::launch::async, [this, i, &results]() {
                results[i].reachable = get_node_status(i, results[i].info);
            }));
        }
        for (auto& f : futures) f.get();
    }

    for (auto& r : results) {
        if (r.reachable) {
            health.nodes_online++;
            health.node_statuses.emplace_back(i, info);
            // If any node reports degraded, note it
            if (info.status == node_status::DEGRADED ||
                info.status == node_status::REBUILD) {
                health.overall = info.status;
            health.node_statuses.emplace_back(r.index, r.info);
            if (r.info.status == node_status::DEGRADED ||
                r.info.status == node_status::REBUILD) {
                health.overall = r.info.status;
            }
        }
    }

    // Determine overall status based on reachability
    if (health.nodes_online == 0) {
        health.overall = node_status::DEGRADED;
    } else if (health.nodes_online < health.nodes_total) {
        // Some nodes unreachable — still degraded even if individual nodes report OK
        if (health.overall == node_status::OK)
            health.overall = node_status::DEGRADED;
    }