Commit ad19b715 authored by jan.koester's avatar jan.koester
Browse files

test

parent 1a246491
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -521,6 +521,37 @@ namespace authdb {
            return it->second.get();
        }

        // Pre-populate domain cache so API requests never need to lock _AdminBackend
        void warmDomainCache() {
            Domain domain;
            std::vector<uuid::uuid> dids;
            {
                AuthBackend::Guard admlock(_AdminBackend, AuthBackend::Shared);
                domain.list(_AdminBackend, dids);
            }
            DomainBackend db(_AdminBackend);
            for (const auto &did : dids) {
                // Skip if already cached
                {
                    std::shared_lock<std::shared_mutex> rl(_DomainCacheMtx);
                    if (_DomainCache.count(std::string(did.value, did.value+16)))
                        continue;
                }
                DomainInfo dinfo;
                {
                    AuthBackend::Guard admlock(_AdminBackend, AuthBackend::Shared);
                    dinfo = db.resolve(did);
                }
                if (!dinfo.found) continue;
                auto backend = std::make_unique<AuthBackend>(
                    dinfo.storageType, dinfo.storageOptions, dinfo.domainName);
                std::unique_lock<std::shared_mutex> wl(_DomainCacheMtx);
                auto key = std::string(did.value, did.value+16);
                _DomainCache.emplace(key, std::move(backend));
            }
            std::cerr << "[AUTHDB] domain cache warmed: " << dids.size() << " domain(s)" << std::endl;
        }

    private:
        AuthBackend        &_AdminBackend;
        std::unique_ptr<Session>  _Session;
@@ -696,6 +727,11 @@ int main(int argc,char *argv[]){

        authdb::AuthDB authdb(backend,httpd.getServerSockets());

        // Pre-load all domain backends into cache so API requests
        // don't need to lock the admin backend for domain resolution.
        if (backend.end() > sizeof(authdb::AuthHeader))
            authdb.warmDomainCache();

        if(cmd.getCmdbyKey("debug")->getValue()=="true"){
            authdb::DEBUG=true;
            authdb.threads=1;