]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3710] fixed db reconnect
authorRazvan Becheriu <razvan@isc.org>
Thu, 13 Mar 2025 11:53:32 +0000 (13:53 +0200)
committerRazvan Becheriu <razvan@isc.org>
Mon, 17 Mar 2025 13:11:33 +0000 (13:11 +0000)
src/hooks/dhcp/forensic_log/rotating_file.cc
src/hooks/dhcp/forensic_log/rotating_file.h
src/hooks/dhcp/mysql/mysql_legal_log.cc
src/hooks/dhcp/mysql/mysql_legal_log.h
src/hooks/dhcp/pgsql/pgsql_legal_log.cc
src/hooks/dhcp/pgsql/pgsql_legal_log.h
src/lib/dhcpsrv/legal_log_mgr.h
src/lib/dhcpsrv/legal_log_mgr_factory.cc
src/lib/dhcpsrv/tests/legal_log_mgr_factory_unittest.cc

index d50a7dbdc4420bc956bc5a2b2ae9bf860ce39eac..4f48d1613885f6b949752b181278ef7becff007b 100644 (file)
@@ -271,7 +271,7 @@ RotatingFile::useExistingFiles(struct tm& time_info) {
 }
 
 void
-RotatingFile::open() {
+RotatingFile::open(ManagerID) {
     if (isOpen() || MultiThreadingMgr::instance().isTestMode()) {
         return;
     }
index 7dc942c943e9ee92bda0dbe9062519e4411826f3..00d121dd88dd592b15fb1c26ada6fc715dc8b5e5 100644 (file)
@@ -135,8 +135,10 @@ public:
     /// it is created.  If the file is already open, the method simply
     /// returns.
     ///
+    /// @param id the forensic backend manager ID.
+    ///
     /// @throw LegalLogMgrError if the file cannot be opened.
-    virtual void open();
+    virtual void open(isc::dhcp::ManagerID id = 0);
 
     /// @brief Closes the underlying file.
     ///
index ff6f3a3df1c4ee3d979c5be1e4c3bfb8b4ad9d8d..2ec9ce5b75618912b2fb4374b84b8acde63916a5 100644 (file)
@@ -280,15 +280,15 @@ MySqlStore::MySqlStore(const DatabaseConnection::ParameterMap& parameters)
     timer_name_ += "]DbReconnectTimer";
 }
 
-void MySqlStore::open() {
+void MySqlStore::open(ManagerID id) {
     LegalLogDbLogger pushed(mysql_legal_log_db_logger);
 
     // Test schema version first.
     std::pair<uint32_t, uint32_t> code_version(MYSQL_SCHEMA_VERSION_MAJOR,
                                                MYSQL_SCHEMA_VERSION_MINOR);
 
-    LegalLogMgrPtr store = LegalLogMgrFactory::instance();
-    LegalLogMgrFactory::instance().reset();
+    LegalLogMgrPtr store = LegalLogMgrFactory::instance(id);
+    LegalLogMgrFactory::instance(id).reset();
 
     string timer_name;
     bool retry = false;
@@ -310,7 +310,7 @@ void MySqlStore::open() {
                   << db_version.second);
     }
 
-    LegalLogMgrFactory::instance() = store;
+    LegalLogMgrFactory::instance(id) = store;
 
     // Create an initial context.
     pool_.reset(new MySqlStoreContextPool());
index d5be34e27a60e788f6ef14784fb73c86ce9c3094..f038b24d7f1b4a329d7f99bf223cd66d79934c05 100644 (file)
@@ -136,10 +136,12 @@ public:
     ///
     /// Finally, all the SQL commands are pre-compiled.
     ///
+    /// @param id the forensic backend manager ID.
+    ///
     /// @throw isc::db::DbOpenError Error opening the database
     /// @throw isc::db::DbOperationError An operation on the open
     ///        database has failed.
-    virtual void open();
+    virtual void open(ManagerID id = 0);
 
     /// @brief Closes the store.
     virtual void close();
index 4fac2bce7b16ae79fd881effc26b6d2e9e9111e0..f952ad7a9e55dc6ae09f51b4ba005558a54b988f 100644 (file)
@@ -177,7 +177,7 @@ PgSqlStore::PgSqlStore(const DatabaseConnection::ParameterMap& parameters)
     timer_name_ += "]DbReconnectTimer";
 }
 
-void PgSqlStore::open() {
+void PgSqlStore::open(ManagerID id) {
     LegalLogDbLogger pushed(pgsql_legal_log_db_logger);
 
     // Check TLS support.
@@ -207,8 +207,8 @@ void PgSqlStore::open() {
     pair<uint32_t, uint32_t> code_version(PGSQL_SCHEMA_VERSION_MAJOR,
                                           PGSQL_SCHEMA_VERSION_MINOR);
 
-    LegalLogMgrPtr store = LegalLogMgrFactory::instance();
-    LegalLogMgrFactory::instance().reset();
+    LegalLogMgrPtr store = LegalLogMgrFactory::instance(id);
+    LegalLogMgrFactory::instance(id).reset();
 
     string timer_name;
     bool retry = false;
@@ -230,7 +230,7 @@ void PgSqlStore::open() {
                   << db_version.second);
     }
 
-    LegalLogMgrFactory::instance() = store;
+    LegalLogMgrFactory::instance(id) = store;
 
     // Create an initial context.
     pool_.reset(new PgSqlStoreContextPool());
index 8742663d7ebf40ba711445f9607cd5a1704eee0d..88051766636749526e66624ec6bae8242ca041d0 100644 (file)
@@ -131,10 +131,12 @@ public:
     ///
     /// Finally, all the SQL commands are pre-compiled.
     ///
+    /// @param id the forensic backend manager ID.
+    ///
     /// @throw isc::db::DbOpenError Error opening the database
     /// @throw isc::db::DbOperationError An operation on the open
     ///        database has failed.
-    virtual void open();
+    virtual void open(ManagerID id = 0);
 
     /// @brief Closes the store.
     virtual void close();
index 6abeb3fe645cb0dd849606a93de432649c87b3fd..c1a5a46bb62c14a9a0ebf84f0dfca021dee363e7 100644 (file)
@@ -35,6 +35,9 @@ class LegalLogMgr;
 /// @brief Defines a smart pointer to a LegalLogMgr.
 typedef boost::shared_ptr<LegalLogMgr> LegalLogMgrPtr;
 
+/// @brief Manger ID used by hook libraries to retrieve respective LegalLogMgr instance.
+typedef uint64_t ManagerID;
+
 /// @brief LegalLogMgr abstract class
 class LegalLogMgr {
 public:
@@ -84,7 +87,9 @@ public:
     static void parseExtraParameters(const isc::data::ConstElementPtr& parameters, isc::db::DatabaseConnection::ParameterMap& map);
 
     /// @brief Opens the store.
-    virtual void open() = 0;
+    ///
+    /// @param id the forensic backend manager ID.
+    virtual void open(ManagerID id = 0) = 0;
 
     /// @brief Closes the store.
     virtual void close() = 0;
@@ -267,9 +272,6 @@ private:
     isc::db::DatabaseConnection::ParameterMap parameters_;
 };
 
-/// @brief Manger ID used by hook libraries to retrieve respective LegalLogMgr instance.
-typedef uint64_t ManagerID;
-
 /// @brief LegalLogMgr pool
 typedef std::map<ManagerID, std::pair<isc::db::DatabaseConnection::ParameterMap, LegalLogMgrPtr>> LegalLogMgrPool;
 
index f4f5811795e0ad34e9545f7fae951e93c48beb31..2590aa7ba1e14e5863077dda8b51840734304060 100644 (file)
@@ -101,7 +101,10 @@ LegalLogMgrFactory::addBackend(DatabaseConnection::ParameterMap& parameters, Man
                   " factory returned NULL");
     }
 
-    backend->open();
+    // Add the parameters and an empty instance in case retry on startup is configured.
+    pool_[id] = pair<DatabaseConnection::ParameterMap, LegalLogMgrPtr>(parameters, LegalLogMgrPtr());
+
+    backend->open(id);
 
     // Apply extra parameters.
     if (parameters.find("request-parser-format") != parameters.end()) {
index dfa7bab397c906b425eb9f2ea9092db49dc09de9..970c67204787a38446b1ca3c85f40df8146db684 100644 (file)
@@ -38,7 +38,7 @@ public:
     }
 
     /// @brief Opens the store.
-    virtual void open() {
+    virtual void open(ManagerID) {
     }
 
     /// @brief Closes the store.