]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Format cachecleaner
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Sun, 6 Feb 2022 15:25:12 +0000 (16:25 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 1 Apr 2022 08:08:54 +0000 (10:08 +0200)
.not-formatted
pdns/cachecleaner.hh
pdns/recpacketcache.cc
pdns/recpacketcache.hh
pdns/recursordist/rec-main.cc

index bd022488572d82e32ce99324e7830a9785ac2739..11b45e55148a278e00e23c5955e1e769ba7a718f 100644 (file)
@@ -24,7 +24,6 @@
 ./pdns/bindparserclasses.hh
 ./pdns/bpf-filter.cc
 ./pdns/bpf-filter.hh
-./pdns/cachecleaner.hh
 ./pdns/calidns.cc
 ./pdns/capabilities.cc
 ./pdns/cdb.cc
index 018e2a4457d8c9bef6fa3bc4c132d73a51772106..578b4690948159924d332f73dc760aab469093cf 100644 (file)
@@ -29,7 +29,8 @@
 // this function can clean any cache that has a getTTD() method on its entries, a preRemoval() method and a 'sequence' index as its second index
 // the ritual is that the oldest entries are in *front* of the sequence collection, so on a hit, move an item to the end
 // and optionally, on a miss, move it to the beginning
-template <typename S, typename C, typename T> void pruneCollection(C& container, T& collection, size_t maxCached, size_t scanFraction = 1000)
+template <typename S, typename C, typename T>
+void pruneCollection(C& container, T& collection, size_t maxCached, size_t scanFraction = 1000)
 {
   const time_t now = time(nullptr);
   size_t toTrim = 0;
@@ -41,13 +42,13 @@ template <typename S, typename C, typename T> void pruneCollection(C& container,
 
   auto& sidx = collection.template get<S>();
 
-  // two modes - if toTrim is 0, just look through 1/scanFraction of all records 
+  // two modes - if toTrim is 0, just look through 1/scanFraction of all records
   // and nuke everything that is expired
   // otherwise, scan first 5*toTrim records, and stop once we've nuked enough
   const size_t lookAt = toTrim ? 5 * toTrim : cacheSize / scanFraction;
   size_t tried = 0, erased = 0;
 
-  for (auto iter = sidx.begin(); iter != sidx.end() && tried < lookAt ; ++tried) {
+  for (auto iter = sidx.begin(); iter != sidx.end() && tried < lookAt; ++tried) {
     if (iter->getTTD() < now) {
       iter = sidx.erase(iter);
       erased++;
@@ -75,44 +76,49 @@ template <typename S, typename C, typename T> void pruneCollection(C& container,
 }
 
 // note: this expects iterator from first index
-template <typename S, typename T> void moveCacheItemToFrontOrBack(T& collection, typename T::iterator& iter, bool front)
+template <typename S, typename T>
+void moveCacheItemToFrontOrBack(T& collection, typename T::iterator& iter, bool front)
 {
   typedef typename T::template index<S>::type sequence_t;
-  sequence_t& sidx=collection.template get<S>();
-  typename sequence_t::iterator si=collection.template project<S>(iter);
-  if(front)
+  sequence_t& sidx = collection.template get<S>();
+  typename sequence_t::iterator si = collection.template project<S>(iter);
+  if (front)
     sidx.relocate(sidx.begin(), si); // at the beginning of the delete queue
   else
-    sidx.relocate(sidx.end(), si);  // back
+    sidx.relocate(sidx.end(), si); // back
 }
 
-template <typename S, typename T> void moveCacheItemToFront(T& collection, typename T::iterator& iter)
+template <typename S, typename T>
+void moveCacheItemToFront(T& collection, typename T::iterator& iter)
 {
   moveCacheItemToFrontOrBack<S>(collection, iter, true);
 }
 
-template <typename S, typename T> void moveCacheItemToBack(T& collection, typename T::iterator& iter)
+template <typename S, typename T>
+void moveCacheItemToBack(T& collection, typename T::iterator& iter)
 {
   moveCacheItemToFrontOrBack<S>(collection, iter, false);
 }
 
-template <typename S, typename T> uint64_t pruneLockedCollectionsVector(std::vector<T>& maps)
+template <typename S, typename T>
+uint64_t pruneLockedCollectionsVector(std::vector<T>& maps)
 {
   uint64_t totErased = 0;
   time_t now = time(nullptr);
 
-  for(auto& mc : maps) {
+  for (auto& mc : maps) {
     auto map = mc.d_map.write_lock();
 
     uint64_t lookAt = (map->size() + 9) / 10; // Look at 10% of this shard
     uint64_t erased = 0;
 
     auto& sidx = boost::multi_index::get<S>(*map);
-    for(auto i = sidx.begin(); i != sidx.end() && lookAt > 0; lookAt--) {
-      if(i->ttd < now) {
+    for (auto i = sidx.begin(); i != sidx.end() && lookAt > 0; lookAt--) {
+      if (i->ttd < now) {
         i = sidx.erase(i);
         erased++;
-      } else {
+      }
+      else {
         ++i;
       }
     }
@@ -122,7 +128,8 @@ template <typename S, typename T> uint64_t pruneLockedCollectionsVector(std::vec
   return totErased;
 }
 
-template <typename S, typename C, typename T> uint64_t pruneMutexCollectionsVector(C& container, std::vector<T>& maps, uint64_t maxCached, uint64_t cacheSize)
+template <typename S, typename C, typename T>
+uint64_t pruneMutexCollectionsVector(C& container, std::vector<T>& maps, uint64_t maxCached, uint64_t cacheSize)
 {
   time_t now = time(nullptr);
   uint64_t totErased = 0;
@@ -134,7 +141,8 @@ template <typename S, typename C, typename T> uint64_t pruneMutexCollectionsVect
   if (cacheSize > maxCached) {
     toTrim = cacheSize - maxCached;
     lookAt = 5 * toTrim;
-  } else {
+  }
+  else {
     lookAt = cacheSize / 10;
   }
 
@@ -154,7 +162,8 @@ template <typename S, typename C, typename T> uint64_t pruneMutexCollectionsVect
         i = sidx.erase(i);
         erased++;
         --content.d_entriesCount;
-      } else {
+      }
+      else {
         ++i;
       }
 
@@ -198,11 +207,12 @@ template <typename S, typename C, typename T> uint64_t pruneMutexCollectionsVect
   return totErased;
 }
 
-template <typename T> uint64_t purgeLockedCollectionsVector(std::vector<T>& maps)
+template <typename T>
+uint64_t purgeLockedCollectionsVector(std::vector<T>& maps)
 {
-  uint64_t delcount=0;
+  uint64_t delcount = 0;
 
-  for(auto& mc : maps) {
+  for (auto& mc : maps) {
     auto map = mc.d_map.write_lock();
     delcount += map->size();
     map->clear();
@@ -211,20 +221,21 @@ template <typename T> uint64_t purgeLockedCollectionsVector(std::vector<T>& maps
   return delcount;
 }
 
-template <typename N, typename T> uint64_t purgeLockedCollectionsVector(std::vector<T>& maps, const std::string& match)
+template <typename N, typename T>
+uint64_t purgeLockedCollectionsVector(std::vector<T>& maps, const std::string& match)
 {
-  uint64_t delcount=0;
+  uint64_t delcount = 0;
   std::string prefix(match);
-  prefix.resize(prefix.size()-1);
+  prefix.resize(prefix.size() - 1);
   DNSName dprefix(prefix);
-  for(auto& mc : maps) {
+  for (auto& mc : maps) {
     auto map = mc.d_map.write_lock();
     auto& idx = boost::multi_index::get<N>(*map);
     auto iter = idx.lower_bound(dprefix);
     auto start = iter;
 
-    for(; iter != idx.end(); ++iter) {
-      if(!iter->qname.isPartOf(dprefix)) {
+    for (; iter != idx.end(); ++iter) {
+      if (!iter->qname.isPartOf(dprefix)) {
         break;
       }
       delcount++;
@@ -235,13 +246,14 @@ template <typename N, typename T> uint64_t purgeLockedCollectionsVector(std::vec
   return delcount;
 }
 
-template <typename N, typename T> uint64_t purgeExactLockedCollection(T& mc, const DNSName& qname)
+template <typename N, typename T>
+uint64_t purgeExactLockedCollection(T& mc, const DNSName& qname)
 {
-  uint64_t delcount=0;
+  uint64_t delcount = 0;
   auto map = mc.d_map.write_lock();
   auto& idx = boost::multi_index::get<N>(*map);
   auto range = idx.equal_range(qname);
-  if(range.first != range.second) {
+  if (range.first != range.second) {
     delcount += distance(range.first, range.second);
     idx.erase(range.first, range.second);
   }
@@ -249,7 +261,7 @@ template <typename N, typename T> uint64_t purgeExactLockedCollection(T& mc, con
   return delcount;
 }
 
-template<typename S, typename Index>
+template <typename S, typename Index>
 bool lruReplacingInsert(Index& i, const typename Index::value_type& x)
 {
   auto inserted = i.insert(x);
index 6d9bae7494e50952044f0d0cac43de804483f057..697e56de71ed4ddd6315792434a87b915469fe82 100644 (file)
@@ -92,8 +92,8 @@ bool RecursorPacketCache::checkResponseMatches(std::pair<packetCache_t::index<Ha
       return true;
     }
     else {
-      // We used to move the item to the fron ot the to be deleted sequence,
-      // but we're very likely will update the entry very soon, so leave it
+      // We used to move the item to the front of "the to be deleted" sequence,
+      // but we very likely will update the entry very soon, so leave it
       d_misses++;
       break;
     }
index 28554b34722eab20abc796e0151ec8d9c66a8ad6..2ffdabfbecdf98cbd8b78ab20b87faf546959ff4 100644 (file)
@@ -59,8 +59,8 @@ public:
   };
   typedef boost::optional<PBData> OptPBData;
 
-  RecursorPacketCache(size_t maxsize)
-    d_maxSize(maxsize)
+  RecursorPacketCache(size_t maxsize) :
+    d_maxSize(maxsize)
   {
   }
 
index 2af4fb2f1a1629f578400e3412c4e1f1ebbee3c1..8f6afb7338b57fa82a6c69e900dbb5c8558ef583 100644 (file)
@@ -2707,7 +2707,7 @@ string doTraceRegex(vector<string>::const_iterator begin, vector<string>::const_
 
 static uint64_t* pleaseWipePacketCache(const DNSName& canon, bool subtree, uint16_t qtype)
 {
-  return new uint64_t(t_packetCache ? 0 : t_packetCache->doWipePacketCache(canon, qtype, subtree));
+  return new uint64_t(t_packetCache ? t_packetCache->doWipePacketCache(canon, qtype, subtree) : 0);
 }
 
 struct WipeCacheResult wipeCaches(const DNSName& canon, bool subtree, uint16_t qtype)