Commit 1a246491 authored by jan.koester's avatar jan.koester
Browse files

test

parent 23e5811c
Loading
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -241,13 +241,21 @@ namespace authdb {
    }

    void ClusterBackend::prefetch() {
        // Called BEFORE the exclusive lock is acquired.
        // Fast path: if buffer has data and was recently fetched, skip entirely.
        // This avoids _FetchMutex contention when many threads call prefetch().
        if (!_Buffer.empty()) {
            auto now = std::chrono::steady_clock::now();
            bool due = (now - _LastPeerFetch) >= std::chrono::seconds(30);
            uint64_t cur_epoch = g_Cluster ? g_Cluster->getRecoveryEpoch() : _lastRecoveryEpoch;
            if (!due && cur_epoch == _lastRecoveryEpoch)
                return;  // data is fresh, no fetch needed
        }

        // Serialize fetches per-domain: if another thread is already fetching,
        // wait for its result instead of hammering the cluster in parallel.
        std::unique_lock<std::mutex> flk(_FetchMutex, std::try_to_lock);
        if (!flk.owns_lock()) {
            // Another thread is already fetching — wait for it to finish.
            // Its fetchFromCluster() will update _Buffer and _LastPeerFetch.
            DBG_LOG("[CLUSTER-BE] prefetch() domain=" << _Domain
                      << " — waiting for concurrent fetch\n");
            std::lock_guard<std::mutex> wait_lk(_FetchMutex);