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

test

parent 9488ce9b
Loading
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
@@ -536,6 +536,7 @@ namespace authdb {
    void Cluster::pushSession(const SessionData &sess) {
        if (!pclient_) return;

        auto t0 = std::chrono::steady_clock::now();
        auto data = SessionBlock::serialize(sess);

        uuid::uuid uid, did, sid;
@@ -547,15 +548,29 @@ namespace authdb {
        uint64_t sid_gid = sidGroupId(sid);

        try {
            std::cerr << "[CLUSTER] pushSession: acquiring lock" << std::endl;
            std::unique_lock<std::timed_mutex> lock(client_mutex_, std::chrono::seconds(5));
            if (!lock.owns_lock()) {
                std::cerr << "Cluster push session: lock timeout" << std::endl;
                std::cerr << "[CLUSTER] pushSession: lock timeout (5s)" << std::endl;
                return;
            }
            auto t1 = std::chrono::steady_clock::now();
            std::cerr << "[CLUSTER] pushSession: lock acquired in "
                      << std::chrono::duration_cast<std::chrono::milliseconds>(t1-t0).count()
                      << "ms, storing sgid" << std::endl;
            pclient_->store(sgid, data.data(), data.size());
            auto t2 = std::chrono::steady_clock::now();
            std::cerr << "[CLUSTER] pushSession: store(sgid) took "
                      << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count()
                      << "ms, storing sid_gid" << std::endl;
            pclient_->store(sid_gid, data.data(), data.size());
            auto t3 = std::chrono::steady_clock::now();
            std::cerr << "[CLUSTER] pushSession: store(sid_gid) took "
                      << std::chrono::duration_cast<std::chrono::milliseconds>(t3-t2).count()
                      << "ms, total=" << std::chrono::duration_cast<std::chrono::milliseconds>(t3-t0).count()
                      << "ms" << std::endl;
        } catch (const std::exception &e) {
            std::cerr << "Cluster push session: " << e.what() << std::endl;
            std::cerr << "[CLUSTER] pushSession: exception: " << e.what() << std::endl;
        }
    }

@@ -569,8 +584,18 @@ namespace authdb {
        std::vector<uint8_t> data;
        if (pclient_) {
            try {
                auto t0 = std::chrono::steady_clock::now();
                std::cerr << "[CLUSTER] fetchSession: acquiring lock" << std::endl;
                std::unique_lock<std::timed_mutex> lock(client_mutex_, std::chrono::seconds(2)); if (!lock.owns_lock()) throw std::runtime_error("cluster client lock timeout");
                auto t1 = std::chrono::steady_clock::now();
                std::cerr << "[CLUSTER] fetchSession: lock in "
                          << std::chrono::duration_cast<std::chrono::milliseconds>(t1-t0).count()
                          << "ms, retrieving" << std::endl;
                data = pclient_->retrieve(sgid);
                auto t2 = std::chrono::steady_clock::now();
                std::cerr << "[CLUSTER] fetchSession: retrieve took "
                          << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count()
                          << "ms, size=" << data.size() << std::endl;
                if (!data.empty()) {
                    uuid::uuid d_uid, d_did;
                    if (SessionBlock::deserialize(data, sid, d_uid, d_did, members, username, gpo_results)) {
+13 −1
Original line number Diff line number Diff line
@@ -433,6 +433,7 @@ authdb::ClusterSession::ClusterSession() : LocalSession() {}
authdb::ClusterSession::~ClusterSession() {}

const authdb::SessionData *authdb::ClusterSession::addSession(AuthBackend &backend,uuid::uuid domainid,uuid::uuid userid){
    std::cerr << "[SESSION] addSession: checking local cache" << std::endl;
    // Check local cache first
    {
        std::lock_guard<std::mutex> guard(_lock);
@@ -441,19 +442,23 @@ const authdb::SessionData *authdb::ClusterSession::addSession(AuthBackend &backe
            uuid::uuid cur_uid, cur_did;
            cur->getUid(cur_uid);
            cur->getDid(cur_did);
            if (cur_uid == userid && cur_did == domainid)
            if (cur_uid == userid && cur_did == domainid) {
                std::cerr << "[SESSION] addSession: found in local cache" << std::endl;
                return cur;
            }
        }
    }

    // Check cluster for existing session (skip when degraded to avoid blocking)
    if (g_Cluster && g_Cluster->isRunning() && !g_Cluster->isDegraded()) {
        std::cerr << "[SESSION] addSession: fetching from cluster" << std::endl;
        uuid::uuid cluster_sid;
        std::vector<uuid::uuid> cluster_members;
        std::string cluster_username;
        std::vector<std::pair<uuid::uuid, bool>> cluster_gpo;
        if (g_Cluster->fetchSession(userid, domainid, cluster_sid,
                                     cluster_members, cluster_username, cluster_gpo)) {
            std::cerr << "[SESSION] addSession: imported from cluster" << std::endl;
            SessionData *imported = new SessionData(cluster_sid, userid, domainid, cluster_members);
            imported->_username = cluster_username;
            imported->setGPOResults(cluster_gpo);
@@ -462,9 +467,14 @@ const authdb::SessionData *authdb::ClusterSession::addSession(AuthBackend &backe
            appendLocal(imported);
            return imported;
        }
        std::cerr << "[SESSION] addSession: not found in cluster" << std::endl;
    } else {
        std::cerr << "[SESSION] addSession: skipping cluster (degraded=" 
                  << (g_Cluster ? g_Cluster->isDegraded() : false) << ")" << std::endl;
    }

    // Create new session
    std::cerr << "[SESSION] addSession: creating new session" << std::endl;
    SessionData *newSession = createSessionData(backend, domainid, userid);

    {
@@ -474,7 +484,9 @@ const authdb::SessionData *authdb::ClusterSession::addSession(AuthBackend &backe

    // Push to cluster for replication
    if (g_Cluster && g_Cluster->isRunning()) {
        std::cerr << "[SESSION] addSession: pushing to cluster" << std::endl;
        g_Cluster->pushSession(*newSession);
        std::cerr << "[SESSION] addSession: push done" << std::endl;
    }

    return newSession;