]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Code cleanup, move commitTransaction within try-block
authorRuben d'Arco <cyclops@prof-x.net>
Sun, 10 Mar 2013 16:19:18 +0000 (17:19 +0100)
committermind04 <mind04@monshouwer.org>
Fri, 12 Jul 2013 15:26:18 +0000 (17:26 +0200)
pdns/packetcache.cc
pdns/packetcache.hh
pdns/rfc2136handler.cc

index 4a81be404bc6ff1fe0f7a8e8a8974b4ab2df362b..d62b7294ef28c92be64c331e8179af99cffa3ac3 100644 (file)
@@ -254,38 +254,6 @@ int PacketCache::purge(const string &match)
   return delcount;
 }
 
-int PacketCache::purgeRange(const string &begin, const string &end, const string &zone) {
-  WriteLock l(&d_mut);
-  int size=d_map.size();
-  if (size == 0)
-    return 0;
-
-  // Search for the beginning for the purge range
-  cmap_t::const_iterator beginIter = d_map.lower_bound(tie(begin));
-  if (beginIter == d_map.end() || !iends_with(beginIter->qname,zone)) {
-    beginIter = d_map.lower_bound(tie(zone));
-  }
-
-  if (beginIter == d_map.end() || !iends_with(beginIter->qname,zone)) // Couldn't find begin and not the zone? This thing is simply not in the cache!
-    return 0;
-
-  // Search for the end. We make sure we run all the way to the end (because the first match might be a different qtype)
-  cmap_t::const_iterator endIter = beginIter;
-  bool endIterFound=false;
-  for (; endIter != d_map.end(); ++endIter) {
-    if ((endIterFound && !iends_with(endIter->qname, end)) || !iends_with(endIter->qname, zone))
-      break;
-
-    if (iends_with(endIter->qname, end))
-      endIterFound=true;
-  }
-  
-  // Finally erase things.
-  d_map.erase(beginIter, endIter);
-  *d_statnumentries=d_map.size();
-  return size - *d_statnumentries;
-}
-
 // called from ueberbackend
 bool PacketCache::getEntry(const string &qname, const QType& qtype, CacheEntryType cet, string& value, int zoneID, bool meritsRecursion, 
   unsigned int maxReplyLen, bool dnssecOk, bool hasEDNS)
index 0c8fcd5fe02a25071f71f29fb70ebc1191578c48..b60fccda63efb0b1ad249bf7a103b28bbb708506 100644 (file)
@@ -82,8 +82,6 @@ public:
   void cleanup(); //!< force the cache to preen itself from expired packets
   int purge();
   int purge(const string &match);
-  int purgeRange(const string &begin, const string &end, const string &zone);
-
 
   map<char,int> getCounts();
 private:
index 826f4f1416ba978d494f1db0c03857b10563bbbd..e5a1444aca15471b92918ba52d01b24dc707c6a9 100755 (executable)
@@ -312,14 +312,14 @@ uint16_t PacketHandler::performUpdate(const string &msgPrefix, const DNSRecord *
         d_dk.unsetNSEC3PARAM(rrLabel);
       else if (rr->d_class == QClass::NONE) {
         NSEC3PARAMRecordContent nsec3rr(rr->d_content->getZoneRepresentation(), di->zone);
-       if (ns3pr->getZoneRepresentation() == nsec3rr.getZoneRepresentation())
+        if (ns3pr->getZoneRepresentation() == nsec3rr.getZoneRepresentation())
           d_dk.unsetNSEC3PARAM(rrLabel);
         else
           return 0;
       } else 
         return 0;
 
-      *haveNSEC3 = d_dk.getNSEC3PARAM(di->zone, ns3pr, narrow);
+      *haveNSEC3 = d_dk.getNSEC3PARAM(di->zone, ns3pr, narrow); // still update, as other records in this update packet need to use it as well.
       di->backend->list(di->zone, di->id);
       vector<DNSResourceRecord> rrs;
       while (di->backend->get(rec)) {
@@ -413,22 +413,6 @@ uint16_t PacketHandler::performUpdate(const string &msgPrefix, const DNSRecord *
           else
             break;
         }
-
-/*        do {
-          bool foundRealRR=false;
-          if (shorter == di->zone)
-            break; //we're at the top.
-
-          di->backend->lookup(QType(QType::ANY), shorter);
-          while (di->backend->get(rec)) {
-            if (rec.qtype.getCode())
-              foundRealRR=true;
-          }
-          if (!foundRealRR)
-            delnonterm.insert(shorter);
-          else
-            break; // we found a real record - tree is ok again.
-        }while(chopOff(shorter));*/
       }
     }
   }
@@ -711,10 +695,9 @@ int PacketHandler::processUpdate(DNSPacket *p) {
 
 
 
-  // 3.4 - Prescan & Add/Update/Delete records
-  uint16_t changedRecords = 0;
+  // 3.4 - Prescan & Add/Update/Delete records - is all done within a try block.
   try {
-
+    uint16_t changedRecords = 0;
     // 3.4.1 - Prescan section
     for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i != mdp.d_answers.end(); ++i) {
       const DNSRecord *rr = &i->first;
@@ -734,21 +717,6 @@ int PacketHandler::processUpdate(DNSPacket *p) {
     bool haveNSEC3 = d_dk.getNSEC3PARAM(di.zone, &ns3pr, &narrow);
     bool isPresigned = d_dk.isPresigned(di.zone);
 
-    // We get all the before/after fields before doing anything to the db.
-    // We can't do this inside performUpdate() because when we remove a delegate, the before/after result is different to what it should be
-    // to purge the cache correctly - One update/delete might cause a before/after to be created which is before/after the original before/after.
-    vector< pair<string, string> > beforeAfterSet;
-    /*if (!haveNSEC3) {
-      for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i != mdp.d_answers.end(); ++i) {
-        const DNSRecord *rr = &i->first;
-        if (rr->d_place == DNSRecord::Nameserver) {
-          string before, after;
-          di.backend->getBeforeAndAfterNames(di.id, di.zone, stripDot(rr->d_label), before, after, (rr->d_class != QClass::IN));
-          beforeAfterSet.push_back(make_pair(before, after));
-        }
-      }
-    }*/
-
     // 3.4.2 - Perform the updates.
     // There's a special condition where deleting the last NS record at zone apex is never deleted (3.4.2.4)
     // This means we must do it outside the normal performUpdate() because that focusses only on a seperate RR.
@@ -779,30 +747,31 @@ int PacketHandler::processUpdate(DNSPacket *p) {
       }
     }
 
-    // Purge the records!
-    string zone(di.zone);
-    zone.append("$");
-    PC.purge(zone);  // For NSEC3, nuke the complete zone.
-/*
-    if (changedRecords > 0) {
-      if (haveNSEC3) {
-        string zone(di.zone);
-        zone.append("$");
-        PC.purge(zone);  // For NSEC3, nuke the complete zone.
-      } else {
-        //for(vector< pair<string, string> >::const_iterator i=beforeAfterSet.begin(); i != beforeAfterSet.end(); i++)
-          //PC.purgeRange(i->first, i->second, di.zone);
-      }
-    }
-*/
     // Section 3.6 - Update the SOA serial - outside of performUpdate because we do a SOA update for the complete update message
     if (changedRecords > 0 && !updatedSerial) {
       increaseSerial(msgPrefix, &di, haveNSEC3, narrow, &ns3pr);
       changedRecords++;
     }
 
+    if (!di.backend->commitTransaction()) {
+      L<<Logger::Error<<msgPrefix<<"Failed to commit updates!"<<endl;
+      return RCode::ServFail;
+    }
+   
     S.deposit("rfc2136-changes", changedRecords);
 
+    // Purge the records!
+    string zone(di.zone);
+    zone.append("$");
+    PC.purge(zone);
+
+    L<<Logger::Info<<msgPrefix<<"Update completed, "<<changedRecords<<" changed records commited."<<endl;
+    return RCode::NoError; //rfc 2136 3.4.2.5
+  }
+  catch (SSqlException &e) {
+    L<<Logger::Error<<msgPrefix<<"Caught SSqlException: "<<e.txtReason()<<"; Sending ServFail!"<<endl;
+    di.backend->abortTransaction();
+    return RCode::ServFail;
   }
   catch (DBException &e) {
     L<<Logger::Error<<msgPrefix<<"Caught DBException: "<<e.reason<<"; Sending ServFail!"<<endl;
@@ -814,24 +783,11 @@ int PacketHandler::processUpdate(DNSPacket *p) {
     di.backend->abortTransaction();
     return RCode::ServFail;
   }
-  catch (SSqlException &e) {
-    L<<Logger::Error<<msgPrefix<<"Caught SSqlException: "<<e.txtReason()<<"; Sending ServFail!"<<endl;
-    di.backend->abortTransaction();
-    return RCode::ServFail;
-  }  
   catch (...) {
     L<<Logger::Error<<msgPrefix<<"Caught unknown exception when performing update. Sending ServFail!"<<endl;
     di.backend->abortTransaction();
     return RCode::ServFail;
   }
-  
-  if (!di.backend->commitTransaction()) {
-    L<<Logger::Error<<msgPrefix<<"Failed to commit update for domain "<<di.zone<<"!"<<endl;
-    return RCode::ServFail;
-  }
-  L<<Logger::Info<<msgPrefix<<"Update completed, "<<changedRecords<<" changed records commited."<<endl;
-  return RCode::NoError; //rfc 2136 3.4.2.5
 }
 
 void PacketHandler::increaseSerial(const string &msgPrefix, const DomainInfo *di, bool haveNSEC3, bool narrow, const NSEC3PARAMRecordContent *ns3pr) {
@@ -909,7 +865,4 @@ void PacketHandler::increaseSerial(const string &msgPrefix, const DomainInfo *di
   }
   else // NSEC
     di->backend->updateDNSSECOrderAndAuth(di->id, di->zone, newRec.qname, true);
-
-  // purge the cache for the SOA record.
-  PC.purge(newRec.qname); 
 }