Commit 5090c97d authored by jan.koester's avatar jan.koester
Browse files

test

parent 65d03178
Loading
Loading
Loading
Loading
Loading
+26 −54
Changes for src/cluster.cpp: 26 added lines, 54 removed lines.
Original line number Diff line number Diff line
@@ -973,67 +973,39 @@ namespace authdb {
        return false;
    }

    void Cluster::listAllSessions(std::vector<SessionInfo> &out) {
        out.clear();
        if (!session_read_client_) return;
        std::set<std::string> seen_sids;
    std::vector<SessionInfo> Cluster::listAllSessions()
    {
        std::vector<SessionInfo> sessions;
        const auto groups = listAllGroups();

        std::set<uint64_t> all_groups;
        for (const auto gid : groups) {
            try {
            size_t n = session_read_client_->get_cluster_status().nodes_total;
            std::cerr << "[SESSIONS-DIAG] listAllSessions: nodes_total=" << n << std::endl;
            for (size_t i = 0; i < n; i++) {
                std::vector<uint64_t> node_groups;
                bool ok = session_read_client_->list_groups_on_node(i, node_groups);
                std::cerr << "[SESSIONS-DIAG] list_groups_on_node(" << i << ") ok=" << ok
                          << " groups=" << node_groups.size() << std::endl;
                if (ok) {
                    all_groups.insert(node_groups.begin(), node_groups.end());
                }
            }
            std::cerr << "[SESSIONS-DIAG] all_groups (union) size=" << all_groups.size() << std::endl;
                const auto data = retrieve(gid);

            // Try to retrieve and deserialize each group as a session
            for (uint64_t gid : all_groups) {
                try {
                    // Bounded per group — this runs synchronously in the admin
                    // "list sessions" request thread (see apiListSessions in
                    // admin.cpp). Without a deadline, one degraded group gives
                    // its retrieve() an independent ~30s retry budget (see
                    // Cluster::fetchSessionBySid), which multiplies across every
                    // session in the cluster instead of failing that group closed.
                    auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(5);
                    auto data = session_read_client_->retrieve(gid, deadline);
                    std::cerr << "[SESSIONS-DIAG] retrieve gid=" << gid
                              << " data_size=" << data.size() << std::endl;
                    if (data.empty()) continue;
                    SessionInfo info;
                    bool deser = SessionBlock::deserialize(data, info.sid, info.uid, info.did,
                                                  info.members, info.username, info.gpo_results,
                                                  info.created_at);
                    std::cerr << "[SESSIONS-DIAG] deserialize gid=" << gid
                              << " ok=" << deser
                              << " sid=" << (deser ? info.sid.c_str() : "?") << std::endl;
                    if (deser) {
                        std::string key = info.sid.c_str();
                        if (!info.sid.empty() && seen_sids.find(key) == seen_sids.end()) {
                            seen_sids.insert(key);
                            out.push_back(std::move(info));
                        }
                SessionInfo session;
                if (!deserializeSession(data, session)) {
                    std::cerr
                        << "[SESSIONS-DIAG] gid=" << gid
                        << " skipped: payload is not a valid session"
                        << std::endl;
                    continue;
                }

                sessions.emplace_back(std::move(session));
            } catch (const std::exception &e) {
                    std::cerr << "[SESSIONS-DIAG] retrieve/deserialize gid=" << gid
                              << " EXCEPTION: " << e.what() << std::endl;
                } catch (...) {
                    std::cerr << "[SESSIONS-DIAG] retrieve/deserialize gid=" << gid
                              << " unknown exception" << std::endl;
                }
                std::cerr
                    << "[SESSIONS-DIAG] gid=" << gid
                    << " skipped: " << e.what()
                    << std::endl;
            }
        } catch (const std::exception &e) {
            std::cerr << "[SESSIONS-DIAG] listAllSessions outer EXCEPTION: " << e.what() << std::endl;
        } catch (...) {
            std::cerr << "[SESSIONS-DIAG] listAllSessions outer unknown exception" << std::endl;
        }

        std::cerr
            << "[SESSIONS-DIAG] listAllSessions result="
            << sessions.size()
            << std::endl;

        return sessions;
    }

    // --- DataOpBlock serialization ---