]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
implement cache purging for 100% matches (disregarding case), plus make updates actua...
authorBert Hubert <bert.hubert@netherlabs.nl>
Sun, 22 Jun 2008 20:41:42 +0000 (20:41 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Sun, 22 Jun 2008 20:41:42 +0000 (20:41 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1219 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/packetcache.cc
pdns/packetcache.hh

index f3eaf1e27af927f06e66d6472028899b9e3c399a..9ff3be61d069efe73fe1d8597e489375faaeb623 100644 (file)
@@ -27,7 +27,6 @@ extern StatBag S;
 PacketCache::PacketCache()
 {
   pthread_rwlock_init(&d_mut,0);
-  pthread_mutex_init(&d_dellock,0);
   d_hit=d_miss=0;
 
   d_ttl=-1;
@@ -146,61 +145,40 @@ void PacketCache::insert(const string &qname, const QType& qtype, CacheEntryType
     cmap_t::iterator place;
     tie(place, success)=d_map.insert(val);
     //    cerr<<"Insert succeeded: "<<success<<endl;
-    //    if(!success)
-    //      cerr<<"Replace: "<<d_map.replace(place, val)<<endl;
+    if(!success)
+      d_map.replace(place, val);
     
   }
   else 
     S.inc("deferred-cache-inserts"); 
 }
 
-/** purges entries from the packetcache. If prefix ends on a $, it is treated as a suffix */
-int PacketCache::purge(const string &f_prefix)
+/** purges entries from the packetcache. If match ends on a $, it is treated as a suffix */
+int PacketCache::purge(const string &match)
 {
-  Lock pl(&d_dellock);
-
-  string prefix(f_prefix);
-  if(prefix.empty()) {
-    cmap_t *tmp=new cmap_t;
-    {
-      DTime dt;
-      dt.set();
-      WriteLock l(&d_mut);
-      tmp->swap(d_map);
-      L<<Logger::Error<<"cache clean time: "<<dt.udiff()<<"usec"<<endl;
-    }
-
-    int size=tmp->size();
-    delete tmp;
+  WriteLock l(&d_mut);
+  int delcount;
 
+  if(match.empty()) {
+    delcount = d_map.size();
+    d_map.clear();
     *statnumentries=0;
-    return size;
-  }
-
-  bool suffix=false;
-  if(prefix[prefix.size()-1]=='$') {
-    prefix=prefix.substr(0,prefix.size()-1);
-    suffix=true;
+    return delcount;
   }
-  string check=prefix+"|";
 
-  vector<cmap_t::iterator> toRemove;
+  /* 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
+     in the powerdns.com zone, so: 'powerdns.com' and '*.powerdns.com'.
 
-  ReadLock l(&d_mut);
-
-  for(cmap_t::iterator i=d_map.begin();i!=d_map.end();++i) {
-    string::size_type pos=i->qname.find(check);
+     However, we do NOT want to delete 'usepowerdns.com!'
+  */
 
-    if(!pos || (suffix && pos!=string::npos)) 
-      toRemove.push_back(i);
-  }
+  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);
 
-  l.upgrade();  
-
-  for(vector<cmap_t::iterator>::const_iterator i=toRemove.begin();i!=toRemove.end();++i) 
-    d_map.erase(*i);
   *statnumentries=d_map.size();
-  return toRemove.size();
+  return delcount;
 }
 
 bool PacketCache::getEntry(const string &qname, const QType& qtype, CacheEntryType cet, string& value, int zoneID, bool meritsRecursion)
@@ -211,7 +189,6 @@ bool PacketCache::getEntry(const string &qname, const QType& qtype, CacheEntryTy
     return false;
   }
 
-  // needs to do ttl check here
   uint16_t qt = qtype.getCode();
   cmap_t::const_iterator i=d_map.find(tie(qname, qt, cet, zoneID, meritsRecursion));
   time_t now=time(0);
@@ -233,7 +210,6 @@ map<char,int> PacketCache::getCounts()
   return ret;
 }
 
-
 int PacketCache::size()
 {
   ReadLock l(&d_mut);
@@ -243,7 +219,6 @@ int PacketCache::size()
 /** readlock for figuring out which iterators to delete, upgrade to writelock when actually cleaning */
 void PacketCache::cleanup()
 {
-  Lock pl(&d_dellock); // ALWAYS ACQUIRE DELLOCK FIRST
   WriteLock l(&d_mut);
 
   *statnumentries=d_map.size();
index 525a3fdaa2204caeb72b3d86a85146b580f6aab2..d250efb8591a128a4625e4d3d138d06e2bd0ecbf 100644 (file)
@@ -106,7 +106,6 @@ private:
   cmap_t d_map;
 
   pthread_rwlock_t d_mut;
-  pthread_mutex_t d_dellock;
 
   int d_hit;
   int d_miss;