From: Bert Hubert Date: Thu, 16 Feb 2012 20:27:13 +0000 (+0000) Subject: wonderful patch by Keith Buck to solve his own ticket 427 on how we serve up the... X-Git-Tag: auth-3.1-rc1~118 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=27fdc3fc75b2604ea431b283f9fc11778c957d37;p=pdns wonderful patch by Keith Buck to solve his own ticket 427 on how we serve up the old SOA serial number immediately after a change. Great stuff. git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2408 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/dynhandler.cc b/pdns/dynhandler.cc index 282a8ab29..8c9cb9c78 100644 --- a/pdns/dynhandler.cc +++ b/pdns/dynhandler.cc @@ -113,10 +113,13 @@ string DLPurgeHandler(const vector&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::const_iterator i=++parts.begin();i::const_iterator i=cmdomains.begin();i!=cmdomains.end();++i) { extern PacketCache PC; - vector 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); } diff --git a/pdns/packetcache.cc b/pdns/packetcache.cc index 5dc2d4226..79b1b43ec 100644 --- a/pdns/packetcache.cc +++ b/pdns/packetcache.cc @@ -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 &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 &matches) 'www.userpowerdns.com' */ - // skip first entry which is the pdns_control command - for(vector::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!"<qname, suffix) && !iends_with(iter->qname, dotsuffix)) { + // cerr<<"Stopping!"< 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 range = d_map.equal_range(tie(match)); + d_map.erase(range.first, range.second); } *d_statnumentries=d_map.size(); return delcount; diff --git a/pdns/packetcache.hh b/pdns/packetcache.hh index 658382b90..4a748b2df 100644 --- a/pdns/packetcache.hh +++ b/pdns/packetcache.hh @@ -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&matches= vector()); + int purge(); + int purge(const string &match); map getCounts(); private: