]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Implement a way to only dump specific cache(s), undocumented!
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 5 Sep 2023 08:20:50 +0000 (10:20 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 5 Sep 2023 08:37:45 +0000 (10:37 +0200)
pdns/recursordist/rec_channel_rec.cc

index 34305559f546305796bb54d5797048a4810dc6d8..9ff615ae4432f07e8cfbd1c409ed861aa1170278 100644 (file)
@@ -401,19 +401,52 @@ static RecursorControlChannel::Answer doDumpToFile(int s, uint64_t* (*function)(
 }
 
 // Does not follow the generic dump to file pattern, has a more complex lambda
-static RecursorControlChannel::Answer doDumpCache(int socket)
+template <typename T>
+static RecursorControlChannel::Answer doDumpCache(int socket, T begin, T end)
 {
   auto fdw = getfd(socket);
 
   if (fdw < 0) {
     return {1, "Error opening dump file for writing: " + stringerror() + "\n"};
   }
+  bool dumpRecordCache = true;
+  bool dumpNegCache = true;
+  bool dumpPacketCache = true;
+  bool dumpAggrCache = true;
+  if (begin != end) {
+    dumpRecordCache = false;
+    dumpNegCache = false;
+    dumpPacketCache = false;
+    dumpAggrCache = false;
+    for (auto name = begin; name != end; ++name) {
+      if (*name == "r") {
+        dumpRecordCache = true;
+      }
+      else if (*name == "n") {
+        dumpNegCache = true;
+      }
+      else if (*name == "p") {
+        dumpPacketCache = true;
+      }
+      else if (*name == "a") {
+        dumpAggrCache = true;
+      }
+    }
+  }
   uint64_t total = 0;
   try {
-    total += g_recCache->doDump(fdw, g_maxCacheEntries.load());
-    total += g_negCache->doDump(fdw, g_maxCacheEntries.load() / 8);
-    total += g_packetCache ? g_packetCache->doDump(fdw) : 0;
-    total += dumpAggressiveNSECCache(fdw);
+    if (dumpRecordCache) {
+      total += g_recCache->doDump(fdw, g_maxCacheEntries.load());
+    }
+    if (dumpNegCache) {
+      total += g_negCache->doDump(fdw, g_maxCacheEntries.load() / 8);
+    }
+    if (dumpPacketCache) {
+      total += g_packetCache ? g_packetCache->doDump(fdw) : 0;
+    }
+    if (dumpAggrCache) {
+      total += dumpAggressiveNSECCache(fdw);
+    }
   }
   catch (...) {
   }
@@ -2163,7 +2196,7 @@ RecursorControlChannel::Answer RecursorControlParser::getAnswer(int socket, cons
     return {0, "bye nicely\n"};
   }
   if (cmd == "dump-cache") {
-    return doDumpCache(socket);
+    return doDumpCache(socket, begin, end);
   }
   if (cmd == "dump-dot-probe-map") {
     return doDumpToFile(socket, pleaseDumpDoTProbeMap, cmd, false);