From bd78c8726fd09008a69762d91280bcc76763046e Mon Sep 17 00:00:00 2001 From: Kees Monshouwer Date: Wed, 6 Feb 2019 22:28:10 +0100 Subject: [PATCH] auth: speedup getUpdatedMasters() for the gsql backends --- modules/gmysqlbackend/gmysqlbackend.cc | 2 +- modules/godbcbackend/godbcbackend.cc | 2 +- modules/gpgsqlbackend/gpgsqlbackend.cc | 2 +- modules/gsqlite3backend/gsqlite3backend.cc | 2 +- pdns/backends/gsql/gsqlbackend.cc | 49 +++++++++++----------- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/modules/gmysqlbackend/gmysqlbackend.cc b/modules/gmysqlbackend/gmysqlbackend.cc index e3033abe3..6bdb5fa3e 100644 --- a/modules/gmysqlbackend/gmysqlbackend.cc +++ b/modules/gmysqlbackend/gmysqlbackend.cc @@ -120,7 +120,7 @@ public: declare(suffix,"update-account-query","", "update domains set account=? where name=?"); declare(suffix,"update-serial-query","", "update domains set notified_serial=? where id=?"); declare(suffix,"update-lastcheck-query","", "update domains set last_check=? where id=?"); - declare(suffix,"info-all-master-query","", "select id,name,master,last_check,notified_serial,type from domains where type='MASTER'"); + declare(suffix,"info-all-master-query","", "select d.id, d.name, d.notified_serial, r.content from records r join domains d on r.name=d.name where r.type='SOA' and r.disabled=0 and d.type='MASTER'"); declare(suffix,"delete-domain-query","", "delete from domains where name=?"); declare(suffix,"delete-zone-query","", "delete from records where domain_id=?"); declare(suffix,"delete-rrset-query","","delete from records where domain_id=? and name=? and type=?"); diff --git a/modules/godbcbackend/godbcbackend.cc b/modules/godbcbackend/godbcbackend.cc index 7334df4c9..533f50f95 100644 --- a/modules/godbcbackend/godbcbackend.cc +++ b/modules/godbcbackend/godbcbackend.cc @@ -107,7 +107,7 @@ public: declare(suffix,"update-account-query","", "update domains set account=? where name=?"); declare(suffix,"update-serial-query","", "update domains set notified_serial=? where id=?"); declare(suffix,"update-lastcheck-query","", "update domains set last_check=? where id=?"); - declare(suffix,"info-all-master-query","", "select id,name,master,last_check,notified_serial,type from domains where type='MASTER'"); + declare(suffix,"info-all-master-query","", "select domains.id, domains.name, domains.notified_serial, records.content from records join domains on records.name=domains.name where records.type='SOA' and records.disabled=0 and domains.type='MASTER'"); declare(suffix,"delete-domain-query","", "delete from domains where name=?"); declare(suffix,"delete-zone-query","", "delete from records where domain_id=?"); declare(suffix,"delete-rrset-query","","delete from records where domain_id=? and name=? and type=?"); diff --git a/modules/gpgsqlbackend/gpgsqlbackend.cc b/modules/gpgsqlbackend/gpgsqlbackend.cc index 641f74bb1..cc1c601de 100644 --- a/modules/gpgsqlbackend/gpgsqlbackend.cc +++ b/modules/gpgsqlbackend/gpgsqlbackend.cc @@ -129,7 +129,7 @@ public: declare(suffix,"update-account-query","", "update domains set account=$1 where name=$2"); declare(suffix,"update-serial-query","", "update domains set notified_serial=$1 where id=$2"); declare(suffix,"update-lastcheck-query","", "update domains set last_check=$1 where id=$2"); - declare(suffix,"info-all-master-query","", "select id,name,master,last_check,notified_serial,type from domains where type='MASTER'"); + declare(suffix,"info-all-master-query","", "select domains.id, domains.name, domains.notified_serial, records.content from records join domains on records.name=domains.name where records.type='SOA' and records.disabled=false and domains.type='MASTER'"); declare(suffix,"delete-domain-query","", "delete from domains where name=$1"); declare(suffix,"delete-zone-query","", "delete from records where domain_id=$1"); declare(suffix,"delete-rrset-query","","delete from records where domain_id=$1 and name=$2 and type=$3"); diff --git a/modules/gsqlite3backend/gsqlite3backend.cc b/modules/gsqlite3backend/gsqlite3backend.cc index f9cb892fc..28eddf2aa 100644 --- a/modules/gsqlite3backend/gsqlite3backend.cc +++ b/modules/gsqlite3backend/gsqlite3backend.cc @@ -119,7 +119,7 @@ public: declare(suffix, "update-account-query","", "update domains set account=:account where name=:domain"); declare(suffix, "update-serial-query", "", "update domains set notified_serial=:serial where id=:domain_id"); declare(suffix, "update-lastcheck-query", "", "update domains set last_check=:last_check where id=:domain_id"); - declare(suffix, "info-all-master-query", "", "select id,name,master,last_check,notified_serial,type from domains where type='MASTER'"); + declare(suffix, "info-all-master-query", "", "select domains.id, domains.name, domains.notified_serial, records.content from records join domains on records.name=domains.name where records.type='SOA' and records.disabled=0 and domains.type='MASTER'"); declare(suffix, "delete-domain-query","", "delete from domains where name=:domain"); declare(suffix, "delete-zone-query", "", "delete from records where domain_id=:domain_id"); declare(suffix, "delete-rrset-query", "", "delete from records where domain_id=:domain_id and name=:qname and type=:qtype"); diff --git a/pdns/backends/gsql/gsqlbackend.cc b/pdns/backends/gsql/gsqlbackend.cc index 74864b004..5e4d9070c 100644 --- a/pdns/backends/gsql/gsqlbackend.cc +++ b/pdns/backends/gsql/gsqlbackend.cc @@ -375,7 +375,7 @@ void GSQLBackend::getUnfreshSlaveInfos(vector *unfreshDomains) void GSQLBackend::getUpdatedMasters(vector *updatedDomains) { /* list all domains that need notifications for which we are master, and insert into updatedDomains - id,name,master IP,serial */ + id, name, notified_serial, serial */ try { reconnectIfNeeded(); @@ -388,32 +388,33 @@ void GSQLBackend::getUpdatedMasters(vector *updatedDomains) throw PDNSException("GSQLBackend unable to retrieve list of master domains: "+e.txtReason()); } - vector allMasters; size_t numanswers=d_result.size(); - for(size_t n=0;nparts; + DomainInfo di; + + di.backend = this; + di.kind = DomainInfo::Master; + + for( size_t n = 0; n < numanswers; ++n ) { // id, name, notified_serial, content + ASSERT_ROW_COLUMNS( "info-all-master-query", d_result[n], 4 ); + + parts.clear(); + stringtok( parts, d_result[n][3] ); + try { - sd.zone= DNSName(d_result[n][1]); - } catch (...) { - continue; - } - sd.last_check=pdns_stou(d_result[n][3]); - sd.notified_serial=pdns_stou(d_result[n][4]); - sd.backend=this; - sd.kind=DomainInfo::Master; - allMasters.push_back(sd); - } + uint32_t serial = parts.size() > 2 ? pdns_stou(parts[2]) : 0; + uint32_t notified_serial = pdns_stou( d_result[n][2] ); - for(vector::iterator i=allMasters.begin();i!=allMasters.end();++i) { - SOAData sdata; - sdata.serial=0; - sdata.refresh=0; - getSOA(i->zone,sdata); - if(i->notified_serial!=sdata.serial) { - i->serial=sdata.serial; - updatedDomains->push_back(*i); + if( serial != notified_serial ) { + di.id = pdns_stou( d_result[n][0] ); + di.zone = DNSName( d_result[n][1] ); + di.serial = serial; + di.notified_serial = notified_serial; + + updatedDomains->emplace_back(di); + } + } catch ( ... ) { + continue; } } } -- 2.40.0