Skip to content

Instantly share code, notes, and snippets.

@Habbie
Created April 26, 2013 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Habbie/5466729 to your computer and use it in GitHub Desktop.
Save Habbie/5466729 to your computer and use it in GitHub Desktop.
Index: pdns/packetcache.hh
===================================================================
--- pdns/packetcache.hh (revision 2373)
+++ pdns/packetcache.hh (working copy)
@@ -80,7 +80,8 @@
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:
Index: pdns/packetcache.cc
===================================================================
--- pdns/packetcache.cc (revision 2373)
+++ pdns/packetcache.cc (working copy)
@@ -165,21 +165,21 @@
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,31 +224,28 @@
'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);
+ 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;
+ 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++;
+ 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);
+ delcount++;
}
- 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_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: pdns/mastercommunicator.cc
===================================================================
--- pdns/mastercommunicator.cc (revision 2373)
+++ pdns/mastercommunicator.cc (working copy)
@@ -118,9 +118,7 @@
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: pdns/dynhandler.cc
===================================================================
--- pdns/dynhandler.cc (revision 2373)
+++ pdns/dynhandler.cc (working copy)
@@ -113,10 +113,13 @@
{
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment