]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Make snapshot write interval settable
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 20 Mar 2024 13:52:38 +0000 (14:52 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 22 Mar 2024 08:13:58 +0000 (09:13 +0100)
pdns/recursordist/nod.cc
pdns/recursordist/nod.hh
pdns/recursordist/rec-main.cc
pdns/recursordist/settings/table.py
pdns/recursordist/stable-bloom.hh

index 6a1f4277ddc4f9351aa2d0a32b52cf62d8ea7b94..4aae73d97aeb30901c65ec9c408449daeb819752 100644 (file)
@@ -43,7 +43,7 @@ std::mutex PersistentSBF::d_cachedir_mutex;
 void PersistentSBF::remove_tmp_files(const filesystem::path& path, std::lock_guard<std::mutex>& /* lock */)
 {
   Regex file_regex(d_prefix + ".*\\." + bf_suffix + "\\..{8}$");
-  for (const auto& file : filesystem::directory_iterator (path)) {
+  for (const auto& file : filesystem::directory_iterator(path)) {
     if (filesystem::is_regular_file(file.path()) && file_regex.match(file.path().filename().string())) {
       filesystem::remove(file);
     }
@@ -67,11 +67,11 @@ bool PersistentSBF::init(bool ignore_pid)
         filesystem::path newest_file;
         std::time_t newest_time = 0;
         Regex file_regex(d_prefix + ".*\\." + bf_suffix + "$");
-        for (const auto& file : filesystem::directory_iterator (path)) {
+        for (const auto& file : filesystem::directory_iterator(path)) {
           if (filesystem::is_regular_file(file.path()) && file_regex.match(file.path().filename().string())) {
             if (ignore_pid || (file.path().filename().string().find(std::to_string(getpid())) == std::string::npos)) {
               // look for the newest file matching the regex
-              if (last_write_time(file.path()) > newest_time) { 
+              if (last_write_time(file.path()) > newest_time) {
                 newest_time = last_write_time(file.path());
                 newest_file = file.path();
               }
@@ -204,8 +204,6 @@ bool NODDB::isNewDomain(const std::string& domain)
 bool NODDB::isNewDomain(const DNSName& dname)
 {
   std::string dname_lc = dname.toDNSStringLC();
-  // The only time this should block is when snapshotting from the
-  // housekeeping thread
   // the result is always the inverse of what is returned by the SBF
   return !d_psbf.testAndAdd(dname_lc);
 }
index 4e6d1e7d7d167974607cfc082477144c84590add..2a5bb3edf49dcf2ffd59bf6dec0cc86f60cf164e 100644 (file)
@@ -33,7 +33,7 @@ namespace nod
 const float c_fp_rate = 0.01;
 const size_t c_num_cells = 67108864;
 const uint8_t c_num_dec = 10;
-  const unsigned int snapshot_interval_default = 30; // XXX 600;
+const unsigned int snapshot_interval_default = 600;
 const std::string bf_suffix = "bf";
 const std::string sbf_prefix = "sbf";
 
index 075fbec059f0eaf46b976e9069ccecb49ae1b3ab..3f451d30088a013f41bf4350fc76f235898978a0 100644 (file)
@@ -796,10 +796,13 @@ static void setupNODThread(Logr::log_t log)
            log->info(Logr::Error, "Could not initialize domain tracking"));
       _exit(1);
     }
-    std::thread thread([tid = std::this_thread::get_id()]() {
-      g_nodDBp->housekeepingThread(tid);
-    });
-    thread.detach();
+    if (::arg().asNum("new-domain-db-snapshot-interval") > 0) {
+      g_nodDBp->setSnapshotInterval(::arg().asNum("new-domain-db-snapshot-interval"));
+      std::thread thread([tid = std::this_thread::get_id()]() {
+        g_nodDBp->housekeepingThread(tid);
+      });
+      thread.detach();
+    }
   }
   if (g_udrEnabled) {
     uint32_t num_cells = ::arg().asNum("unique-response-db-size");
@@ -817,10 +820,13 @@ static void setupNODThread(Logr::log_t log)
            log->info(Logr::Error, "Could not initialize unique response tracking"));
       _exit(1);
     }
-    std::thread thread([tid = std::this_thread::get_id()]() {
-      g_udrDBp->housekeepingThread(tid);
-    });
-    thread.detach();
+    if (::arg().asNum("new-domain-db-snapshot-interval") > 0) {
+      g_udrDBp->setSnapshotInterval(::arg().asNum("new-domain-db-snapshot-interval"));
+      std::thread thread([tid = std::this_thread::get_id()]() {
+        g_udrDBp->housekeepingThread(tid);
+      });
+      thread.detach();
+    }
   }
 }
 
index 5028b4c5f482f9754a851c51b5bda3a6f0d580a3..7e374aeb66338ca9699964e0126a0ee6af26315f 100644 (file)
@@ -1737,6 +1737,19 @@ from this directory.
  ''',
     'versionadded': '4.2.0'
     },
+    {
+        'name' : 'db_snapshot_interval',
+        'section' : 'nod',
+        'oldname' : 'new-domain-db-snapshot-interval',
+        'type' : LType.Uint64,
+        'default' : '600',
+        'help' : 'Interval (in seconds) to write the NOD and UDR DB snapshots',
+        'doc' : '''
+Interval (in seconds) to write the NOD and UDR DB snapshots.
+Set to zero to disable snapshot writing.',
+ ''',
+        'versionadded': '5.1.0'
+    },
     {
         'name' : 'whitelist',
         'section' : 'nod',
index 1c1b7b1e1b55e75713715bd2791aecf1a0e92ec0..a025eb8e8d2516e5a8b5dbb7760dc5cdb7966f88 100644 (file)
@@ -29,7 +29,6 @@
 #include <boost/dynamic_bitset.hpp>
 #include "misc.hh"
 #include "noinitvector.hh"
-#include "views.hh"
 #include "ext/probds/murmur3.h"
 
 namespace bf