Permalink
Browse files

cut the number of database queries in half for AXFR-in

  • Loading branch information...
1 parent 7a4cba2 commit f9cf6d92ed18974133580595bbdef45bfcd73048 @mind04 mind04 committed with mind04 May 9, 2013
@@ -87,9 +87,14 @@ class gMySQLFactory : public BackendFactory
declare(suffix,"info-all-slaves-query","","select id,name,master,last_check,type from domains where type='SLAVE'");
declare(suffix,"supermaster-query","", "select account from supermasters where ip='%s' and nameserver='%s'");
declare(suffix,"insert-slave-query","", "insert into domains (type,name,master,account) values('SLAVE','%s','%s','%s')");
+
declare(suffix,"insert-record-query","", "insert into records (content,ttl,prio,type,domain_id,name) values ('%s',%d,%d,'%s',%d,'%s')");
- declare(suffix,"insert-record-query-auth","", "insert into records (content,ttl,prio,type,domain_id,name,auth) values ('%s',%d,%d,'%s',%d,'%s', '%d')");
-
+ declare(suffix,"insert-record-query-auth","", "insert into records (content,ttl,prio,type,domain_id,name,auth) values ('%s',%d,%d,'%s',%d,'%s','%d')");
+ declare(suffix,"insert-record-order-query-auth","", "insert into records (content,ttl,prio,type,domain_id,name,ordername,auth) values ('%s',%d,%d,'%s',%d,'%s','%s','%d')");
+ declare(suffix,"insert-ent-query", "insert empty non-terminal in zone", "insert into records (type,domain_id,name) values (null,'%d','%s')");
+ declare(suffix,"insert-ent-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,name,auth) values (null,'%d','%s','1')");
+ declare(suffix,"insert-ent-order-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,name,ordername,auth) values (null,'%d','%s','%s','1')");
+
declare(suffix,"get-order-first-query","DNSSEC Ordering Query, first", "select ordername, name from records where domain_id=%d and ordername is not null order by 1 asc limit 1");
declare(suffix,"get-order-before-query","DNSSEC Ordering Query, before", "select ordername, name from records where ordername <= '%s' and domain_id=%d and ordername is not null order by 1 desc limit 1");
declare(suffix,"get-order-after-query","DNSSEC Ordering Query, after", "select min(ordername) from records where ordername > '%s' and domain_id=%d and ordername is not null");
@@ -87,8 +87,13 @@ class gPgSQLFactory : public BackendFactory
declare(suffix,"info-all-slaves-query","","select id,name,master,last_check,type from domains where type='SLAVE'");
declare(suffix,"supermaster-query","", "select account from supermasters where ip='%s' and nameserver=E'%s'");
declare(suffix,"insert-slave-query","", "insert into domains (type,name,master,account) values('SLAVE',E'%s',E'%s',E'%s')");
+
declare(suffix,"insert-record-query","", "insert into records (content,ttl,prio,type,domain_id,name) values (E'%s',%d,%d,'%s',%d,E'%s')");
- declare(suffix,"insert-record-query-auth","", "insert into records (content,ttl,prio,type,domain_id,name,auth) values (E'%s',%d,%d,'%s',%d,E'%s', '%d')");
+ declare(suffix,"insert-record-query-auth","", "insert into records (content,ttl,prio,type,domain_id,name,auth) values (E'%s',%d,%d,'%s',%d,E'%s','%d')");
+ declare(suffix,"insert-record-order-query-auth","", "insert into records (content,ttl,prio,type,domain_id,name,ordername,auth) values (E'%s',%d,%d,'%s',%d,E'%s',E'%s','%d')");
+ declare(suffix,"insert-ent-query", "insert empty non-terminal in zone", "insert into records (type,domain_id,name) values (null,'%d',E'%s')");
+ declare(suffix,"insert-ent-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,name,auth) values (null,'%d',E'%s',true)");
+ declare(suffix,"insert-ent-order-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,name,ordername,auth) values (null,'%d',E'%s',E'%s',true)");
declare(suffix,"get-order-first-query","DNSSEC Ordering Query, last", "select ordername, name from records where domain_id=%d and ordername is not null order by 1 using ~<~ limit 1");
declare(suffix,"get-order-before-query","DNSSEC Ordering Query, before", "select ordername, name from records where ordername ~<=~ E'%s' and domain_id=%d and ordername is not null order by 1 using ~>~ limit 1");
@@ -106,9 +106,14 @@ class gSQLite3Factory : public BackendFactory
declare( suffix, "info-all-slaves-query", "","select id,name,master,last_check,type from domains where type='SLAVE'");
declare( suffix, "supermaster-query", "", "select account from supermasters where ip='%s' and nameserver='%s'");
declare( suffix, "insert-slave-query", "", "insert into domains (type,name,master,account) values('SLAVE','%s','%s','%s')");
+
declare( suffix, "insert-record-query", "", "insert into records (content,ttl,prio,type,domain_id,name) values ('%s',%d,%d,'%s',%d,'%s')");
- declare( suffix, "insert-record-query-auth", "", "insert into records (content,ttl,prio,type,domain_id,name,auth) values ('%s',%d,%d,'%s',%d,'%s', %d)");
-
+ declare( suffix, "insert-record-query-auth", "", "insert into records (content,ttl,prio,type,domain_id,name,auth) values ('%s',%d,%d,'%s',%d,'%s',%d)");
+ declare( suffix, "insert-record-order-query-auth","", "insert into records (content,ttl,prio,type,domain_id,name,ordername,auth) values ('%s',%d,%d,'%s',%d,'%s','%s','%d')");
+ declare( suffix, "insert-ent-query", "insert empty non-terminal in zone", "insert into records (type,domain_id,name) values (null,'%d','%s')");
+ declare( suffix, "insert-ent-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,name,auth) values (null,'%d','%s','1')");
+ declare( suffix, "insert-ent-order-query-auth", "insert empty non-terminal in zone", "insert into records (type,domain_id,name,ordername,auth) values (null,'%d','%s','%s','1')");
+
declare( suffix, "update-serial-query", "", "update domains set notified_serial=%d where id=%d");
declare( suffix, "update-lastcheck-query", "", "update domains set last_check=%d where id=%d");
declare (suffix, "zone-lastchange-query", "", "select max(change_date) from records where domain_id=%d");
@@ -233,7 +233,7 @@ bool Bind2Backend::updateDNSSECOrderAndAuthAbsolute(uint32_t domain_id, const st
return false;
}
-bool Bind2Backend::feedRecord(const DNSResourceRecord &r)
+bool Bind2Backend::feedRecord(const DNSResourceRecord &r, string *ordername)
{
string qname=r.qname;
@@ -141,7 +141,7 @@ public:
void setNotified(uint32_t id, uint32_t serial);
bool startTransaction(const string &qname, int id);
// bool Bind2Backend::stopTransaction(const string &qname, int id);
- bool feedRecord(const DNSResourceRecord &r);
+ bool feedRecord(const DNSResourceRecord &r, string *ordername=0);
bool commitTransaction();
bool abortTransaction();
bool updateDNSSECOrderAndAuthAbsolute(uint32_t domain_id, const std::string& qname, const std::string& ordername, bool auth);
@@ -34,6 +34,8 @@
#include "pdns/ahuexception.hh"
#include "pdns/logger.hh"
#include "pdns/arguments.hh"
+#include "pdns/base32.hh"
+#include "pdns/dnssecinfra.hh"
#include <boost/algorithm/string.hpp>
#include <sstream>
#include <boost/foreach.hpp>
@@ -273,6 +275,7 @@ GSQLBackend::GSQLBackend(const string &mode, const string &suffix)
d_SuperMasterInfoQuery=getArg("supermaster-query");
d_InsertSlaveZoneQuery=getArg("insert-slave-query");
d_InsertRecordQuery=getArg("insert-record-query"+authswitch);
+ d_InsertEntQuery=getArg("insert-ent-query"+authswitch);
d_UpdateSerialOfZoneQuery=getArg("update-serial-query");
d_UpdateLastCheckofZoneQuery=getArg("update-lastcheck-query");
d_ZoneLastChangeQuery=getArg("zone-lastchange-query");
@@ -287,6 +290,9 @@ GSQLBackend::GSQLBackend(const string &mode, const string &suffix)
if (d_dnssecQueries)
{
+ d_InsertRecordOrderQuery=getArg("insert-record-order-query-auth");
+ d_InsertEntOrderQuery=getArg("insert-ent-order-query-auth");
+
d_firstOrderQuery = getArg("get-order-first-query");
d_beforeOrderQuery = getArg("get-order-before-query");
d_afterOrderQuery = getArg("get-order-after-query");
@@ -884,15 +890,18 @@ bool GSQLBackend::replaceRRSet(uint32_t domain_id, const string& qname, const QT
return true;
}
-bool GSQLBackend::feedRecord(const DNSResourceRecord &r)
+bool GSQLBackend::feedRecord(const DNSResourceRecord &r, string *ordername)
{
string output;
if(d_dnssecQueries) {
- output = (boost::format(d_InsertRecordQuery) % sqlEscape(r.content) % r.ttl % r.priority % sqlEscape(r.qtype.getName()) % r.domain_id % toLower(sqlEscape(r.qname)) % (int)r.auth).str();
+ if(ordername)
+ output = (boost::format(d_InsertRecordOrderQuery) % sqlEscape(r.content) % r.ttl % r.priority % sqlEscape(r.qtype.getName()) % r.domain_id % toLower(sqlEscape(r.qname)) % sqlEscape(*ordername) % (int)r.auth).str();
+ else
+ output = (boost::format(d_InsertRecordQuery) % sqlEscape(r.content) % r.ttl % r.priority % sqlEscape(r.qtype.getName()) % r.domain_id % toLower(sqlEscape(r.qname)) % (int)r.auth).str();
} else {
output = (boost::format(d_InsertRecordQuery) % sqlEscape(r.content) % r.ttl % r.priority % sqlEscape(r.qtype.getName()) % r.domain_id % toLower(sqlEscape(r.qname))).str();
}
-
+
try {
d_db->doCommand(output.c_str());
}
@@ -902,6 +911,46 @@ bool GSQLBackend::feedRecord(const DNSResourceRecord &r)
return true; // XXX FIXME this API should not return 'true' I think -ahu
}
+bool GSQLBackend::feedEnts(int domain_id, set<string>& nonterm)
+{
+ string output;
+ BOOST_FOREACH(const string qname, nonterm) {
+ output = (boost::format(d_InsertEntQuery) % domain_id % toLower(sqlEscape(qname))).str();
+
+ try {
+ d_db->doCommand(output.c_str());
+ }
+ catch (SSqlException &e) {
+ throw AhuException("GSQLBackend unable to feed empty non-terminal: "+e.txtReason());
+ }
+ }
+ return true;
+}
+
+bool GSQLBackend::feedEnts3(int domain_id, const string &domain, set<string> &nonterm, unsigned int times, const string &salt, bool narrow)
+{
+ if(!d_dnssecQueries)
+ return false;
+
+ string ordername, output;
+ BOOST_FOREACH(const string qname, nonterm) {
+ if(narrow) {
+ output = (boost::format(d_InsertEntQuery) % domain_id % toLower(sqlEscape(qname))).str();
+ } else {
+ ordername=toBase32Hex(hashQNameWithSalt(times, salt, qname));
+ output = (boost::format(d_InsertEntOrderQuery) % domain_id % toLower(sqlEscape(qname)) % toLower(sqlEscape(ordername))).str();
+ }
+
+ try {
+ d_db->doCommand(output.c_str());
+ }
+ catch (SSqlException &e) {
+ throw AhuException("GSQLBackend unable to feed empty non-terminal: "+e.txtReason());
+ }
+ }
+ return true;
+}
+
bool GSQLBackend::startTransaction(const string &domain, int domain_id)
{
char output[1024];
@@ -32,7 +32,9 @@ public:
bool startTransaction(const string &domain, int domain_id=-1);
bool commitTransaction();
bool abortTransaction();
- bool feedRecord(const DNSResourceRecord &r);
+ bool feedRecord(const DNSResourceRecord &r, string *ordername=0);
+ bool feedEnts(int domain_id, set<string>& nonterm);
+ bool feedEnts3(int domain_id, const string &domain, set<string> &nonterm, unsigned int times, const string &salt, bool narrow);
bool createSlaveDomain(const string &ip, const string &domain, const string &account);
bool superMasterBackend(const string &ip, const string &domain, const vector<DNSResourceRecord>&nsset, string *account, DNSBackend **db);
void setFresh(uint32_t domain_id);
@@ -86,6 +88,9 @@ private:
string d_SuperMasterInfoQuery;
string d_InsertSlaveZoneQuery;
string d_InsertRecordQuery;
+ string d_InsertEntQuery;
+ string d_InsertRecordOrderQuery;
+ string d_InsertEntOrderQuery;
string d_UpdateSerialOfZoneQuery;
string d_UpdateLastCheckofZoneQuery;
string d_InfoOfAllMasterDomainsQuery;
View
@@ -201,10 +201,19 @@ public:
}
//! feeds a record to a zone, needs a call to startTransaction first
- virtual bool feedRecord(const DNSResourceRecord &rr)
+ virtual bool feedRecord(const DNSResourceRecord &rr, string *ordername=0)
{
return false; // no problem!
}
+ virtual bool feedEnts(int domain_id, set<string> &nonterm)
+ {
+ return false;
+ }
+ virtual bool feedEnts3(int domain_id, const string &domain, set<string> &nonterm, unsigned int times, const string &salt, bool narrow)
+ {
+ return false;
+ }
+
//! if this returns true, DomainInfo di contains information about the domain
virtual bool getDomainInfo(const string &domain, DomainInfo &di)
{
Oops, something went wrong.

0 comments on commit f9cf6d9

Please sign in to comment.