Commit 540e62fe authored by jan.koester's avatar jan.koester
Browse files

test

parent 130525bc
Loading
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -257,6 +257,15 @@ namespace authdb {
                        rep.send(curreq,"[{\"error\":\"not initialized\"}]",29);
                        return;
                    }
                    // Cluster has data but not enough peers to reconstruct — don't
                    // show the wizard (would create conflicting admin data).
                    if(_AdminBackend.clusterDataExists()){
                        libhttppp::HttpResponse rep;
                        rep.setState(HTTP503);
                        rep.setContentType("text/html");
                        rep.send(curreq,"cluster data unavailable — waiting for peers",45);
                        return;
                    }
                    std::cerr << "[AUTHDB] wizard check: end=" << _AdminBackend.end()
                              << " header=" << sizeof(authdb::AuthHeader) << std::endl;
                    AuthBackend::Guard admlock(_AdminBackend);
+4 −0
Original line number Diff line number Diff line
@@ -113,6 +113,10 @@ void authdb::AuthBackend::purge(){
    _Api->purge();
}

bool authdb::AuthBackend::clusterDataExists() const {
    return _Api->clusterDataExists();
}

authdb::AuthBackend::Guard::Guard(AuthBackend &backend) : _Backend(backend){
    _Backend.lock();
}
+3 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ namespace authdb{
        virtual void newRevesion()=0;
        virtual void vacuum()=0;
        virtual void purge(){};
        virtual bool clusterDataExists() const { return false; }
    };

    class VISIBILITY AuthBackend {
@@ -96,6 +97,8 @@ namespace authdb{
        const std::string &getDomain() const { return _Domain; }
        int getType() const { return _Type; }

        bool clusterDataExists() const;

    private:
        void lock();
        void unlock();
+3 −0
Original line number Diff line number Diff line
@@ -109,6 +109,9 @@ namespace authdb {
                } catch (const std::exception &e) {
                    std::cerr << "ClusterBackend::fetchFromCluster: retrieve failed: "
                              << e.what() << std::endl;
                    // "not enough blocks" means data exists but too few peers are reachable
                    if (std::string(e.what()).find("not enough blocks") != std::string::npos)
                        _ClusterDataExists.store(true);
                } catch (...) {
                    std::cerr << "ClusterBackend::fetchFromCluster: retrieve failed (unknown)" << std::endl;
                }
+3 −0
Original line number Diff line number Diff line
@@ -64,6 +64,8 @@ namespace authdb {
        void vacuum();
        void purge();

        bool clusterDataExists() const override { return _ClusterDataExists.load(); }

    private:
        uint64_t domainGroupId() const;
        void fetchFromCluster();
@@ -74,6 +76,7 @@ namespace authdb {
        std::vector<uint8_t>     _Buffer;
        size_t                   _Pos;
        std::atomic<bool>        _Dirty;
        std::atomic<bool>        _ClusterDataExists{false};
        std::chrono::steady_clock::time_point _LastPeerFetch{};
    };
};