]> granicus.if.org Git - pdns/commitdiff
wonderful patch by Keith Buck to solve his own ticket 427 on how we serve up the...
authorBert Hubert <bert.hubert@netherlabs.nl>
Thu, 16 Feb 2012 20:27:13 +0000 (20:27 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Thu, 16 Feb 2012 20:27:13 +0000 (20:27 +0000)
immediately after a change. Great stuff.

git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2408 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/dynhandler.cc
pdns/mastercommunicator.cc
pdns/packetcache.cc
pdns/packetcache.hh

index 282a8ab2938d0995cbdd5df0c3568d8a151c185f..8c9cb9c78e6e1767efb034c50512041316c5abbe 100644 (file)
@@ -113,10 +113,13 @@ string DLPurgeHandler(const vector<string>&parts, Utility::pid_t ppid)
 {
   extern PacketCache PC;  
   ostringstream os;
-  int ret;
+  int ret=0;
 
-  if(parts.size()>1)
-    ret=PC.purge(parts);
+  if(parts.size()>1) {
+    for (vector<string>::const_iterator i=++parts.begin();i<parts.end();++i) {
+      ret+=PC.purge(*i);
+    }
+  }
   else
     ret=PC.purge();
   os<<ret;
index 56cac304268a44c25e9a3a563d108e5795850e78..c555eeeb69c6e7fd81a06e189908a5b9258826b0 100644 (file)
@@ -118,9 +118,7 @@ void CommunicatorClass::masterUpdateCheck(PacketHandler *P)
   
   for(vector<DomainInfo>::const_iterator i=cmdomains.begin();i!=cmdomains.end();++i) {
     extern PacketCache PC;
-    vector<string> topurge;
-    topurge.push_back(i->zone);
-    PC.purge(topurge); // fixes cvstrac ticket #30
+    PC.purge(i->zone); // fixes cvstrac ticket #30
     queueNotifyDomain(i->zone,P->getBackend());
     i->backend->setNotified(i->id,i->serial); 
   }
index 5dc2d4226be65c15c910eeda47e0ef509626f1a1..79b1b43ec34c5633d5da70a9e98a53b06c2898f5 100644 (file)
@@ -165,21 +165,21 @@ void PacketCache::insert(const string &qname, const QType& qtype, CacheEntryType
     S.inc("deferred-cache-inserts"); 
 }
 
-/** purges entries from the packetcache. If match ends on a $, it is treated as a suffix 
-    for historical reasons, the first entry in matches is the original command passed to
-    pdns_control (typically 'PURGE') and needs to be ignored 
-*/
-int PacketCache::purge(const vector<string> &matches)
+/* clears the entire packetcache. */
+int PacketCache::purge()
+{
+  WriteLock l(&d_mut);
+  int delcount=d_map.size();
+  d_map.clear();
+  *d_statnumentries=0;
+  return delcount;
+}
+
+/* purges entries from the packetcache. If match ends on a $, it is treated as a suffix */
+int PacketCache::purge(const string &match)
 {
   WriteLock l(&d_mut);
   int delcount=0;
-  
-  if(matches.empty()) {
-    delcount = d_map.size();
-    d_map.clear();
-    *d_statnumentries=0;
-    return delcount;
-  }
 
   /* ok, the suffix delete plan. We want to be able to delete everything that 
      pertains 'www.powerdns.com' but we also want to be able to delete everything
@@ -224,30 +224,27 @@ int PacketCache::purge(const vector<string> &matches)
      'www.userpowerdns.com'
 
   */
-  // skip first entry which is the pdns_control command
-  for(vector<string>::const_iterator match = ++matches.begin(); match != matches.end() ; ++match) {
-    if(ends_with(*match, "$")) {
-      string suffix(*match);
-      suffix.resize(suffix.size()-1);
-
-      cmap_t::const_iterator iter = d_map.lower_bound(tie(suffix));
-      cmap_t::const_iterator start=iter;
-      string dotsuffix = "."+suffix;
-
-      for(; iter != d_map.end(); ++iter) {
-        if(!pdns_iequals(iter->qname, suffix) && !iends_with(iter->qname, dotsuffix)) {
-          //   cerr<<"Stopping!"<<endl;
-          break;
-        }
-        delcount++;
+  if(ends_with(match, "$")) {
+    string suffix(match);
+    suffix.resize(suffix.size()-1);
+
+    cmap_t::const_iterator iter = d_map.lower_bound(tie(suffix));
+    cmap_t::const_iterator start=iter;
+    string dotsuffix = "."+suffix;
+
+    for(; iter != d_map.end(); ++iter) {
+      if(!pdns_iequals(iter->qname, suffix) && !iends_with(iter->qname, dotsuffix)) {
+        //     cerr<<"Stopping!"<<endl;
+        break;
       }
-      d_map.erase(start, iter);
-    }
-    else {
-      delcount=d_map.count(tie(*match));
-      pair<cmap_t::iterator, cmap_t::iterator> range = d_map.equal_range(tie(*match));
-      d_map.erase(range.first, range.second);
+      delcount++;
     }
+    d_map.erase(start, iter);
+  }
+  else {
+    delcount=d_map.count(tie(match));
+    pair<cmap_t::iterator, cmap_t::iterator> range = d_map.equal_range(tie(match));
+    d_map.erase(range.first, range.second);
   }
   *d_statnumentries=d_map.size();
   return delcount;
index 658382b90b05b151d871d4d2a99ae966d8ae3a6c..4a748b2df3725660acdcb54c4310955e7d002c64 100644 (file)
@@ -80,7 +80,8 @@ public:
 
   int size(); //!< number of entries in the cache
   void cleanup(); //!< force the cache to preen itself from expired packets
-  int purge(const vector<string>&matches= vector<string>());
+  int purge();
+  int purge(const string &match);
 
   map<char,int> getCounts();
 private: