Commit 9a5bd99e authored by jan.koester's avatar jan.koester
Browse files

test

parent 5859e759
Loading
Loading
Loading
Loading
Loading
+7 −12
Changes for src/backends/cluster.cpp: 7 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ namespace authdb {

        uint64_t dgid = domainGroupId();

        // Try local store first, then peers
        // Try local store first
        auto &store = g_Cluster->getStore();
        std::vector<uint8_t> data;
        if (store.fetch(dgid, 0, data) && !data.empty()) {
@@ -59,15 +59,13 @@ namespace authdb {
            return;
        }

        // Try retrieving from peers if we have a parity group
        if (_HasParityGroup) {
        // Try fetching from peer nodes by domain group ID
        auto &client = g_Cluster->getClient();
        if (client) {
            try {
                auto &cmtx = g_Cluster->getClientMutex();
                std::lock_guard<std::mutex> lock(cmtx);
                    data = client->retrieve(_ParityGroupId, _Buffer.size());
                    if (!data.empty()) {
                if (client->fetch_from_peers(dgid, 0, data) && !data.empty()) {
                    _Buffer = std::move(data);
                    // Cache locally
                    store.store(dgid, 0, _Buffer.data(), _Buffer.size());
@@ -75,7 +73,6 @@ namespace authdb {
            } catch (...) {}
        }
    }
    }

    void ClusterBackend::pushToCluster() {
        if (!g_Cluster || !g_Cluster->isRunning()) {
@@ -97,16 +94,15 @@ namespace authdb {
                      << std::endl;
        }

        // Distribute to peers with parity encoding
        // Replicate raw data to all peer nodes
        auto &client = g_Cluster->getClient();
        if (client) {
            try {
                auto &cmtx = g_Cluster->getClientMutex();
                std::lock_guard<std::mutex> lock(cmtx);
                _ParityGroupId = client->store(_Buffer);
                _HasParityGroup = true;
                client->replicate_to_peers(dgid, 0, _Buffer.data(), _Buffer.size());
            } catch (const std::exception &e) {
                std::cerr << "Cluster push failed: " << e.what() << std::endl;
                std::cerr << "Cluster replicate failed: " << e.what() << std::endl;
            }
        }

@@ -114,8 +110,7 @@ namespace authdb {
    }

    ClusterBackend::ClusterBackend(const char *domain, size_t version, const char *filepath)
        : _Domain(domain), _Pos(0), _Dirty(false),
          _ParityGroupId(0), _HasParityGroup(false)
        : _Domain(domain), _Pos(0), _Dirty(false)
    {
        // Try to fetch existing data from cluster/store
        fetchFromCluster();
+0 −4
Changes for src/backends/cluster.h: 0 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -70,9 +70,5 @@ namespace authdb {
        std::vector<uint8_t>     _Buffer;
        size_t                   _Pos;
        bool                     _Dirty;

        // Cluster-side tracking
        uint64_t                 _ParityGroupId;
        bool                     _HasParityGroup;
    };
};