]> granicus.if.org Git - pdns/commitdiff
first 20% speedup of bind backend, possibly much more in setups with a lot of zones
authorBert Hubert <bert.hubert@netherlabs.nl>
Fri, 30 Nov 2007 22:25:36 +0000 (22:25 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Fri, 30 Nov 2007 22:25:36 +0000 (22:25 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1108 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/backends/bind/bindbackend2.cc
pdns/backends/bind/bindbackend2.hh

index 0895e3dc8bf168f2e6484860f231901f5e36486a..380d237dbf253bb84b8c17672d539358b9f5ad87 100644 (file)
@@ -725,15 +725,6 @@ void Bind2Backend::queueReload(BB2DomainInfo *bbd)
   }
 }
 
-bool operator<(const Bind2DNSRecord &a, const string &b)
-{
-  return a.qname < b;
-}
-
-bool operator<(const string &a, const Bind2DNSRecord &b)
-{
-  return a < b.qname;
-}
 
 
 void Bind2Backend::lookup(const QType &qtype, const string &qname, DNSPacket *pkt_p, int zoneId )
@@ -742,15 +733,16 @@ void Bind2Backend::lookup(const QType &qtype, const string &qname, DNSPacket *pk
 
   string domain=toLower(qname);
 
-  bool mustlog=::arg().mustDo("query-logging");
+  static bool mustlog=::arg().mustDo("query-logging");
   if(mustlog) 
     L<<Logger::Warning<<"Lookup for '"<<qtype.getName()<<"' of '"<<domain<<"'"<<endl;
 
   shared_ptr<State> state = s_state;
 
-  while(!state->name_id_map.count(domain) && chopOff(domain));
+  name_id_map_t::const_iterator iditer;
+  while((iditer=state->name_id_map.find(domain)) == state->name_id_map.end() && chopOff(domain))
+    ;
 
-  name_id_map_t::const_iterator iditer=state->name_id_map.find(domain);
 
   if(iditer==state->name_id_map.end()) {
     if(mustlog)
@@ -760,7 +752,7 @@ void Bind2Backend::lookup(const QType &qtype, const string &qname, DNSPacket *pk
   }
   //  unsigned int id=*iditer;
   if(mustlog)
-    L<<Logger::Warning<<"Found data in zone '"<<domain<<"' with id "<<iditer->second<<endl;
+    L<<Logger::Warning<<"Found a zone '"<<domain<<"' (with id " << iditer->second<<") that might contain data "<<endl;
     
   d_handle.id=iditer->second;
   
@@ -787,7 +779,7 @@ void Bind2Backend::lookup(const QType &qtype, const string &qname, DNSPacket *pk
     state = s_state;
   }
 
-  d_handle.d_records = state->id_zone_map[iditer->second].d_records; // give it a reference counted copy
+  d_handle.d_records = bbd.d_records; // give it a reference counted copy
   
   if(d_handle.d_records->empty())
     DLOG(L<<"Query with no results"<<endl);
@@ -798,6 +790,7 @@ void Bind2Backend::lookup(const QType &qtype, const string &qname, DNSPacket *pk
   
   string lname=toLower(d_handle.qname);
   range=equal_range(d_handle.d_records->begin(), d_handle.d_records->end(), lname);
+  d_handle.mustlog = mustlog;
   
   if(range.first==range.second) {
     d_handle.d_list=false;
@@ -806,7 +799,6 @@ void Bind2Backend::lookup(const QType &qtype, const string &qname, DNSPacket *pk
   else {
     d_handle.d_iter=range.first;
     d_handle.d_end_iter=range.second;
-    d_handle.mustlog = mustlog;
   }
 
   d_handle.d_list=false;
@@ -819,14 +811,17 @@ Bind2Backend::handle::handle()
 
 bool Bind2Backend::get(DNSResourceRecord &r)
 {
-  if(!d_handle.d_records)
+  if(!d_handle.d_records) {
+    if(d_handle.mustlog)
+      L<<Logger::Warning<<"There were no answers"<<endl;
     return false;
+  }
 
   if(!d_handle.get(r)) {
-    d_handle.reset();
+    if(d_handle.mustlog)
+      L<<Logger::Warning<<"End of answers"<<endl;
 
-    if(::arg().mustDo("query-logging"))
-      L<<"End of answers"<<endl;
+    d_handle.reset();
 
     return false;
   }
index fcbb392ec68a9ade07a50f32d046dc3d03607e8a..c0f34aa47b17011388849a229e13c85069e47a4a 100644 (file)
@@ -53,8 +53,17 @@ struct Bind2DNSRecord
       return true;
     return tie(qtype,content, ttl) < tie(rhs.qtype, rhs.content, rhs.ttl);
   }
+  bool operator<(const string &b) const
+  {
+    return qname < b;
+  }
 };
 
+inline bool operator<(const string &a, const Bind2DNSRecord &b)
+{
+  return a < b.qname;
+}
+
 
 /** Class which describes all metadata of a domain for storage by the Bind2Backend, and also contains a pointer to a vector of Bind2DNSRecord's */
 class BB2DomainInfo