]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
slaveRefresh: avoid extra SOA lookups
authorChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Mon, 14 Sep 2020 20:36:55 +0000 (22:36 +0200)
committerChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Thu, 24 Sep 2020 12:02:40 +0000 (14:02 +0200)
For incoming NOTIFYs, we already call getDomainInfo, so reuse the serial
from there. For unfresh domains, we already have a serial from the
backend.

However, a serial of 0 is now always considered stale.

pdns/slavecommunicator.cc

index f31d3d8d7fb08b8646e82f368c6e236f9198ae50..a524069e39c6bd44b6e77d4374ebc2313fc844da 100644 (file)
@@ -900,7 +900,9 @@ void CommunicatorClass::slaveRefresh(PacketHandler *P)
   time_t now = time(0);
   for(auto& val : sdomains) {
     DomainInfo& di(val.di);
-    // might've come from the packethandler
+    // If our di comes from packethandler (caused by incoming NOTIFY), di.backend will not be filled out,
+    // and di.serial will not either.
+    // Conversely, if our di came from getUnfreshSlaveInfos, di.backend and di.serial are valid.
     if(!di.backend) {
       // Do not overwrite received DI just to make sure it exists in backend:
       // di.masters should contain the picked master (as first entry)!
@@ -912,6 +914,7 @@ void CommunicatorClass::slaveRefresh(PacketHandler *P)
       // Backend for di still doesn't exist and this might cause us to
       // SEGFAULT on the setFresh command later on
       di.backend = tempdi.backend;
+      di.serial = tempdi.serial;
     }
 
     if(!ssr.d_freshness.count(di.id)) { // If we don't have an answer for the domain
@@ -939,30 +942,15 @@ void CommunicatorClass::slaveRefresh(PacketHandler *P)
         d_failedSlaveRefresh.erase(di.zone);
     }
 
-    bool hasSOA = false;
-    SOAData sd;
-    sd.serial = 0;
-    try {
-      // Use UeberBackend cache for SOA. Cache gets cleared after AXFR/IXFR.
-      B->lookup(QType(QType::SOA), di.zone, di.id, nullptr);
-      DNSZoneRecord zr;
-      hasSOA = B->get(zr);
-      if (hasSOA) {
-        fillSOAData(zr, sd);
-        while(B->get(zr));
-      }
-    }
-    catch(...) {}
-
     uint32_t theirserial = ssr.d_freshness[di.id].theirSerial;
-    uint32_t ourserial = sd.serial;
+    uint32_t ourserial = di.serial;
     const ComboAddress remote = *di.masters.begin();
 
     if(rfc1982LessThan(theirserial, ourserial) && ourserial != 0 && !::arg().mustDo("axfr-lower-serial"))  {
       g_log<<Logger::Error<<"Domain '" << di.zone << "' more recent than master " << remote.toStringWithPortExcept(53) << ", our serial "<< ourserial<< " > their serial "<< theirserial << endl;
       di.backend->setFresh(di.id);
     }
-    else if(hasSOA && theirserial == ourserial) {
+    else if(ourserial != 0 && theirserial == ourserial) {
       uint32_t maxExpire=0, maxInception=0;
       if(dk.isPresigned(di.zone)) {
         B->lookup(QType(QType::RRSIG), di.zone, di.id); // can't use DK before we are done with this lookup!
@@ -1001,12 +989,11 @@ void CommunicatorClass::slaveRefresh(PacketHandler *P)
       }
     }
     else {
-      if(hasSOA) {
+      if (ourserial == 0) {
+        g_log<<Logger::Warning<<"Domain '"<< di.zone << "' has serial zero, forcing transfer, master " << remote.toStringWithPortExcept(53) << " serial " << theirserial << endl;
+      } else {
         g_log<<Logger::Warning<<"Domain '"<< di.zone << "' is stale, master " << remote.toStringWithPortExcept(53) << " serial " << theirserial << ", our serial " << ourserial << endl;
       }
-      else {
-        g_log<<Logger::Warning<<"Domain '"<< di.zone << "' is empty, master " << remote.toStringWithPortExcept(53) << " serial " << theirserial << endl;
-      }
       addSuckRequest(di.zone, remote);
     }
   }