From: Bert Hubert Date: Sun, 22 Jun 2008 20:41:42 +0000 (+0000) Subject: implement cache purging for 100% matches (disregarding case), plus make updates actua... X-Git-Tag: rec-3.1.7.1~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aee8cae28b6619ab4f0a412301f8030081d399b8;p=thirdparty%2Fpdns.git implement cache purging for 100% matches (disregarding case), plus make updates actually update the cache git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1219 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/packetcache.cc b/pdns/packetcache.cc index f3eaf1e27a..9ff3be61d0 100644 --- a/pdns/packetcache.cc +++ b/pdns/packetcache.cc @@ -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: "<swap(d_map); - L<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 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 range = d_map.equal_range(tie(match)); + d_map.erase(range.first, range.second); - l.upgrade(); - - for(vector::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 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(); diff --git a/pdns/packetcache.hh b/pdns/packetcache.hh index 525a3fdaa2..d250efb859 100644 --- a/pdns/packetcache.hh +++ b/pdns/packetcache.hh @@ -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;