]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4508] Init allocators in lease mgr recreate()
authorThomas Markwalder <tmark@isc.org>
Fri, 29 May 2026 18:18:56 +0000 (14:18 -0400)
committerRazvan Becheriu <razvan@isc.org>
Fri, 29 May 2026 18:23:43 +0000 (18:23 +0000)
/src/bin/dhcp4/ctrl_dhcp4_srv.cc
    ControlledDhcpv4Srv::processConfig() - set allocator init flag

/src/bin/dhcp6/ctrl_dhcp6_srv.cc
    ControlledDhcpv6Srv::processConfig() - set allocator init flag

/src/lib/dhcpsrv/lease_mgr_factory.*
    LeaseMgrFactory::init_allocators_  - new static flag

    LeaseMgrFactory::initAllocators() - new function that initializes
    lease allocators when static flag is true

    LeaseMgrFactory::recreate() - call initAllocators()

changelog_unreleased/4508-shared-flq-allocator-fix-retry-on-startup [new file with mode: 0644]
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/lib/dhcpsrv/lease_mgr_factory.cc
src/lib/dhcpsrv/lease_mgr_factory.h

diff --git a/changelog_unreleased/4508-shared-flq-allocator-fix-retry-on-startup b/changelog_unreleased/4508-shared-flq-allocator-fix-retry-on-startup
new file mode 100644 (file)
index 0000000..cbea437
--- /dev/null
@@ -0,0 +1,8 @@
+[bug]          tmark
+       Treat allocator initializition failures caused
+       by database connectivity issues as a recoverable
+       condition. Prior to this the server would exit
+       with a fatal error even when configure to retry.
+       Applies to both kea-dhcp4 and kea-dhcp6 when
+       using either the FLQ or SLFQ allocators.
+       (Gitlab #4508)
index ae65a91aa8cebb47824dbbdbaf1b5b7d5237fc84..070e42b17d3be80711cf03f2967acb7d775aad23 100644 (file)
@@ -1406,6 +1406,9 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
         return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
     }
 
+    // Enable allocator initialization prior to creating lease manager.
+    LeaseMgrFactory::init_allocators_ = true;
+
     // Re-open lease and host database with new parameters.
     try {
         DatabaseConnection::db_lost_callback_ =
@@ -1530,18 +1533,6 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
         return (notify_libraries);
     }
 
-    // Initialize the allocators. If the user selected a Free Lease Queue Allocator
-    // for any of the subnets, the server will now populate free leases to the queue.
-    // It may take a while!
-    try {
-        CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->initAllocatorsAfterConfigure();
-
-    } catch (const std::exception& ex) {
-        err << "Error initializing the lease allocators: "
-            << ex.what();
-        return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
-    }
-
     // Apply multi threading settings.
     // @note These settings are applied/updated only if no errors occur while
     // applying the new configuration.
index 25c9b30c5c2855977846ccb323bb892857710057..ab38cf3d1d88b69e1d9e0de8892a17edecc64770 100644 (file)
@@ -1173,6 +1173,9 @@ ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
         return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
     }
 
+    // Enable allocator initialization prior to creating lease manager.
+    LeaseMgrFactory::init_allocators_ = true;
+
     // Re-open lease and host database with new parameters.
     try {
         DatabaseConnection::db_lost_callback_ =
@@ -1317,18 +1320,6 @@ ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
         return (notify_libraries);
     }
 
-    // Initialize the allocators. If the user selected a Free Lease Queue Allocator
-    // for any of the subnets, the server will now populate free leases to the queue.
-    // It may take a while!
-    try {
-        CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->initAllocatorsAfterConfigure();
-
-    } catch (const std::exception& ex) {
-        err << "Error initializing the lease allocators: "
-            << ex.what();
-        return (isc::config::createAnswer(CONTROL_RESULT_ERROR, err.str()));
-    }
-
     // Apply multi threading settings.
     // @note These settings are applied/updated only if no errors occur while
     // applying the new configuration.
index 2e33622291b07798fef52a12e4da00a44b3c29f8..eea39380fc908f53d09cedbfd64c93d20a734276 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <config.h>
 
+#include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/dhcpsrv_log.h>
 #include <dhcpsrv/lease_mgr_factory.h>
 #include <dhcpsrv/memfile_lease_mgr.h>
@@ -39,6 +40,23 @@ LeaseMgrFactory::getLeaseMgrPtr() {
     return (lease_mgr_ptr);
 }
 
+bool LeaseMgrFactory::init_allocators_ = false;
+
+void
+LeaseMgrFactory::initAllocators(bool use_staging /* = false */) {
+    if (!LeaseMgrFactory::init_allocators_) {
+        return;
+    }
+    auto cfg = (use_staging ? CfgMgr::instance().getStagingCfg()
+                            : CfgMgr::instance().getCurrentCfg());
+    if (CfgMgr::instance().getFamily() == AF_INET) {
+        cfg->getCfgSubnets4()->initAllocatorsAfterConfigure();
+    } else {
+        cfg->getCfgSubnets6()->initAllocatorsAfterConfigure();
+    }
+    LeaseMgrFactory::init_allocators_ = false;
+}
+
 void
 LeaseMgrFactory::create(const std::string& dbaccess) {
     const std::string type = "type";
@@ -108,6 +126,12 @@ LeaseMgrFactory::recreate(const std::string& dbaccess, bool preserve_callbacks)
     destroy();
     create(dbaccess);
 
+    // Init lease allocators. We do this here for allocators which require
+    // the lease manager access (i.e. SFLQ and FLQ) for initialization.
+    // When preserve_callbacks is true are using the a current configuration.
+    // If it is false we are using staging. Pass the inverse to initAllocators().
+    LeaseMgrFactory::initAllocators(!preserve_callbacks);
+
     if (callbacks) {
         // Copy the callbacks to the new instance. It should be fast
         // because we merely copy the pointer.
index 3433124c5c7a11191daa6f6c985b31f6cb988f68..67520d3b566fb3403c1ffa95907b04cb2f67723b 100644 (file)
@@ -157,6 +157,14 @@ public:
     /// @brief Return extended version info for registered backends.
     static std::list<std::string> getDBVersions();
 
+    /// @brief Initializes the lease allocators for all subnets.
+    /// @param use_staging  Use the staging configuration when true, otherwise
+    /// use the current configuration. Defaults to false.
+    static void initAllocators(bool use_staging = false);
+
+    /// @brief Flag which indicates if allocators must be initialized.
+    static bool init_allocators_;
+
 private:
     /// @brief Hold pointer to lease manager
     ///