Commit c53b27d5 authored by jan.koester's avatar jan.koester
Browse files

test

parent 7c00cd7a
Loading
Loading
Loading
Loading
Loading
+12 −3
Changes for src/admin.cpp: 12 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -616,11 +616,20 @@ namespace authdb {

            auto &pclient = g_Cluster->getClient();
            if (pclient) {
                // Fetch cluster health under mutex, then release immediately
                // to avoid blocking session/replication operations during JSON build
                // Use try_lock to avoid blocking the HTTP handler (and other
                // cluster operations) while get_cluster_status() sequentially
                // probes every node — unreachable nodes cause long waits.
                decltype(pclient->get_cluster_status()) health;
                try {
                    std::lock_guard<std::mutex> lock(g_Cluster->getClientMutex());
                    std::unique_lock<std::mutex> lock(g_Cluster->getClientMutex(), std::try_to_lock);
                    if (!lock.owns_lock()) {
                        json_object_object_add(jobj, "status", json_object_new_string("BUSY"));
                        json_object_object_add(jobj, "nodes_total", json_object_new_int(0));
                        json_object_object_add(jobj, "nodes_online", json_object_new_int(0));
                        sendJson(curreq, jobj);
                        json_object_put(jobj);
                        return;
                    }
                    health = pclient->get_cluster_status();
                } catch (...) {
                    json_object_object_add(jobj, "status", json_object_new_string("UNAVAILABLE"));