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=?");
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=?");
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");
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");
void GSQLBackend::getUpdatedMasters(vector<DomainInfo> *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();
throw PDNSException("GSQLBackend unable to retrieve list of master domains: "+e.txtReason());
}
- vector<DomainInfo> allMasters;
size_t numanswers=d_result.size();
- for(size_t n=0;n<numanswers;++n) { // id,name,master,last_check,notified_serial
- DomainInfo sd;
- ASSERT_ROW_COLUMNS("info-all-master-query", d_result[n], 6);
- sd.id=pdns_stou(d_result[n][0]);
+ vector<string>parts;
+ 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<DomainInfo>::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;
}
}
}