]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1188] addressed review
authorRazvan Becheriu <razvan@isc.org>
Thu, 30 Apr 2020 10:42:19 +0000 (13:42 +0300)
committerRazvan Becheriu <razvan@isc.org>
Thu, 30 Apr 2020 10:53:48 +0000 (13:53 +0300)
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/lib/dhcpsrv/parsers/multi_threading_config_parser.h

index 05cbcd99222fac6d9086cf7ff55e9bdd8050daf1..ba3bb02c1f3718db94e0e20e4bc61ff939cfad99 100644 (file)
@@ -229,8 +229,9 @@ ControlledDhcpv4Srv::commandShutdownHandler(const string&, ConstElementPtr args)
 
 ConstElementPtr
 ControlledDhcpv4Srv::commandLibReloadHandler(const string&, ConstElementPtr) {
-    // pause dhcp service when reloading libraries
+    // stop thread pool (if running)
     MultiThreadingCriticalSection cs;
+
     /// @todo delete any stored CalloutHandles referring to the old libraries
     /// Get list of currently loaded libraries and reload them.
     HookLibsCollection loaded = HooksManager::getLibraryInfo();
@@ -354,7 +355,12 @@ ControlledDhcpv4Srv::commandConfigSetHandler(const string&,
         return (result);
     }
 
+    // stop thread pool (if running)
+    MultiThreadingCriticalSection cs;
+
     // disable multi-threading (it will be applied by new configuration)
+    // this must be done in order to properly handle MT to ST transition
+    // when 'multi-threading' structure is missing from new config
     MultiThreadingMgr::instance().apply(false, 0, 0);
 
     // We are starting the configuration process so we should remove any
@@ -415,18 +421,6 @@ ControlledDhcpv4Srv::commandConfigSetHandler(const string&,
         CfgMgr::instance().getCurrentCfg()->applyLoggingCfg();
     }
 
-    // Configure multi threading
-    try {
-        CfgMultiThreading::apply(CfgMgr::instance().getStagingCfg()->getDHCPMultiThreading());
-        if (MultiThreadingMgr::instance().getMode()) {
-            LOG_FATAL(dhcp4_logger, DHCP4_MULTI_THREADING_WARNING);
-        }
-    } catch (const std::exception& ex) {
-        err << "Error applying multi threading settings: "
-            << ex.what();
-        return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
-    }
-
     return (result);
 }
 
@@ -596,6 +590,7 @@ ControlledDhcpv4Srv::commandConfigBackendPullHandler(const std::string&,
         return (createAnswer(CONTROL_RESULT_EMPTY, "No config backend."));
     }
 
+    // stop thread pool (if running)
     MultiThreadingCriticalSection cs;
 
     // Reschedule the periodic CB fetch.
@@ -897,6 +892,18 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
         // operation.
     }
 
+    // Configure multi threading
+    try {
+        CfgMultiThreading::apply(CfgMgr::instance().getStagingCfg()->getDHCPMultiThreading());
+        if (MultiThreadingMgr::instance().getMode()) {
+            LOG_FATAL(dhcp4_logger, DHCP4_MULTI_THREADING_WARNING);
+        }
+    } catch (const std::exception& ex) {
+        err << "Error applying multi threading settings: "
+            << ex.what();
+        return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
+    }
+
     return (answer);
 }
 
@@ -1178,6 +1185,7 @@ ControlledDhcpv4Srv::dbLostCallback(ReconnectCtlPtr db_reconnect_ctl) {
 void
 ControlledDhcpv4Srv::cbFetchUpdates(const SrvConfigPtr& srv_cfg,
                                     boost::shared_ptr<unsigned> failure_count) {
+    // stop thread pool (if running)
     MultiThreadingCriticalSection cs;
 
     try {
index 7e49af0c8cdf28d7061239df6253029f820a960e..835e8cf36ce0649f31b9de31c5617f527d595035 100644 (file)
@@ -232,8 +232,9 @@ ControlledDhcpv6Srv::commandShutdownHandler(const string&, ConstElementPtr args)
 
 ConstElementPtr
 ControlledDhcpv6Srv::commandLibReloadHandler(const string&, ConstElementPtr) {
-    // pause dhcp service when reloading libraries
+    // stop thread pool (if running)
     MultiThreadingCriticalSection cs;
+
     /// @todo delete any stored CalloutHandles referring to the old libraries
     /// Get list of currently loaded libraries and reload them.
     HookLibsCollection loaded = HooksManager::getLibraryInfo();
@@ -357,7 +358,12 @@ ControlledDhcpv6Srv::commandConfigSetHandler(const string&,
         return (result);
     }
 
+    // stop thread pool (if running)
+    MultiThreadingCriticalSection cs;
+
     // disable multi-threading (it will be applied by new configuration)
+    // this must be done in order to properly handle MT to ST transition
+    // when 'multi-threading' structure is missing from new config
     MultiThreadingMgr::instance().apply(false, 0, 0);
 
     // We are starting the configuration process so we should remove any
@@ -418,18 +424,6 @@ ControlledDhcpv6Srv::commandConfigSetHandler(const string&,
         CfgMgr::instance().getCurrentCfg()->applyLoggingCfg();
     }
 
-    // Configure multi threading
-    try {
-        CfgMultiThreading::apply(CfgMgr::instance().getStagingCfg()->getDHCPMultiThreading());
-        if (MultiThreadingMgr::instance().getMode()) {
-            LOG_FATAL(dhcp6_logger, DHCP6_MULTI_THREADING_WARNING);
-        }
-    } catch (const std::exception& ex) {
-        err << "Error applying multi threading settings: "
-            << ex.what();
-        return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
-    }
-
     return (result);
 }
 
@@ -599,6 +593,7 @@ ControlledDhcpv6Srv::commandConfigBackendPullHandler(const std::string&,
         return (createAnswer(CONTROL_RESULT_EMPTY, "No config backend."));
     }
 
+    // stop thread pool (if running)
     MultiThreadingCriticalSection cs;
 
     // Reschedule the periodic CB fetch.
@@ -918,6 +913,18 @@ ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
         // operation.
     }
 
+    // Configure multi threading
+    try {
+        CfgMultiThreading::apply(CfgMgr::instance().getStagingCfg()->getDHCPMultiThreading());
+        if (MultiThreadingMgr::instance().getMode()) {
+            LOG_FATAL(dhcp6_logger, DHCP6_MULTI_THREADING_WARNING);
+        }
+    } catch (const std::exception& ex) {
+        err << "Error applying multi threading settings: "
+            << ex.what();
+        return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
+    }
+
     return (answer);
 }
 
@@ -1196,6 +1203,7 @@ ControlledDhcpv6Srv::dbLostCallback(ReconnectCtlPtr db_reconnect_ctl) {
 void
 ControlledDhcpv6Srv::cbFetchUpdates(const SrvConfigPtr& srv_cfg,
                                     boost::shared_ptr<unsigned> failure_count) {
+    // stop thread pool (if running)
     MultiThreadingCriticalSection cs;
 
     try {
index bd285acbbedaca174f56d75e9d2b48c14bb8c501..d099a05002471fc21b1d97d49192c70d34a1a9ee 100644 (file)
@@ -20,7 +20,7 @@ public:
     /// @brief parses JSON structure.
     ///
     /// This function stores the 'multi-threading' settings in the server
-    /// configuration and applies the MT mode so that is can be checked when
+    /// configuration and updates the MT mode so that is can be checked when
     /// parsing 'hooks-libraries'.
     ///
     /// @param srv_cfg parsed value will be stored here.