]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Fix three shared cache issues: 9226/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 12 Jun 2020 10:24:26 +0000 (12:24 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 15 Jun 2020 10:13:56 +0000 (12:13 +0200)
- Only prime share cache once on startup

- Cache pruning could go into an infinite loop if not enough expired
entries could be pruned.

- Handler thread isn't run very often, but now the record cache
pruning is done by it, so increase frequency of the housekeeping
call for the handler thread.

pdns/cachecleaner.hh
pdns/pdns_recursor.cc

index 18e5ea147494a65d3ec505ff993aab50e1276d58..7d42274bffb2e2f27fcdb601dabdfddd80f0f02e 100644 (file)
@@ -190,7 +190,7 @@ template <typename S, typename C, typename T> uint64_t pruneMutexCollectionsVect
 
   toTrim -= totErased;
 
-  while (toTrim > 0) {
+    while (true) {
     size_t pershard = toTrim / maps_size + 1;
     for (auto& mc : maps) {
       const typename C::lock l(mc);
@@ -204,11 +204,12 @@ template <typename S, typename C, typename T> uint64_t pruneMutexCollectionsVect
         totErased++;
         toTrim--;
         if (toTrim == 0) {
-          break;
+          return totErased;
         }
       }
     }
   }
+  // Not reached
   return totErased;
 }
 
index 8e51e26350c8bc2a981053ec1144d805f1806564..f99dd5af58d0d5fa164ffa52292a70dee088e2f5 100644 (file)
@@ -4662,11 +4662,13 @@ try
   t_allowFrom = g_initialAllowFrom;
   t_udpclientsocks = std::unique_ptr<UDPClientSocks>(new UDPClientSocks());
   t_tcpClientCounts = std::unique_ptr<tcpClientCounts_t>(new tcpClientCounts_t());
-  primeHints();
+  if (threadInfo.isHandler) {
+    primeHints();
+    g_log<<Logger::Warning<<"Done priming cache with root hints"<<endl;
+  }
 
   t_packetCache = std::unique_ptr<RecursorPacketCache>(new RecursorPacketCache());
 
-  g_log<<Logger::Warning<<"Done priming cache with root hints"<<endl;
 
 #ifdef NOD_ENABLED
   if (threadInfo.isWorker)
@@ -4784,7 +4786,9 @@ try
   while (!RecursorControlChannel::stop) {
     while(MT->schedule(&g_now)); // MTasker letting the mthreads do their thing
 
-    if(!(counter%500)) {
+    // Use primes, it avoid not being scheduled in cases where the counter has a regular pattern.
+    // We want to call handler thread often, it gets scheduled about 2 times per second
+    if ((threadInfo.isHandler && counter % 11 == 0) || counter % 499 == 0) {
       MT->makeThread(houseKeeping, 0);
     }