Loading src/backends/cluster.cpp +15 −12 Changes for src/backends/cluster.cpp: 15 added lines, 12 removed lines. Original line number Diff line number Diff line Loading @@ -52,25 +52,19 @@ namespace authdb { uint64_t dgid = domainGroupId(); // Try local store first // Fetch from local store auto &store = g_Cluster->getStore(); std::vector<uint8_t> data; if (store.fetch(dgid, 0, data) && !data.empty()) { _Buffer = std::move(data); return; } std::vector<uint8_t> local_data; store.fetch(dgid, 0, local_data); // Try fetching from peer nodes by domain group ID // Also try fetching from peer nodes std::vector<uint8_t> peer_data; auto &client = g_Cluster->getClient(); if (client) { try { auto &cmtx = g_Cluster->getClientMutex(); std::lock_guard<std::mutex> lock(cmtx); if (client->fetch_from_peers(dgid, 0, data) && !data.empty()) { _Buffer = std::move(data); // Cache locally store.store(dgid, 0, _Buffer.data(), _Buffer.size()); } client->fetch_from_peers(dgid, 0, peer_data); } catch (const netplus::NetException &e) { std::cerr << "ClusterBackend::fetchFromCluster: fetch_from_peers failed: " << e.what() << std::endl; Loading @@ -79,6 +73,15 @@ namespace authdb { << e.what() << std::endl; } } // Use whichever has more data (the one with actual content beyond the header) if (peer_data.size() > local_data.size()) { _Buffer = std::move(peer_data); // Update local cache with the better version store.store(dgid, 0, _Buffer.data(), _Buffer.size()); } else if (!local_data.empty()) { _Buffer = std::move(local_data); } } void ClusterBackend::pushToCluster() { Loading Loading
src/backends/cluster.cpp +15 −12 Changes for src/backends/cluster.cpp: 15 added lines, 12 removed lines. Original line number Diff line number Diff line Loading @@ -52,25 +52,19 @@ namespace authdb { uint64_t dgid = domainGroupId(); // Try local store first // Fetch from local store auto &store = g_Cluster->getStore(); std::vector<uint8_t> data; if (store.fetch(dgid, 0, data) && !data.empty()) { _Buffer = std::move(data); return; } std::vector<uint8_t> local_data; store.fetch(dgid, 0, local_data); // Try fetching from peer nodes by domain group ID // Also try fetching from peer nodes std::vector<uint8_t> peer_data; auto &client = g_Cluster->getClient(); if (client) { try { auto &cmtx = g_Cluster->getClientMutex(); std::lock_guard<std::mutex> lock(cmtx); if (client->fetch_from_peers(dgid, 0, data) && !data.empty()) { _Buffer = std::move(data); // Cache locally store.store(dgid, 0, _Buffer.data(), _Buffer.size()); } client->fetch_from_peers(dgid, 0, peer_data); } catch (const netplus::NetException &e) { std::cerr << "ClusterBackend::fetchFromCluster: fetch_from_peers failed: " << e.what() << std::endl; Loading @@ -79,6 +73,15 @@ namespace authdb { << e.what() << std::endl; } } // Use whichever has more data (the one with actual content beyond the header) if (peer_data.size() > local_data.size()) { _Buffer = std::move(peer_data); // Update local cache with the better version store.store(dgid, 0, _Buffer.data(), _Buffer.size()); } else if (!local_data.empty()) { _Buffer = std::move(local_data); } } void ClusterBackend::pushToCluster() { Loading