]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
packetcache hashed
authorbert hubert <bert.hubert@netherlabs.nl>
Sun, 4 Sep 2016 19:03:16 +0000 (21:03 +0200)
committerbert hubert <bert.hubert@powerdns.com>
Tue, 13 Sep 2016 10:53:30 +0000 (12:53 +0200)
pdns/packetcache.cc
pdns/packetcache.hh

index 35212fc417669aa1e1a382c51053586974911cc3..cfc391593112cfa0c3c4af1536c0d00c4fa254fe 100644 (file)
@@ -315,16 +315,26 @@ bool PacketCache::getEntryLocked(const DNSName &qname, const QType& qtype, Cache
   uint16_t qt = qtype.getCode();
   //cerr<<"Lookup for maxReplyLen: "<<maxReplyLen<<endl;
   auto& mc=getMap(qname);
-  cmap_t::const_iterator i=mc.d_map.find(tie(qname, qt, cet, zoneID, meritsRecursion, maxReplyLen, dnssecOK, hasEDNS, *age));
+  //  cmap_t::const_iterator i=mc.d_map.find(tie(qname, qt, cet, zoneID, meritsRecursion, maxReplyLen, dnssecOK, hasEDNS, *age));
+
+  auto& idx = boost::multi_index::get<UnorderedNameTag>(mc.d_map);
+  auto range=idx.equal_range(tie(qname, qt, cet, zoneID));
+
+  if(range.first == range.second)
+    return false;
   time_t now=time(0);
-  bool ret=(i!=mc.d_map.end() && i->ttd > now);
-  if(ret) {
-    if (age)
-      *age = now - i->created;
-    value = i->value;
+  for(auto iter = range.first ; iter != range.second; ++iter) {
+    if(meritsRecursion == iter->meritsRecursion && maxReplyLen == iter->maxReplyLen && dnssecOK == iter->dnssecOk && hasEDNS == iter->hasEDNS ) {
+      if(iter->ttd > now) {
+        if (age)
+          *age = now - iter->created;
+        value = iter->value;
+        return true;
+      }
+    }
   }
   
-  return ret;
+  return false;
 }
                           
 bool PacketCache::getEntryLocked(const DNSName &qname, const QType& qtype, CacheEntryType cet, vector<DNSZoneRecord>& value, int zoneID)
@@ -332,13 +342,17 @@ bool PacketCache::getEntryLocked(const DNSName &qname, const QType& qtype, Cache
   uint16_t qt = qtype.getCode();
   //cerr<<"Lookup for maxReplyLen: "<<maxReplyLen<<endl;
   auto& mc=getMap(qname);
-  cmap_t::const_iterator i=mc.d_map.find(tie(qname, qt, cet, zoneID));
+  auto& idx = boost::multi_index::get<UnorderedNameTag>(mc.d_map);
+  auto i=idx.find(tie(qname, qt, cet, zoneID));
+  if(i==idx.end())
+    return false;
+
   time_t now=time(0);
-  bool ret=(i!=mc.d_map.end() && i->ttd > now);
-  if(ret) {
+  if(i->ttd > now) {
     value = i->drs;
+    return true;
   }
-  return ret;
+  return false;
 }
 
 
index 47c344537178e628b52382644567316386801349..172524ab3b96f10d33cfe75e39d306bc73768e97 100644 (file)
@@ -32,6 +32,7 @@
 using namespace ::boost::multi_index;
 
 #include "namespaces.hh"
+#include <boost/multi_index/hashed_index.hpp> 
 #include "dnspacket.hh"
 #include "lock.hh"
 #include "statbag.hh"
@@ -111,6 +112,7 @@ private:
 
   void getTTLS();
 
+  struct UnorderedNameTag{};
   typedef multi_index_container<
     CacheEntry,
     indexed_by <
@@ -128,8 +130,13 @@ private:
                         >,
                       composite_key_compare<CanonDNSNameCompare, std::less<uint16_t>, std::less<uint16_t>, std::less<int>, std::less<bool>, 
                           std::less<unsigned int>, std::less<bool>, std::less<bool> >
-                            >,
-                           sequenced<>
+                       >,
+      hashed_non_unique<tag<UnorderedNameTag>, composite_key<CacheEntry,
+                                                             member<CacheEntry,DNSName,&CacheEntry::qname>,
+                                                             member<CacheEntry,uint16_t,&CacheEntry::qtype>,
+                                                             member<CacheEntry,uint16_t, &CacheEntry::ctype>,
+                                                             member<CacheEntry,int, &CacheEntry::zoneID> > > ,
+      sequenced<>
                            >
   > cmap_t;