]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Move preRemoval() to MapCombo::LockedContent
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 23 Oct 2023 09:10:47 +0000 (11:10 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 23 Oct 2023 09:12:08 +0000 (11:12 +0200)
Simplifies a few things, and gets rid of the clang-tidy "method can be static"
comment.

pdns/cachecleaner.hh
pdns/recursordist/negcache.cc
pdns/recursordist/negcache.hh
pdns/recursordist/recpacketcache.cc
pdns/recursordist/recpacketcache.hh
pdns/recursordist/recursor_cache.cc
pdns/recursordist/recursor_cache.hh

index fa45ca5736c42034ba1537155d0407d623aa3eed..aaf798152aa335392d273265b0ce80f89663493f 100644 (file)
@@ -130,8 +130,8 @@ uint64_t pruneLockedCollectionsVector(std::vector<T>& maps)
   return totErased;
 }
 
-template <typename S, typename C, typename T>
-uint64_t pruneMutexCollectionsVector(time_t now, C& container, std::vector<T>& maps, uint64_t maxCached, uint64_t cacheSize)
+template <typename S, typename T>
+uint64_t pruneMutexCollectionsVector(time_t now, std::vector<T>& maps, uint64_t maxCached, uint64_t cacheSize)
 {
   uint64_t totErased = 0;
   uint64_t toTrim = 0;
@@ -163,7 +163,7 @@ uint64_t pruneMutexCollectionsVector(time_t now, C& container, std::vector<T>& m
     uint64_t lookedAt = 0;
     for (auto i = sidx.begin(); i != sidx.end(); lookedAt++) {
       if (i->isStale(now)) {
-        container.preRemoval(*shard, *i);
+        shard->preRemoval(*i);
         i = sidx.erase(i);
         erased++;
         content.decEntriesCount();
@@ -223,7 +223,7 @@ uint64_t pruneMutexCollectionsVector(time_t now, C& container, std::vector<T>& m
     auto& sidx = boost::multi_index::get<S>(shard->d_map);
     size_t removed = 0;
     for (auto i = sidx.begin(); i != sidx.end() && removed < toTrimForThisShard; removed++) {
-      container.preRemoval(*shard, *i);
+      shard->preRemoval(*i);
       i = sidx.erase(i);
       content.decEntriesCount();
       ++totErased;
index af6cd1fa6aa9b858993e448dc5648be250a390a1..1dec55c687a00b832e8585416a3bfd59637b7722 100644 (file)
@@ -287,7 +287,7 @@ void NegCache::clear()
 void NegCache::prune(time_t now, size_t maxEntries)
 {
   size_t cacheSize = size();
-  pruneMutexCollectionsVector<SequenceTag>(now, *this, d_maps, maxEntries, cacheSize);
+  pruneMutexCollectionsVector<SequenceTag>(now, d_maps, maxEntries, cacheSize);
 }
 
 /*!
index 86c3b562f428e3e1b636cb1c33f5bcfd3bc9c554..80c91a481675b3258caacf55e9804f74204ba488 100644 (file)
@@ -140,6 +140,7 @@ private:
       uint64_t d_contended_count{0};
       uint64_t d_acquired_count{0};
       void invalidate() {}
+      void preRemoval(const NegCacheEntry& /* entry */) {}
     };
 
     LockGuardedTryHolder<MapCombo::LockedContent> lock()
@@ -188,7 +189,4 @@ private:
   {
     return d_maps.at(qname.hash() % d_maps.size());
   }
-
-public:
-  void preRemoval(MapCombo::LockedContent& /* map */, const NegCacheEntry& /* entry */) {}
 };
index f19176a141517c93160a7af672cc24c5572fe768..0b54090e058a9e7b28ec86ca7bce677d562d2789 100644 (file)
@@ -254,7 +254,7 @@ void RecursorPacketCache::insertResponsePacket(unsigned int tag, uint32_t qhash,
 void RecursorPacketCache::doPruneTo(time_t now, size_t maxSize)
 {
   size_t cacheSize = size();
-  pruneMutexCollectionsVector<SequencedTag>(now, *this, d_maps, maxSize, cacheSize);
+  pruneMutexCollectionsVector<SequencedTag>(now, d_maps, maxSize, cacheSize);
 }
 
 uint64_t RecursorPacketCache::doDump(int file)
index 0e51cea628f0de42ceaeffa5c68b5ea61fafc427..17b618563eba72a334bd4c1d94c33f036d589732 100644 (file)
@@ -183,6 +183,7 @@ private:
       uint64_t d_contended_count{0};
       uint64_t d_acquired_count{0};
       void invalidate() {}
+      void preRemoval(const Entry& /* entry */) {}
     };
 
     LockGuardedTryHolder<MapCombo::LockedContent> lock()
@@ -241,9 +242,4 @@ private:
   static bool checkResponseMatches(MapCombo::LockedContent& shard, std::pair<packetCache_t::index<HashTag>::type::iterator, packetCache_t::index<HashTag>::type::iterator> range, const std::string& queryPacket, const DNSName& qname, uint16_t qtype, uint16_t qclass, time_t now, std::string* responsePacket, uint32_t* age, vState* valState, OptPBData* pbdata);
 
   void setShardSizes(size_t shardSize);
-
-public:
-  void preRemoval(MapCombo::LockedContent& /* map */, const Entry& /* entry */)
-  {
-  }
 };
index 13b6c3ec4f42ee1aa9302998f2a39144ad6c90bb..36f327e97686f6fe59e878e7c434607dd84f420c 100644 (file)
@@ -818,7 +818,7 @@ uint64_t MemRecursorCache::doDump(int fileDesc, size_t maxCacheEntries)
 void MemRecursorCache::doPrune(time_t now, size_t keep)
 {
   size_t cacheSize = size();
-  pruneMutexCollectionsVector<SequencedTag>(now, *this, d_maps, keep, cacheSize);
+  pruneMutexCollectionsVector<SequencedTag>(now, d_maps, keep, cacheSize);
 }
 
 namespace boost
index 982c715a7f422cc4643be036e751619e23b1e954..f0d821e7aa4bf1acda7d0517f85039742dc0eb8c 100644 (file)
@@ -267,6 +267,22 @@ private:
       {
         d_cachecachevalid = false;
       }
+
+      void preRemoval(const CacheEntry& entry)
+      {
+        if (entry.d_netmask.empty()) {
+          return;
+        }
+
+        auto key = std::tie(entry.d_qname, entry.d_qtype);
+        auto ecsIndexEntry = d_ecsIndex.find(key);
+        if (ecsIndexEntry != d_ecsIndex.end()) {
+          ecsIndexEntry->removeNetmask(entry.d_netmask);
+          if (ecsIndexEntry->isEmpty()) {
+            d_ecsIndex.erase(ecsIndexEntry);
+          }
+        }
+      }
     };
 
     LockGuardedTryHolder<LockedContent> lock()
@@ -320,23 +336,6 @@ private:
   static time_t handleHit(MapCombo::LockedContent& content, OrderedTagIterator_t& entry, const DNSName& qname, uint32_t& origTTL, vector<DNSRecord>* res, vector<std::shared_ptr<const RRSIGRecordContent>>* signatures, std::vector<std::shared_ptr<DNSRecord>>* authorityRecs, bool* variable, boost::optional<vState>& state, bool* wasAuth, DNSName* authZone, ComboAddress* fromAuthIP);
   static void updateStaleEntry(time_t now, OrderedTagIterator_t& entry);
   static void handleServeStaleBookkeeping(time_t, bool, OrderedTagIterator_t&);
-
-public:
-  void preRemoval(MapCombo::LockedContent& map, const CacheEntry& entry)
-  {
-    if (entry.d_netmask.empty()) {
-      return;
-    }
-
-    auto key = std::tie(entry.d_qname, entry.d_qtype);
-    auto ecsIndexEntry = map.d_ecsIndex.find(key);
-    if (ecsIndexEntry != map.d_ecsIndex.end()) {
-      ecsIndexEntry->removeNetmask(entry.d_netmask);
-      if (ecsIndexEntry->isEmpty()) {
-        map.d_ecsIndex.erase(ecsIndexEntry);
-      }
-    }
-  }
 };
 
 namespace boost