From: Otto Moerbeek Date: Mon, 23 Oct 2023 09:10:47 +0000 (+0200) Subject: Move preRemoval() to MapCombo::LockedContent X-Git-Tag: rec-5.0.0-beta1~25^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a6465c8816408132615127ca35b5c8f5b6c02ae6;p=thirdparty%2Fpdns.git Move preRemoval() to MapCombo::LockedContent Simplifies a few things, and gets rid of the clang-tidy "method can be static" comment. --- diff --git a/pdns/cachecleaner.hh b/pdns/cachecleaner.hh index fa45ca5736..aaf798152a 100644 --- a/pdns/cachecleaner.hh +++ b/pdns/cachecleaner.hh @@ -130,8 +130,8 @@ uint64_t pruneLockedCollectionsVector(std::vector& maps) return totErased; } -template -uint64_t pruneMutexCollectionsVector(time_t now, C& container, std::vector& maps, uint64_t maxCached, uint64_t cacheSize) +template +uint64_t pruneMutexCollectionsVector(time_t now, std::vector& 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& 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& m auto& sidx = boost::multi_index::get(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; diff --git a/pdns/recursordist/negcache.cc b/pdns/recursordist/negcache.cc index af6cd1fa6a..1dec55c687 100644 --- a/pdns/recursordist/negcache.cc +++ b/pdns/recursordist/negcache.cc @@ -287,7 +287,7 @@ void NegCache::clear() void NegCache::prune(time_t now, size_t maxEntries) { size_t cacheSize = size(); - pruneMutexCollectionsVector(now, *this, d_maps, maxEntries, cacheSize); + pruneMutexCollectionsVector(now, d_maps, maxEntries, cacheSize); } /*! diff --git a/pdns/recursordist/negcache.hh b/pdns/recursordist/negcache.hh index 86c3b562f4..80c91a4816 100644 --- a/pdns/recursordist/negcache.hh +++ b/pdns/recursordist/negcache.hh @@ -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 lock() @@ -188,7 +189,4 @@ private: { return d_maps.at(qname.hash() % d_maps.size()); } - -public: - void preRemoval(MapCombo::LockedContent& /* map */, const NegCacheEntry& /* entry */) {} }; diff --git a/pdns/recursordist/recpacketcache.cc b/pdns/recursordist/recpacketcache.cc index f19176a141..0b54090e05 100644 --- a/pdns/recursordist/recpacketcache.cc +++ b/pdns/recursordist/recpacketcache.cc @@ -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(now, *this, d_maps, maxSize, cacheSize); + pruneMutexCollectionsVector(now, d_maps, maxSize, cacheSize); } uint64_t RecursorPacketCache::doDump(int file) diff --git a/pdns/recursordist/recpacketcache.hh b/pdns/recursordist/recpacketcache.hh index 0e51cea628..17b618563e 100644 --- a/pdns/recursordist/recpacketcache.hh +++ b/pdns/recursordist/recpacketcache.hh @@ -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 lock() @@ -241,9 +242,4 @@ private: static bool checkResponseMatches(MapCombo::LockedContent& shard, std::pair::type::iterator, packetCache_t::index::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 */) - { - } }; diff --git a/pdns/recursordist/recursor_cache.cc b/pdns/recursordist/recursor_cache.cc index 13b6c3ec4f..36f327e976 100644 --- a/pdns/recursordist/recursor_cache.cc +++ b/pdns/recursordist/recursor_cache.cc @@ -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(now, *this, d_maps, keep, cacheSize); + pruneMutexCollectionsVector(now, d_maps, keep, cacheSize); } namespace boost diff --git a/pdns/recursordist/recursor_cache.hh b/pdns/recursordist/recursor_cache.hh index 982c715a7f..f0d821e7aa 100644 --- a/pdns/recursordist/recursor_cache.hh +++ b/pdns/recursordist/recursor_cache.hh @@ -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 lock() @@ -320,23 +336,6 @@ private: static time_t handleHit(MapCombo::LockedContent& content, OrderedTagIterator_t& entry, const DNSName& qname, uint32_t& origTTL, vector* res, vector>* signatures, std::vector>* authorityRecs, bool* variable, boost::optional& 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