From: Ruben d'Arco Date: Sun, 10 Mar 2013 16:19:18 +0000 (+0100) Subject: Code cleanup, move commitTransaction within try-block X-Git-Tag: rec-3.6.0-rc1~556^2~3^2~53 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0bb68041509633aff6c424eaadf26efead2ff297;p=thirdparty%2Fpdns.git Code cleanup, move commitTransaction within try-block --- diff --git a/pdns/packetcache.cc b/pdns/packetcache.cc index 4a81be404b..d62b7294ef 100644 --- a/pdns/packetcache.cc +++ b/pdns/packetcache.cc @@ -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) diff --git a/pdns/packetcache.hh b/pdns/packetcache.hh index 0c8fcd5fe0..b60fccda63 100644 --- a/pdns/packetcache.hh +++ b/pdns/packetcache.hh @@ -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 getCounts(); private: diff --git a/pdns/rfc2136handler.cc b/pdns/rfc2136handler.cc index 826f4f1416..e5a1444aca 100755 --- a/pdns/rfc2136handler.cc +++ b/pdns/rfc2136handler.cc @@ -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 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 > 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 >::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<abortTransaction(); + return RCode::ServFail; } catch (DBException &e) { L<abortTransaction(); return RCode::ServFail; } - catch (SSqlException &e) { - L<abortTransaction(); - return RCode::ServFail; - } catch (...) { L<abortTransaction(); return RCode::ServFail; } - - if (!di.backend->commitTransaction()) { - L<backend->updateDNSSECOrderAndAuth(di->id, di->zone, newRec.qname, true); - - // purge the cache for the SOA record. - PC.purge(newRec.qname); }