]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Rec: Don't reload Lua config if it hasn't changed
authorFred Morcos <fred.morcos@open-xchange.com>
Thu, 11 Aug 2022 13:27:38 +0000 (15:27 +0200)
committerFred Morcos <fred.morcos@open-xchange.com>
Fri, 12 Aug 2022 10:59:54 +0000 (12:59 +0200)
This also groups together 1) the list of frame stream servers, 2) the config from which
the list was created and 3) the config's generation into a single struct called
FrameStreamServersInfo. The struct is used to compare the old and new configuration to
decide whether to destroy the old config object or not.

Part of #11795

pdns/pdns_recursor.cc
pdns/rec-lua-conf.cc
pdns/rec-lua-conf.hh
pdns/recursordist/rec-main.cc
pdns/recursordist/rec-main.hh

index b9e05657f853263d9bd6f534048e9404fb59f1f1..f646b30e02bb4de8180bbc965f0aa6a14c7b7a83 100644 (file)
@@ -940,7 +940,7 @@ void startDoResolve(void* p)
     sr.setInitialRequestId(dc->d_uuid);
     sr.setOutgoingProtobufServers(t_outgoingProtobufServers);
 #ifdef HAVE_FSTRM
-    sr.setFrameStreamServers(t_frameStreamServers);
+    sr.setFrameStreamServers(t_frameStreamServersInfo.servers);
 #endif
 
     bool useMapped = true;
index ab6c158ca388353443372c28dd03bad4883bf06c..b6b133dd7da9424ae3a2ff52b9eb102eda8f7780 100644 (file)
@@ -43,6 +43,27 @@ LuaConfigItems::LuaConfigItems()
 
 /* DID YOU READ THE STORY ABOVE? */
 
+bool operator==(const FrameStreamExportConfig& configA, const FrameStreamExportConfig& configB)
+{
+  // clang-format off
+  return configA.enabled              == configB.enabled              &&
+         configA.logQueries           == configB.logQueries           &&
+         configA.logResponses         == configB.logResponses         &&
+         configA.bufferHint           == configB.bufferHint           &&
+         configA.flushTimeout         == configB.flushTimeout         &&
+         configA.inputQueueSize       == configB.inputQueueSize       &&
+         configA.outputQueueSize      == configB.outputQueueSize      &&
+         configA.queueNotifyThreshold == configB.queueNotifyThreshold &&
+         configA.reopenInterval       == configB.reopenInterval       &&
+         configA.servers              == configB.servers;
+  // clang-format on
+}
+
+bool operator!=(const FrameStreamExportConfig& configA, const FrameStreamExportConfig& configB)
+{
+  return !(configA == configB);
+}
+
 template <typename C>
 typename C::value_type::second_type constGet(const C& c, const std::string& name)
 {
index d0b19057b90c7ecb2a5c4a099958c7694af4ed59..17b8b689adf2d38e48136222115d1714a30a0893 100644 (file)
@@ -28,6 +28,7 @@
 #include "validate.hh"
 #include "rec-zonetocache.hh"
 #include "logging.hh"
+#include "fstrm_logger.hh"
 
 struct ProtobufExportConfig
 {
@@ -58,6 +59,16 @@ struct FrameStreamExportConfig
   unsigned reopenInterval{0};
 };
 
+bool operator==(const FrameStreamExportConfig& configA, const FrameStreamExportConfig& configB);
+bool operator!=(const FrameStreamExportConfig& configA, const FrameStreamExportConfig& configB);
+
+struct FrameStreamServersInfo
+{
+  std::shared_ptr<std::vector<std::unique_ptr<FrameStreamLogger>>> servers;
+  uint64_t generation;
+  FrameStreamExportConfig config;
+};
+
 struct TrustAnchorFileInfo
 {
   uint32_t interval{24};
index c5c77e10a83af1cec11b7dce6e12cca5e6d9f648..d91cb080c6c1049633b01d5f5d38249a8e82762a 100644 (file)
@@ -58,8 +58,7 @@ static thread_local uint64_t t_protobufServersGeneration;
 static thread_local uint64_t t_outgoingProtobufServersGeneration;
 
 #ifdef HAVE_FSTRM
-thread_local std::shared_ptr<std::vector<std::unique_ptr<FrameStreamLogger>>> t_frameStreamServers{nullptr};
-thread_local uint64_t t_frameStreamServersGeneration;
+thread_local FrameStreamServersInfo t_frameStreamServersInfo;
 #endif /* HAVE_FSTRM */
 
 string g_programname = "pdns_recursor";
@@ -629,26 +628,28 @@ static std::shared_ptr<std::vector<std::unique_ptr<FrameStreamLogger>>> startFra
 bool checkFrameStreamExport(LocalStateHolder<LuaConfigItems>& luaconfsLocal)
 {
   if (!luaconfsLocal->frameStreamExportConfig.enabled) {
-    if (t_frameStreamServers) {
+    if (t_frameStreamServersInfo.servers) {
       // dt's take care of cleanup
-      t_frameStreamServers.reset();
+      t_frameStreamServersInfo.servers.reset();
+      t_frameStreamServersInfo.config = luaconfsLocal->frameStreamExportConfig;
     }
 
     return false;
   }
 
-  /* if the server was not running, or if it was running according to a
-     previous configuration */
-  if (!t_frameStreamServers || t_frameStreamServersGeneration < luaconfsLocal->generation) {
-
-    if (t_frameStreamServers) {
+  /* if the server was not running, or if it was running according to a previous
+   * configuration
+   */
+  if (t_frameStreamServersInfo.generation < luaconfsLocal->generation && t_frameStreamServersInfo.config != luaconfsLocal->frameStreamExportConfig) {
+    if (t_frameStreamServersInfo.servers) {
       // dt's take care of cleanup
-      t_frameStreamServers.reset();
+      t_frameStreamServersInfo.servers.reset();
     }
 
-    auto log = g_slog->withName("dnstap");
-    t_frameStreamServers = startFrameStreamServers(luaconfsLocal->frameStreamExportConfig, log);
-    t_frameStreamServersGeneration = luaconfsLocal->generation;
+    auto dnsTapLog = g_slog->withName("dnstap");
+    t_frameStreamServersInfo.servers = startFrameStreamServers(luaconfsLocal->frameStreamExportConfig, dnsTapLog);
+    t_frameStreamServersInfo.config = luaconfsLocal->frameStreamExportConfig;
+    t_frameStreamServersInfo.generation = luaconfsLocal->generation;
   }
 
   return true;
index 56e8ea72afb70e440678146c89abd2bc5c265e83..167c974fad7b61834a27c463dbb0f57c923e3c87 100644 (file)
@@ -249,8 +249,7 @@ extern thread_local std::shared_ptr<nod::UniqueResponseDB> t_udrDBp;
 #endif
 
 #ifdef HAVE_FSTRM
-extern thread_local std::shared_ptr<std::vector<std::unique_ptr<FrameStreamLogger>>> t_frameStreamServers;
-extern thread_local uint64_t t_frameStreamServersGeneration;
+extern thread_local FrameStreamServersInfo t_frameStreamServersInfo;
 #endif /* HAVE_FSTRM */
 
 #ifdef HAVE_BOOST_CONTAINER_FLAT_SET_HPP