Commit 7078df15 authored by jan.koester's avatar jan.koester
Browse files

test

parent 57278522
Loading
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -153,11 +153,17 @@ namespace authdb {
    ClusterBackend::ClusterBackend(const char *domain, size_t version, const char *filepath)
        : _Domain(domain), _Pos(0), _Dirty(false)
    {
        // Try to fetch existing data from cluster/store
        // Try to fetch existing data from cluster/store (retry a few times on startup)
        for (int attempt = 0; attempt < 3 && _Buffer.empty(); ++attempt) {
            if (attempt > 0)
                std::this_thread::sleep_for(std::chrono::seconds(attempt));
            fetchFromCluster();
        }

        if (_Buffer.empty()) {
            // Initialize with a fresh header
            // 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;
@@ -167,10 +173,7 @@ namespace authdb {

            _Buffer.resize(sizeof(AuthHeader));
            std::memcpy(_Buffer.data(), &head, sizeof(AuthHeader));
            _Dirty = true;

            // Push initial header to cluster/store
            pushToCluster();
            _Dirty = false;
        }
    }