Loading src/backends/cluster.cpp +17 −14 Original line number Diff line number Diff line Loading @@ -276,10 +276,10 @@ namespace authdb { return; } // Serialize fetches per domain // Serialize fetches per domain — don't block if another thread is fetching std::unique_lock<std::mutex> flk(cache->fetch_mutex, std::try_to_lock); if (!flk.owns_lock()) { std::lock_guard<std::mutex> wait_lk(cache->fetch_mutex); // Another thread is already fetching — use cached data, don't wait if (!cache->buffer.empty()) { _Buffer = cache->buffer; _ClusterDataExists.store(_Buffer.size() > sizeof(AuthHeader)); Loading Loading @@ -404,23 +404,26 @@ namespace authdb { ClusterBackend::ClusterBackend(const char *domain, size_t version, const char *filepath) : _Domain(domain), _Pos(0), _Dirty(false) { // Check if the local block store already has shards for this domain. // Try the shared domain cache first — no network I/O needed. // This is critical: the constructor must NOT call pclient_->retrieve() // because the push_worker may hold pclient_->mutex_ for seconds, // blocking this constructor and causing HTTP timeouts. if (g_Cluster && g_Cluster->isRunning()) { auto cache = getDomainCache(); if (!cache->buffer.empty()) { _Buffer = cache->buffer; _ClusterDataExists.store(true); } else { // No cached data yet — check local block store (no network) uint64_t dgid = domainGroupId(); auto &store = g_Cluster->getStore(); auto blocks = store.list_blocks(dgid); if (!blocks.empty()) _ClusterDataExists.store(true); } // Try to fetch existing data from cluster (single attempt, non-blocking). // If peers aren't reachable yet, lock() will fetch on first use. fetchFromCluster(); } if (_Buffer.empty()) { // Initialize with a fresh header locally. // Do NOT push to cluster — we may have failed to fetch existing data // and pushing an empty header would overwrite real data on other nodes. AuthHeader head; head.Version = version; head.Revesion = 0; Loading Loading
src/backends/cluster.cpp +17 −14 Original line number Diff line number Diff line Loading @@ -276,10 +276,10 @@ namespace authdb { return; } // Serialize fetches per domain // Serialize fetches per domain — don't block if another thread is fetching std::unique_lock<std::mutex> flk(cache->fetch_mutex, std::try_to_lock); if (!flk.owns_lock()) { std::lock_guard<std::mutex> wait_lk(cache->fetch_mutex); // Another thread is already fetching — use cached data, don't wait if (!cache->buffer.empty()) { _Buffer = cache->buffer; _ClusterDataExists.store(_Buffer.size() > sizeof(AuthHeader)); Loading Loading @@ -404,23 +404,26 @@ namespace authdb { ClusterBackend::ClusterBackend(const char *domain, size_t version, const char *filepath) : _Domain(domain), _Pos(0), _Dirty(false) { // Check if the local block store already has shards for this domain. // Try the shared domain cache first — no network I/O needed. // This is critical: the constructor must NOT call pclient_->retrieve() // because the push_worker may hold pclient_->mutex_ for seconds, // blocking this constructor and causing HTTP timeouts. if (g_Cluster && g_Cluster->isRunning()) { auto cache = getDomainCache(); if (!cache->buffer.empty()) { _Buffer = cache->buffer; _ClusterDataExists.store(true); } else { // No cached data yet — check local block store (no network) uint64_t dgid = domainGroupId(); auto &store = g_Cluster->getStore(); auto blocks = store.list_blocks(dgid); if (!blocks.empty()) _ClusterDataExists.store(true); } // Try to fetch existing data from cluster (single attempt, non-blocking). // If peers aren't reachable yet, lock() will fetch on first use. fetchFromCluster(); } if (_Buffer.empty()) { // Initialize with a fresh header locally. // Do NOT push to cluster — we may have failed to fetch existing data // and pushing an empty header would overwrite real data on other nodes. AuthHeader head; head.Version = version; head.Revesion = 0; Loading