From: Fred Morcos Date: Thu, 11 Aug 2022 13:27:38 +0000 (+0200) Subject: Rec: Don't reload Lua config if it hasn't changed X-Git-Tag: rec-4.8.0-alpha1~59^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=afaf1b5d87c4a4961eadaf114855a335711c33c8;p=thirdparty%2Fpdns.git Rec: Don't reload Lua config if it hasn't changed 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 --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index b9e05657f8..f646b30e02 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -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; diff --git a/pdns/rec-lua-conf.cc b/pdns/rec-lua-conf.cc index ab6c158ca3..b6b133dd7d 100644 --- a/pdns/rec-lua-conf.cc +++ b/pdns/rec-lua-conf.cc @@ -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::value_type::second_type constGet(const C& c, const std::string& name) { diff --git a/pdns/rec-lua-conf.hh b/pdns/rec-lua-conf.hh index d0b19057b9..17b8b689ad 100644 --- a/pdns/rec-lua-conf.hh +++ b/pdns/rec-lua-conf.hh @@ -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>> servers; + uint64_t generation; + FrameStreamExportConfig config; +}; + struct TrustAnchorFileInfo { uint32_t interval{24}; diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index c5c77e10a8..d91cb080c6 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -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>> 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>> startFra bool checkFrameStreamExport(LocalStateHolder& 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; diff --git a/pdns/recursordist/rec-main.hh b/pdns/recursordist/rec-main.hh index 56e8ea72af..167c974fad 100644 --- a/pdns/recursordist/rec-main.hh +++ b/pdns/recursordist/rec-main.hh @@ -249,8 +249,7 @@ extern thread_local std::shared_ptr t_udrDBp; #endif #ifdef HAVE_FSTRM -extern thread_local std::shared_ptr>> 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