From: Bert Hubert Date: Sun, 22 Jun 2008 22:17:20 +0000 (+0000) Subject: implement fast wiping of "ds9a.nl" and "blah.ds9a.nl" using inverted ordering X-Git-Tag: rec-3.1.7.1~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9e1341960ccb0ce00be9a4543ab17b3004828131;p=thirdparty%2Fpdns.git implement fast wiping of "ds9a.nl" and "blah.ds9a.nl" using inverted ordering git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1220 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/packetcache.cc b/pdns/packetcache.cc index 9ff3be61d0..337109fc3e 100644 --- a/pdns/packetcache.cc +++ b/pdns/packetcache.cc @@ -21,6 +21,7 @@ #include "arguments.hh" #include "statbag.hh" #include +#include extern StatBag S; @@ -129,7 +130,7 @@ void PacketCache::insert(const string &qname, const QType& qtype, CacheEntryType if(!ttl) return; - // cerr<<"Inserting, cet: "<<(int)cet< range = d_map.equal_range(tie(match)); - d_map.erase(range.first, range.second); + Ok - next step, can we get away with only reversing the comparison? + 'powerdns.com' + 'images.powerdns.com' + ' www.powerdns.com' + 'powerdnsiscool.com' + 'www.userpowerdns.com' + + */ + if(ends_with(match, "$")) { + string suffix(match); + suffix.resize(suffix.size()-1); + + // cerr<<"Begin dump!"<qname, suffix) && !iends_with(iter->qname, dotsuffix)) { + // cerr<<"Stopping!"<qname<<"'\n"; + + delcount++; + } + // cerr<<"End dump!"< range = d_map.equal_range(tie(match)); + d_map.erase(range.first, range.second); + } *statnumentries=d_map.size(); return delcount; } diff --git a/pdns/packetcache.hh b/pdns/packetcache.hh index d250efb859..2a1412cbae 100644 --- a/pdns/packetcache.hh +++ b/pdns/packetcache.hh @@ -49,6 +49,31 @@ using namespace boost; first marks and then sweeps, a second lock is present to prevent simultaneous inserts and deletes. */ +struct CIBackwardsStringCompare: public binary_function +{ + bool operator()(const string& a, const string& b) const + { + const unsigned char *p1 = (const unsigned char *) a.c_str() + a.length(); + const unsigned char *p2 = (const unsigned char *) b.c_str() + b.length(); + int result; + + if (p1 == p2) { + return 0; + } + + while ((result = dns_tolower (*p1--) - dns_tolower (*p2--)) == 0) + if (p1 == (unsigned char*)a.c_str() || p2 == (unsigned char*) b.c_str()) + break; + + if(result==0) { // one of our strings ended, the shortest one is smaller then + return a.length() < b.length(); + } + + return result < 0; + } +}; + + class PacketCache { public: @@ -96,7 +121,7 @@ private: member, member >, - composite_key_compare, std::less, std::less, std::less > + composite_key_compare, std::less, std::less, std::less > >, sequenced<> >