From: Bert Hubert Date: Fri, 4 Mar 2011 20:43:28 +0000 (+0000) Subject: remove our old DNSResourceRecord serializer, replace it with the boost one, plus... X-Git-Tag: auth-3.0~189 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cb433f9c6b70cc7cac4c1c7f40b3d3570f86dc46;p=pdns remove our old DNSResourceRecord serializer, replace it with the boost one, plus serialize vectors of DNSResourceRecords now, allowing the querycache to store answers with multiple records, which should be a big speedup! git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2059 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 7dadaa2c5..918e1367c 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -44,8 +44,8 @@ dnsseckeeper.hh dnssecinfra.hh base32.hh dns.cc dnssecsigner.cc polarrsakeyinfra md5.hh signingpipe.cc signingpipe.hh dnslabeltext.cc # -pdns_server_LDFLAGS=@moduleobjects@ @modulelibs@ @DYNLINKFLAGS@ @LIBDL@ @THREADFLAGS@ -Lext/polarssl/library -pdns_server_LDADD= -lpolarssl +pdns_server_LDFLAGS=@moduleobjects@ @modulelibs@ @DYNLINKFLAGS@ @LIBDL@ @THREADFLAGS@ -Lext/polarssl/library $(BOOST_SERIALIZATION_LDFLAGS) +pdns_server_LDADD= -lpolarssl $(BOOST_SERIALIZATION_LIBS) if BOTAN19 pdns_server_SOURCES += botan19signers.cc botansigners.cc @@ -74,8 +74,8 @@ pdnssec_SOURCES=pdnssec.cc dbdnsseckeeper.cc sstuff.hh dnsparser.cc dnsparser.hh dynlistener.cc dns.cc randombackend.cc dnssecsigner.cc polarrsakeyinfra.cc md5.cc \ signingpipe.cc dnslabeltext.cc -pdnssec_LDFLAGS=@moduleobjects@ @modulelibs@ @DYNLINKFLAGS@ @LIBDL@ @THREADFLAGS@ -Lext/polarssl/library/ $(BOOST_PROGRAM_OPTIONS_LDFLAGS) -pdnssec_LDADD= -lpolarssl $(BOOST_PROGRAM_OPTIONS_LIBS) +pdnssec_LDFLAGS=@moduleobjects@ @modulelibs@ @DYNLINKFLAGS@ @LIBDL@ @THREADFLAGS@ -Lext/polarssl/library/ $(BOOST_PROGRAM_OPTIONS_LDFLAGS) $(BOOST_SERIALIZATION_LDFLAGS) +pdnssec_LDADD= -lpolarssl $(BOOST_PROGRAM_OPTIONS_LIBS) $(BOOST_SERIALIZATION_LIBS) if BOTAN19 pdnssec_SOURCES += botan19signers.cc botansigners.cc diff --git a/pdns/dns.hh b/pdns/dns.hh index 050d2b7bb..044a2d108 100644 --- a/pdns/dns.hh +++ b/pdns/dns.hh @@ -25,6 +25,12 @@ #include #include #include + +#include +#include +#include + + #include "utility.hh" #include "qtype.hh" #include @@ -66,9 +72,6 @@ public: DNSResourceRecord() : qclass(1), priority(0), last_modified(0), d_place(ANSWER) {}; ~DNSResourceRecord(){}; - string serialize() const; - int unSerialize(const string &str); - // data QType qtype; //!< qtype of this record, ie A, CNAME, MX etc @@ -76,7 +79,7 @@ public: string qname; //!< the name of this record, for example: www.powerdns.com string wildcardname; string content; //!< what this record points to. Example: 10.1.2.3 - uint16_t priority; //!< For qtype's that support a priority or preference. Currently only MX + uint16_t priority; //!< For qtypes that support a priority or preference (MX, SRV) uint32_t ttl; //!< Time To Live of this record int domain_id; //!< If a backend implements this, the domain_id of the zone this record is in time_t last_modified; //!< For autocalculating SOA serial numbers - the backend needs to fill this in @@ -85,6 +88,22 @@ public: bool auth; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & qtype; + ar & qclass; + ar & qname; + ar & wildcardname; + ar & content; + ar & priority; + ar & ttl; + ar & domain_id; + ar & last_modified; + ar & d_place; + ar & auth; + } + bool operator<(const DNSResourceRecord &b) const { if(qname < b.qname) @@ -93,9 +112,6 @@ public: return(content < b.content); return false; } - -private: - string escape(const string &str) const; }; #ifdef _MSC_VER diff --git a/pdns/qtype.cc b/pdns/qtype.cc index 55e5aaea4..4aadb4d33 100644 --- a/pdns/qtype.cc +++ b/pdns/qtype.cc @@ -133,97 +133,3 @@ QType::QType(uint16_t n) QType(); code=n; } - -string DNSResourceRecord::serialize() const -{ - ostringstream ostr; - ostr< #include #include - #include "namespaces.hh" /** The QType class is meant to deal easily with the different kind of resource types, like 'A', 'NS', @@ -64,6 +63,12 @@ public: return code < rhs.code; } + template + void serialize(Archive &ar, const unsigned int version) + { + ar & code; + } + bool operator==(const QType &) const; //!< equality operator const string getName() const; //!< Get a string representation of this type diff --git a/pdns/ueberbackend.cc b/pdns/ueberbackend.cc index 993b58208..3b4d296cf 100644 --- a/pdns/ueberbackend.cc +++ b/pdns/ueberbackend.cc @@ -15,6 +15,9 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include +#include + #include "packetcache.hh" #include "utility.hh" @@ -25,13 +28,12 @@ #include #include #include - +#include #include #include #include #include #include - #include "dns.hh" #include "arguments.hh" #include "dnsbackend.hh" @@ -219,15 +221,14 @@ bool UeberBackend::getSOA(const string &domain, SOAData &sd, DNSPacket *p) d_question.zoneId=-1; if(sd.db!=(DNSBackend *)-1) { - int cstat=cacheHas(d_question,d_answer); - if(cstat==0) { + int cstat=cacheHas(d_question,d_answers); + if(cstat==0) { // negative return false; } - else if(cstat==1) { - // ehm - fillSOAData(d_answer.content,sd); - sd.domain_id=d_answer.domain_id; - sd.ttl=d_answer.ttl; + else if(cstat==1 && !d_answers.empty()) { + fillSOAData(d_answers[0].content,sd); + sd.domain_id=d_answers[0].domain_id; + sd.ttl=d_answers[0].ttl; sd.db=0; return true; } @@ -241,7 +242,9 @@ bool UeberBackend::getSOA(const string &domain, SOAData &sd, DNSPacket *p) rr.content=serializeSOAData(sd); rr.ttl=sd.ttl; rr.domain_id=sd.domain_id; - addOneCache(d_question,rr); + vector rrs; + rrs.push_back(rr); + addCache(d_question, rrs); return true; } @@ -301,7 +304,8 @@ void UeberBackend::cleanup() // silly Solaris fix #undef PC -int UeberBackend::cacheHas(const Question &q, DNSResourceRecord &rr) +// returns -1 for miss, 0 for negative match, 1 for hit +int UeberBackend::cacheHas(const Question &q, vector &rrs) { extern PacketCache PC; static unsigned int *qcachehit=S.getPointer("query-cache-hit"); @@ -318,8 +322,7 @@ int UeberBackend::cacheHas(const Question &q, DNSResourceRecord &rr) string content; // L<> rrs; return 1; } @@ -337,18 +344,22 @@ void UeberBackend::addNegCache(const Question &q) static int negqueryttl=::arg().asNum("negquery-cache-ttl"); if(!negqueryttl) return; - // L< &rrs) { extern PacketCache PC; static int queryttl=::arg().asNum("query-cache-ttl"); if(!queryttl) return; + // L< *ips) @@ -396,8 +407,8 @@ void UeberBackend::lookup(const QType &qtype,const string &qname, DNSPacket *pkt else { d_question.qtype=qtype; d_question.qname=qname; - d_question.zoneId=zoneId; - int cstat=cacheHas(d_question,d_answer); + d_question.zoneId=-1; + int cstat=cacheHas(d_question, d_answers); if(cstat<0) { // nothing d_negcached=d_cached=false; (d_handle.d_hinterBackend=backends[d_handle.i++])->lookup(qtype, qname,pkt_p,zoneId); @@ -405,15 +416,16 @@ void UeberBackend::lookup(const QType &qtype,const string &qname, DNSPacket *pkt else if(cstat==0) { d_negcached=true; d_cached=false; + d_answers.clear(); } else { d_negcached=false; d_cached=true; + d_cachehandleiter = d_answers.begin(); } } d_handle.parent=this; - } bool UeberBackend::get(DNSResourceRecord &rr) @@ -423,24 +435,22 @@ bool UeberBackend::get(DNSResourceRecord &rr) } if(d_cached) { - rr=d_answer; - d_negcached=true; // ugly, confusing - return true; + if(d_cachehandleiter != d_answers.end()) { + rr=*d_cachehandleiter++;; + return true; + } + return false; } if(!d_handle.get(rr)) { if(!d_ancount && !d_handle.qname.empty()) // don't cache axfr addNegCache(d_question); - if(d_ancount==1) { - addOneCache(d_question, lastrr); - } - + addCache(d_question, d_answers); + d_answers.clear(); return false; } - - if(!d_ancount++) { - lastrr=rr; - } + d_ancount++; + d_answers.push_back(rr); return true; } diff --git a/pdns/ueberbackend.hh b/pdns/ueberbackend.hh index 962e3a60a..ea8dfbb74 100644 --- a/pdns/ueberbackend.hh +++ b/pdns/ueberbackend.hh @@ -149,11 +149,12 @@ private: string qname; int zoneId; }d_question; - DNSResourceRecord d_answer; + vector d_answers; + vector::const_iterator d_cachehandleiter; - int cacheHas(const Question &q, DNSResourceRecord &rr); + int cacheHas(const Question &q, vector &rrs); void addNegCache(const Question &q); - void addOneCache(const Question &q, const DNSResourceRecord &rr); + void addCache(const Question &q, const vector &rrs); static pthread_mutex_t d_mut; static pthread_cond_t d_cond;