From be9d7339ad735a8d7a01508bd1a8b645a986abc5 Mon Sep 17 00:00:00 2001 From: Christian Hofstaedtler Date: Fri, 4 Dec 2015 20:28:46 +0100 Subject: [PATCH] Add PacketCache::purgeExact --- pdns/mastercommunicator.cc | 3 +-- pdns/packetcache.cc | 32 +++++++++++++++++++------------- pdns/packetcache.hh | 2 +- pdns/ws-auth.cc | 4 ++-- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/pdns/mastercommunicator.cc b/pdns/mastercommunicator.cc index 638725c37..181fab137 100644 --- a/pdns/mastercommunicator.cc +++ b/pdns/mastercommunicator.cc @@ -148,7 +148,7 @@ void CommunicatorClass::masterUpdateCheck(PacketHandler *P) for(vector::const_iterator i=cmdomains.begin();i!=cmdomains.end();++i) { extern PacketCache PC; - PC.purge(i->zone.toString()); // fixes cvstrac ticket #30 + PC.purgeExact(i->zone); queueNotifyDomain(i->zone,P->getBackend()); i->backend->setNotified(i->id,i->serial); } @@ -262,4 +262,3 @@ void CommunicatorClass::notify(const DNSName &domain, const string &ip) d_nq.add(domain, ip); d_any_sem.post(); } - diff --git a/pdns/packetcache.cc b/pdns/packetcache.cc index a54cdf9fd..2d0ec82fa 100644 --- a/pdns/packetcache.cc +++ b/pdns/packetcache.cc @@ -251,11 +251,26 @@ int PacketCache::purge() return delcount; } +int PacketCache::purgeExact(const DNSName& qname) +{ + int delcount=0; + auto& mc = getMap(qname); + + WriteLock l(&mc.d_mut); + auto range = mc.d_map.equal_range(tie(qname)); + if(range.first != range.second) { + delcount+=distance(range.first, range.second); + mc.d_map.erase(range.first, range.second); + } + *d_statnumentries-=delcount; // XXX FIXME NEEDS TO BE ADJUSTED (for packetcache shards) + return delcount; +} + /* purges entries from the packetcache. If match ends on a $, it is treated as a suffix */ int PacketCache::purge(const string &match) { - int delcount=0; if(ends_with(match, "$")) { + int delcount=0; string prefix(match); prefix.resize(prefix.size()-1); DNSName dprefix(prefix); @@ -272,21 +287,12 @@ int PacketCache::purge(const string &match) } mc.d_map.erase(start, iter); } + *d_statnumentries-=delcount; // XXX FIXME NEEDS TO BE ADJUSTED (for packetcache shards) + return delcount; } else { - DNSName dn(match); - auto& mc = getMap(dn); - - WriteLock l(&mc.d_mut); - auto range = mc.d_map.equal_range(tie(dn)); - if(range.first != range.second) { - delcount+=distance(range.first, range.second); - mc.d_map.erase(range.first, range.second); - } + return purgeExact(DNSName(match)); } - - *d_statnumentries-=delcount; // XXX FIXME NEEDS TO BE ADJUSTED - return delcount; } // called from ueberbackend bool PacketCache::getEntry(const DNSName &qname, const QType& qtype, CacheEntryType cet, vector& value, int zoneID) diff --git a/pdns/packetcache.hh b/pdns/packetcache.hh index 14eae25f8..93d219329 100644 --- a/pdns/packetcache.hh +++ b/pdns/packetcache.hh @@ -71,6 +71,7 @@ public: void cleanup(); //!< force the cache to preen itself from expired packets int purge(); int purge(const std::string& match); // could be $ terminated. Is not a dnsname! + int purgeExact(const DNSName& qname); // no wildcard matching here map getCounts(); private: @@ -149,4 +150,3 @@ private: #endif /* PACKETCACHE_HH */ - diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index 0b376a4d1..641cde8e9 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -1052,7 +1052,7 @@ static void patchZone(HttpRequest* req, HttpResponse* resp) { di.backend->commitTransaction(); extern PacketCache PC; - PC.purge(zonename.toString()); // XXX DNSName pain - this seems the wrong way round! + PC.purgeExact(zonename); // now the PTRs for(const DNSResourceRecord& rr : new_ptrs) { @@ -1070,7 +1070,7 @@ static void patchZone(HttpRequest* req, HttpResponse* resp) { throw ApiException("PTR-Hosting backend for "+rr.qname.toString()+"/"+rr.qtype.getName()+" does not support editing records."); } sd.db->commitTransaction(); - PC.purge(rr.qname.toString()); + PC.purgeExact(rr.qname); } // success -- 2.40.0