]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add PacketCache::purgeExact
authorChristian Hofstaedtler <christian.hofstaedtler@deduktiva.com>
Fri, 4 Dec 2015 19:28:46 +0000 (20:28 +0100)
committerChristian Hofstaedtler <christian.hofstaedtler@deduktiva.com>
Sun, 6 Dec 2015 14:57:31 +0000 (15:57 +0100)
pdns/mastercommunicator.cc
pdns/packetcache.cc
pdns/packetcache.hh
pdns/ws-auth.cc

index 638725c379ed442667898832b0d7e8f071b20c67..181fab13705ce26f816bb6766e81d0e83d8f75d4 100644 (file)
@@ -148,7 +148,7 @@ void CommunicatorClass::masterUpdateCheck(PacketHandler *P)
   
   for(vector<DomainInfo>::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();
 }
-
index a54cdf9fdcfcd83293f7217526fc58249fa2b86e..2d0ec82fa100cb5c626d3dc0ca4af933b12fb449 100644 (file)
@@ -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<DNSResourceRecord>& value, int zoneID)
index 14eae25f80e7cf1244d5075aad8ab04a6e6f28a5..93d219329912e8c4aca26ccfd8bad946005bac11 100644 (file)
@@ -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<char,int> getCounts();
 private:
@@ -149,4 +150,3 @@ private:
 
 
 #endif /* PACKETCACHE_HH */
-
index 0b376a4d1e705344d85c692bdb17fa912eb84641..641cde8e940872b3a23e8c8ea804d2f92a0fa726 100644 (file)
@@ -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