From: Kees Monshouwer Date: Sun, 17 Jul 2022 21:38:56 +0000 (+0200) Subject: auth: clear caches after the catalig transaction is comitted X-Git-Tag: auth-4.8.0-alpha0~7^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5b56b34c31a4b86aac146ebcf24ca2a6f04095d5;p=thirdparty%2Fpdns.git auth: clear caches after the catalig transaction is comitted --- diff --git a/pdns/slavecommunicator.cc b/pdns/slavecommunicator.cc index 6bd209aea5..6c573694a0 100644 --- a/pdns/slavecommunicator.cc +++ b/pdns/slavecommunicator.cc @@ -94,6 +94,7 @@ static bool catalogDiff(const DomainInfo& di, vector& fromXFR, vect bool inTransaction{false}; bool doOptions{false}; CatalogInfo ciCreate, ciRemove; + std::unordered_map clearCache; vector retrieve; try { @@ -218,8 +219,8 @@ static bool catalogDiff(const DomainInfo& di, vector& fromXFR, vect g_log << Logger::Warning << logPrefix << "delete zone '" << ciRemove.d_zone << "'" << endl; di.backend->deleteDomain(ciRemove.d_zone); - if (g_zoneCache.isEnabled()) { - g_zoneCache.remove(ciRemove.d_zone); + if (!create) { + clearCache[ciRemove.d_zone] = false; } } @@ -236,21 +237,34 @@ static bool catalogDiff(const DomainInfo& di, vector& fromXFR, vect di.backend->setOptions(ciCreate.d_zone, ciCreate.toJson()); di.backend->setCatalog(ciCreate.d_zone, di.zone); + clearCache[ciCreate.d_zone] = true; retrieve.emplace_back(ciCreate); + } + } + + if (inTransaction && di.backend->commitTransaction()) { + g_log << Logger::Warning << logPrefix << "backend transaction committed" << endl; + } - if (g_zoneCache.isEnabled()) { - if (di.backend->getDomainInfo(ciCreate.d_zone, d)) { - g_zoneCache.add(ciCreate.d_zone, d.id); + // Update zonecache and clear all caches + DomainInfo d; + for (const auto& zone : clearCache) { + if (g_zoneCache.isEnabled()) { + if (zone.second) { + if (di.backend->getDomainInfo(zone.first, d)) { + g_zoneCache.add(zone.first, d.id); } else { - g_log << Logger::Error << logPrefix << "new zone '" << ciCreate.d_zone << "' does not exists and was not inserted in the zone-cache" << endl; + g_log << Logger::Error << logPrefix << "new zone '" << zone.first << "' does not exists and was not inserted in the zone-cache" << endl; } } + else { + g_zoneCache.remove(zone.first); + } } - } - if (inTransaction && di.backend->commitTransaction()) { - g_log << Logger::Warning << logPrefix << "backend transaction committed" << endl; + DNSSECKeeper::clearCaches(zone.first); + purgeAuthCaches(zone.first.toString() + "$"); } // retrieve new and updated zones with new primaries