Commit 4774128e authored by jan.koester's avatar jan.koester
Browse files

test

parent baf71a04
Loading
Loading
Loading
Loading
Loading
+26 −28
Original line number Diff line number Diff line
@@ -598,38 +598,36 @@ namespace authdb {
                  << " sgid=" << sgid << " sid_gid=" << sid_gid
                  << " data_size=" << data.size() << std::endl;

        // Dedicated session client — retry loop with short lock attempts
        // Store each key in a separate lock acquisition so other operations
        // (fetch, remove) can interleave instead of waiting 2× store time.
        auto store_one = [&](uint64_t gid, const char *label) {
            for (int attempt = 0; attempt < 5; ++attempt) {
                std::unique_lock<std::timed_mutex> lock(session_client_mutex_, std::chrono::milliseconds(200));
                if (!lock.owns_lock()) {
                std::cerr << "[CLUSTER-SESSION] pushSession: lock attempt " << attempt + 1
                          << "/5 failed, retrying..." << std::endl;
                    std::cerr << "[CLUSTER-SESSION] pushSession " << label << ": lock attempt "
                              << attempt + 1 << "/5 failed, retrying..." << std::endl;
                    std::this_thread::sleep_for(std::chrono::milliseconds(100));
                    continue;
                }
                try {
                session_client_->store(sgid, data.data(), data.size());
                session_client_->store(sid_gid, data.data(), data.size());
                    session_client_->store(gid, data.data(), data.size());
                    return true;
                } catch (const std::exception &e) {
                std::cerr << "[CLUSTER-SESSION] pushSession: store attempt " << attempt + 1
                          << "/5 FAILED: " << e.what() << std::endl;
                    std::cerr << "[CLUSTER-SESSION] pushSession " << label << ": store attempt "
                              << attempt + 1 << "/5 FAILED: " << e.what() << std::endl;
                    if (attempt < 4) {
                        std::this_thread::sleep_for(std::chrono::milliseconds(200));
                        continue;
                    }
                throw;
                }

            // Verify and return on success
            try {
                auto verify = session_client_->retrieve(sid_gid);
                std::cerr << "[CLUSTER-SESSION] pushSession: stored OK, verify=" << verify.size() << " bytes" << std::endl;
            } catch (const std::exception &e) {
                std::cerr << "[CLUSTER-SESSION] pushSession: stored but verify failed: " << e.what() << std::endl;
            }
            return;
        }
        throw AuthBackendError("cluster busy — session push timeout after 5 retries");
            return false;
        };

        if (!store_one(sgid, "sgid"))
            throw AuthBackendError("cluster busy — session push (sgid) timeout after 5 retries");
        if (!store_one(sid_gid, "sid_gid"))
            throw AuthBackendError("cluster busy — session push (sid_gid) timeout after 5 retries");
    }

    void Cluster::queuePush(const SessionData &sess) {