]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Change the static lock() method of MemRecursorCache to be an instance
authorOtto <otto.moerbeek@open-xchange.com>
Fri, 25 Jun 2021 09:16:04 +0000 (11:16 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 17 Aug 2021 12:10:34 +0000 (14:10 +0200)
method of MapCombo. Likewise for negcache.

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

index 1841de9ba70960f9566e4d4f57d77f9917425a0a..55ddd48fc125ff8e2421d59d4b89cabbf610a42b 100644 (file)
@@ -144,7 +144,7 @@ template <typename S, typename C, typename T> uint64_t pruneMutexCollectionsVect
   }
 
   for (auto& content : maps) {
-    auto mc = C::lock(content.d_content);
+    auto mc = content.d_content.lock();
     mc->invalidate();
     auto& sidx = boost::multi_index::get<S>(mc->d_map);
     uint64_t erased = 0, lookedAt = 0;
@@ -175,10 +175,10 @@ template <typename S, typename C, typename T> uint64_t pruneMutexCollectionsVect
 
   toTrim -= totErased;
 
-    while (true) {
+  while (true) {
     size_t pershard = toTrim / maps_size + 1;
     for (auto& content : maps) {
-      auto mc = C::lock(content.d_content);
+      auto mc = content.d_content.lock();
       mc->invalidate();
       auto& sidx = boost::multi_index::get<S>(mc->d_map);
       size_t removed = 0;
index 2b526eefcee26f86ee69ee6585c77bd4371004ea..9e2aa858154c989935117cd4e0571fd8825c7b3a 100644 (file)
@@ -32,7 +32,7 @@ pair<uint64_t,uint64_t> MemRecursorCache::stats()
 {
   uint64_t c = 0, a = 0;
   for (auto& mc : d_maps) {
-    auto content = lock(mc.d_content);
+    auto content = mc.d_content.lock();
     c += content->d_contended_count;
     a += content->d_acquired_count;
   }
@@ -44,7 +44,7 @@ size_t MemRecursorCache::ecsIndexSize()
   // XXX!
   size_t count = 0;
   for (auto& mc : d_maps) {
-    auto content = lock(mc.d_content);
+    auto content = mc.d_content.lock();
     count += content->d_ecsIndex.size();
   }
   return count;
@@ -55,7 +55,7 @@ size_t MemRecursorCache::bytes()
 {
   size_t ret = 0;
   for (auto& mc : d_maps) {
-    auto m = lock(mc.d_content);
+    auto m = mc.d_content.lock();
     for (const auto& i : m->d_map) {
       ret += sizeof(struct CacheEntry);
       ret += i.d_qname.toString().length();
@@ -273,7 +273,7 @@ time_t MemRecursorCache::get(time_t now, const DNSName &qname, const QType qt, b
   }
 
   auto& mc = getMap(qname);
-  auto map = lock(mc.d_content);
+  auto map = mc.d_content.lock();
 
   /* If we don't have any netmask-specific entries at all, let's just skip this
      to be able to use the nice d_cachecache hack. */
@@ -389,7 +389,7 @@ time_t MemRecursorCache::get(time_t now, const DNSName &qname, const QType qt, b
 void MemRecursorCache::replace(time_t now, const DNSName &qname, const QType qt, const vector<DNSRecord>& content, const vector<shared_ptr<RRSIGRecordContent>>& signatures, const std::vector<std::shared_ptr<DNSRecord>>& authorityRecs, bool auth, const DNSName& authZone, boost::optional<Netmask> ednsmask, const OptTag& routingTag, vState state, boost::optional<ComboAddress> from)
 {
   auto& mc = getMap(qname);
-  auto map = lock(mc.d_content);
+  auto map = mc.d_content.lock();
 
   map->d_cachecachevalid = false;
   if (ednsmask) {
@@ -492,7 +492,7 @@ size_t MemRecursorCache::doWipeCache(const DNSName& name, bool sub, const QType
 
   if (!sub) {
     auto& mc = getMap(name);
-    auto map = lock(mc.d_content);
+    auto map = mc.d_content.lock();
     map->d_cachecachevalid = false;
     auto& idx = map->d_map.get<OrderedTag>();
     auto range = idx.equal_range(name);
@@ -520,7 +520,7 @@ size_t MemRecursorCache::doWipeCache(const DNSName& name, bool sub, const QType
   }
   else {
     for (auto& mc : d_maps) {
-      auto map = lock(mc.d_content);
+      auto map = mc.d_content.lock();
       map->d_cachecachevalid = false;
       auto& idx = map->d_map.get<OrderedTag>();
       for (auto i = idx.lower_bound(name); i != idx.end(); ) {
@@ -553,7 +553,7 @@ size_t MemRecursorCache::doWipeCache(const DNSName& name, bool sub, const QType
 bool MemRecursorCache::doAgeCache(time_t now, const DNSName& name, const QType qtype, uint32_t newTTL)
 {
   auto& mc = getMap(name);
-  auto map = lock(mc.d_content);
+  auto map = mc.d_content.lock();
   cache_t::iterator iter = map->d_map.find(tie(name, qtype));
   if (iter == map->d_map.end()) {
     return false;
@@ -589,7 +589,7 @@ bool MemRecursorCache::updateValidationStatus(time_t now, const DNSName &qname,
   }
 
   auto& mc = getMap(qname);
-  auto map = lock(mc.d_content);
+  auto map = mc.d_content.lock();
 
   bool updated = false;
   if (!map->d_ecsIndex.empty() && !routingTag) {
@@ -642,7 +642,7 @@ uint64_t MemRecursorCache::doDump(int fd)
   uint64_t count = 0;
 
   for (auto& mc : d_maps) {
-    auto map = lock(mc.d_content);
+    auto map = mc.d_content.lock();
     const auto& sidx = map->d_map.get<SequencedTag>();
 
     time_t now = time(nullptr);
index ebb2f7006001832431df6ae99461e05d02f6deb3..9afebd22faad50a04988cdc73bca26f49e6f0765 100644 (file)
@@ -226,6 +226,17 @@ private:
 
     LockGuarded<LockedContent> d_content;
     std::atomic<uint64_t> d_entriesCount{0};
+
+    LockGuardedTryHolder<LockedContent> lock()
+    {
+      auto locked = d_content.try_lock();
+      if (!locked.owns_lock()) {
+        locked.lock();
+        ++locked->d_contended_count;
+      }
+      ++locked->d_acquired_count;
+      return locked;
+    }
   };
 
   vector<MapCombo> d_maps;
@@ -243,17 +254,6 @@ private:
   time_t handleHit(MapCombo::LockedContent& content, OrderedTagIterator_t& entry, const DNSName& qname, uint32_t& origTTL, vector<DNSRecord>* res, vector<std::shared_ptr<RRSIGRecordContent>>* signatures, std::vector<std::shared_ptr<DNSRecord>>* authorityRecs, bool* variable, boost::optional<vState>& state, bool* wasAuth, DNSName* authZone);
 
 public:
-  static LockGuardedTryHolder<MapCombo::LockedContent> lock(LockGuarded<MapCombo::LockedContent>& content)
-  {
-    auto locked = content.try_lock();
-    if (!locked.owns_lock()) {
-      locked.lock();
-      ++locked->d_contended_count;
-    }
-    ++locked->d_acquired_count;
-    return locked;
-  }
-
   void preRemoval(MapCombo::LockedContent& map, const CacheEntry& entry)
   {
     if (entry.d_netmask.empty()) {
index be51971196c4fd2e2f206c710bdb730deb87ecd9..1fe7c296e87b3bdde97e5eba5c3e0ff37ce69c33 100644 (file)
@@ -60,7 +60,7 @@ bool NegCache::getRootNXTrust(const DNSName& qname, const struct timeval& now, N
   DNSName lastLabel = qname.getLastLabel();
 
   auto& map = getMap(lastLabel);
-  auto content = lock(map.d_content);
+  auto content = map.d_content.lock();
 
   negcache_t::const_iterator ni = content->d_map.find(tie(lastLabel, qtnull));
 
@@ -89,7 +89,7 @@ bool NegCache::getRootNXTrust(const DNSName& qname, const struct timeval& now, N
 bool NegCache::get(const DNSName& qname, const QType& qtype, const struct timeval& now, NegCacheEntry& ne, bool typeMustMatch)
 {
   auto& map = getMap(qname);
-  auto content = lock(map.d_content);
+  auto content = map.d_content.lock();
 
   const auto& idx = content->d_map.get<NegCacheEntry>();
   auto range = idx.equal_range(qname);
@@ -124,7 +124,7 @@ void NegCache::add(const NegCacheEntry& ne)
 {
   bool inserted = false;
   auto& map = getMap(ne.d_name);
-  auto content = lock(map.d_content);
+  auto content = map.d_content.lock();
   inserted = lruReplacingInsert<SequenceTag>(content->d_map, ne);
   if (inserted) {
     ++map.d_entriesCount;
@@ -141,7 +141,7 @@ void NegCache::add(const NegCacheEntry& ne)
 void NegCache::updateValidationStatus(const DNSName& qname, const QType& qtype, const vState newState, boost::optional<time_t> capTTD)
 {
   auto& mc = getMap(qname);
-  auto map = lock(mc.d_content);
+  auto map = mc.d_content.lock();
   auto range = map->d_map.equal_range(tie(qname, qtype));
 
   if (range.first != range.second) {
@@ -160,7 +160,7 @@ void NegCache::updateValidationStatus(const DNSName& qname, const QType& qtype,
 size_t NegCache::count(const DNSName& qname)
 {
   auto& map = getMap(qname);
-  auto content = lock(map.d_content);
+  auto content = map.d_content.lock();
   return content->d_map.count(tie(qname));
 }
 
@@ -173,7 +173,7 @@ size_t NegCache::count(const DNSName& qname)
 size_t NegCache::count(const DNSName& qname, const QType qtype)
 {
   auto& map = getMap(qname);
-  auto content = lock(map.d_content);
+  auto content = map.d_content.lock();
   return content->d_map.count(tie(qname, qtype));
 }
 
@@ -189,7 +189,7 @@ size_t NegCache::wipe(const DNSName& name, bool subtree)
   size_t ret = 0;
   if (subtree) {
     for (auto& map : d_maps) {
-      auto m = lock(map.d_content);
+      auto m = map.d_content.lock();
       for (auto i = m->d_map.lower_bound(tie(name)); i != m->d_map.end();) {
         if (!i->d_name.isPartOf(name))
           break;
@@ -202,7 +202,7 @@ size_t NegCache::wipe(const DNSName& name, bool subtree)
   }
 
   auto& map = getMap(name);
-  auto content = lock(map.d_content);
+  auto content = map.d_content.lock();
   auto range = content->d_map.equal_range(tie(name));
   auto i = range.first;
   while (i != range.second) {
@@ -219,7 +219,7 @@ size_t NegCache::wipe(const DNSName& name, bool subtree)
 void NegCache::clear()
 {
   for (auto& map : d_maps) {
-    auto m = lock(map.d_content);
+    auto m = map.d_content.lock();
     m->d_map.clear();
     map.d_entriesCount = 0;
   }
@@ -246,7 +246,7 @@ size_t NegCache::dumpToFile(FILE* fp, const struct timeval& now)
   size_t ret = 0;
 
   for (auto& mc : d_maps) {
-    auto m = lock(mc.d_content);
+    auto m = mc.d_content.lock();
     auto& sidx = m->d_map.get<SequenceTag>();
     for (const NegCacheEntry& ne : sidx) {
       ret++;
index 5d2260762d25fa7ad22ef98395932251e9529166..97dbe3e8c8bdb454e591adb44940c3796704d02f 100644 (file)
@@ -115,6 +115,17 @@ private:
     };
     LockGuarded<LockedContent> d_content;
     std::atomic<uint64_t> d_entriesCount{0};
+
+    LockGuardedTryHolder<MapCombo::LockedContent> lock()
+    {
+      auto locked = d_content.try_lock();
+      if (!locked.owns_lock()) {
+        locked.lock();
+        ++locked->d_contended_count;
+      }
+      ++locked->d_acquired_count;
+      return locked;
+    }
   };
 
   vector<MapCombo> d_maps;
@@ -129,16 +140,6 @@ private:
   }
 
 public:
-  static LockGuardedTryHolder<MapCombo::LockedContent> lock(LockGuarded<MapCombo::LockedContent>& content)
-  {
-    auto locked = content.try_lock();
-    if (!locked.owns_lock()) {
-      locked.lock();
-      ++locked->d_contended_count;
-    }
-    ++locked->d_acquired_count;
-    return locked;
-  }
 
   void preRemoval(MapCombo::LockedContent& map, const NegCacheEntry& entry)
   {