diff --git a/modules/lmdbbackend/lmdbbackend.cc b/modules/lmdbbackend/lmdbbackend.cc index 394ed6f4ebf67..991bdedd6bdca 100644 --- a/modules/lmdbbackend/lmdbbackend.cc +++ b/modules/lmdbbackend/lmdbbackend.cc @@ -1810,9 +1810,7 @@ void LMDBBackend::setFresh(uint32_t domain_id) void LMDBBackend::getUpdatedPrimaries(vector& updatedDomains, std::unordered_set& catalogs, CatalogHashMap& catalogHashes) { - CatalogInfo ci; - - getAllDomainsFiltered(&(updatedDomains), [this, &catalogs, &catalogHashes, &ci](DomainInfo& di) { + getAllDomainsFiltered(&(updatedDomains), [this, &catalogs, &catalogHashes](DomainInfo& di) { if (!di.isPrimaryType()) { return false; } @@ -1824,12 +1822,13 @@ void LMDBBackend::getUpdatedPrimaries(vector& updatedDomains, std::u } if (!di.catalog.empty()) { - ci.fromJson(di.options, CatalogInfo::CatalogType::Producer); - ci.updateHash(catalogHashes, di); + CatalogInfo::updateCatalogHash(catalogHashes, di); } if (getSerial(di) && di.serial != di.notified_serial) { di.backend = this; + di.catalog.clear(); + di.options.clear(); return true; } diff --git a/pdns/auth-catalogzone.cc b/pdns/auth-catalogzone.cc index 2c6cbbce8c746..6266268add40e 100644 --- a/pdns/auth-catalogzone.cc +++ b/pdns/auth-catalogzone.cc @@ -27,15 +27,17 @@ #include "dnsbackend.hh" #include "json.hh" -void CatalogInfo::fromJson(const std::string& json, CatalogType type) +bool CatalogInfo::parseJson(const std::string& json, CatalogType type) { - d_type = type; - if (d_type == CatalogType::None) { + if (type == CatalogType::None) { throw std::runtime_error("CatalogType is set to None"); } + d_type = type; + if (json.empty()) { - return; + d_doc = nullptr; + return false; } std::string err; @@ -44,7 +46,12 @@ void CatalogInfo::fromJson(const std::string& json, CatalogType type) throw std::runtime_error("Parsing of JSON options failed: " + err); } - if (!d_doc[getTypeString(d_type)].is_null()) { + return !d_doc[getTypeString(d_type)].is_null(); +} + +void CatalogInfo::fromJson(const std::string& json, CatalogType type) +{ + if (parseJson(json, type)) { auto items = d_doc[getTypeString(type)].object_items(); // coo property @@ -107,11 +114,12 @@ std::string CatalogInfo::toJson() const return ret.dump(); } -void CatalogInfo::updateHash(CatalogHashMap& hashes, const DomainInfo& di) const +void CatalogInfo::updateCatalogHash(CatalogHashMap& hashes, const DomainInfo& di) { - hashes[di.catalog].process(std::to_string(di.id) + di.zone.toLogString() + string("\0", 1) + d_coo.toLogString() + string("\0", 1) + d_unique.toLogString()); - for (const auto& group : d_group) { - hashes[di.catalog].process(std::to_string(group.length()) + group); + CatalogInfo ci; + hashes[di.catalog].process(std::to_string(di.id) + di.zone.toLogString()); + if (ci.parseJson(di.options, CatalogType::Producer)) { + hashes[di.catalog].process(ci.d_doc["producer"].dump()); } } diff --git a/pdns/auth-catalogzone.hh b/pdns/auth-catalogzone.hh index d8a4fe907cbfd..0f2b578362dc3 100644 --- a/pdns/auth-catalogzone.hh +++ b/pdns/auth-catalogzone.hh @@ -59,7 +59,7 @@ public: std::string toJson() const; void setType(CatalogType type) { d_type = type; } - void updateHash(CatalogHashMap& hashes, const DomainInfo& di) const; + static void updateCatalogHash(CatalogHashMap& hashes, const DomainInfo& di); DNSName getUnique() const { return DNSName(toBase32Hex(hashQNameWithSalt(std::to_string(d_id), 0, d_zone))); } // salt with domain id to detect recreated zones static DNSZoneRecord getCatalogVersionRecord(const DNSName& zone); void toDNSZoneRecords(const DNSName& zone, vector& dzrs) const; @@ -77,4 +77,6 @@ public: private: CatalogType d_type; json11::Json d_doc; + + bool parseJson(const std::string& json, CatalogType type); }; diff --git a/pdns/backends/gsql/gsqlbackend.cc b/pdns/backends/gsql/gsqlbackend.cc index 0adaadd4cef39..2ff5c695e8a7b 100644 --- a/pdns/backends/gsql/gsqlbackend.cc +++ b/pdns/backends/gsql/gsqlbackend.cc @@ -593,8 +593,8 @@ void GSQLBackend::getUpdatedPrimaries(vector& updatedDomains, std::u try { if (!row[5].empty()) { - ci.fromJson(row[4], CatalogInfo::CatalogType::Producer); - ci.updateHash(catalogHashes, di); + di.options = row[4]; + CatalogInfo::updateCatalogHash(catalogHashes, di); } } catch (const std::exception& e) { @@ -626,6 +626,7 @@ void GSQLBackend::getUpdatedPrimaries(vector& updatedDomains, std::u di.kind = DomainInfo::Primary; di.serial = sd.serial; di.catalog.clear(); + di.options.clear(); updatedDomains.emplace_back(di); }