From: Francis Dupont Date: Tue, 27 Mar 2018 17:22:45 +0000 (+0200) Subject: [master] Tomek's changes + init + deinit fixes X-Git-Tag: trac5458a_base~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e05c4fa661a005e59e46fb51801a48a86865afc;p=thirdparty%2Fkea.git [master] Tomek's changes + init + deinit fixes --- diff --git a/src/bin/dhcp4/json_config_parser.cc b/src/bin/dhcp4/json_config_parser.cc index 6e46f87b1f..43c0758ddf 100644 --- a/src/bin/dhcp4/json_config_parser.cc +++ b/src/bin/dhcp4/json_config_parser.cc @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -297,6 +298,9 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set, // for option definitions. This is equivalent to committing empty container. LibDHCP::setRuntimeOptionDefs(OptionDefSpaceContainer()); + // Print the list of known backends. + HostDataSourceFactory::printRegistered(); + // Answer will hold the result. ConstElementPtr answer; // Rollback informs whether error occurred and original data diff --git a/src/bin/dhcp6/json_config_parser.cc b/src/bin/dhcp6/json_config_parser.cc index 2bc5e49022..531a6588a2 100644 --- a/src/bin/dhcp6/json_config_parser.cc +++ b/src/bin/dhcp6/json_config_parser.cc @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -395,6 +396,9 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set, // for option definitions. This is equivalent to committing empty container. LibDHCP::setRuntimeOptionDefs(OptionDefSpaceContainer()); + // Print the list of known backends. + HostDataSourceFactory::printRegistered(); + // This is a way to convert ConstElementPtr to ElementPtr. // We need a config that can be edited, because we will insert // default values and will insert derived values as well. diff --git a/src/lib/dhcpsrv/host_data_source_factory.cc b/src/lib/dhcpsrv/host_data_source_factory.cc index 9e023c7678..ec5cac31fd 100644 --- a/src/lib/dhcpsrv/host_data_source_factory.cc +++ b/src/lib/dhcpsrv/host_data_source_factory.cc @@ -9,6 +9,7 @@ #include #include #include +#include #ifdef HAVE_MYSQL #include @@ -81,7 +82,7 @@ HostDataSourceFactory::del(HostDataSourceList& sources, if ((*it)->getType() != db_type) { continue; } - LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, HOSTS_CFG_CLOSE_HOST_DATA_SOURCE) + LOG_DEBUG(hosts_logger, DHCPSRV_DBG_TRACE, HOSTS_CFG_CLOSE_HOST_DATA_SOURCE) .arg(db_type); sources.erase(it); return (true); @@ -91,33 +92,51 @@ HostDataSourceFactory::del(HostDataSourceList& sources, bool HostDataSourceFactory::registerFactory(const string& db_type, - const Factory& factory) { + const Factory& factory, + bool no_log) { if (map_.count(db_type)) { return (false); } map_.insert(pair(db_type, factory)); - // As registerFactory can be called before logging is established - // remove temporary this until a better solution is found. -#if 0 - LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, HOSTS_BACKEND_REGISTER) - .arg(db_type); -#endif + + // We are dealing here with static logger initialization fiasco. + // registerFactory may be called from constructors of static global + // objects for built in backends. The logging is not initialized yet, + // so the LOG_DEBUG would throw. + if (!no_log) { + LOG_DEBUG(hosts_logger, DHCPSRV_DBG_TRACE, HOSTS_BACKEND_REGISTER) + .arg(db_type); + } return (true); } bool -HostDataSourceFactory::deregisterFactory(const string& db_type) { +HostDataSourceFactory::deregisterFactory(const string& db_type, bool no_log) { auto index = map_.find(db_type); if (index != map_.end()) { map_.erase(index); - LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE, HOSTS_BACKEND_DEREGISTER) - .arg(db_type); + if (!no_log) { + LOG_DEBUG(hosts_logger, DHCPSRV_DBG_TRACE, + HOSTS_BACKEND_DEREGISTER) + .arg(db_type); + } return (true); } else { return (false); } } +void +HostDataSourceFactory::printRegistered() { + std::stringstream txt; + + for (auto x : map_) { + txt << x.first << " "; + } + + LOG_INFO(hosts_logger, HOSTS_BACKENDS_REGISTERED).arg(txt.str()); +} + } // namespace dhcp } // namespace isc @@ -133,18 +152,18 @@ namespace { struct MySqlHostDataSourceInit { // Constructor registers MySqlHostDataSourceInit() { - HostDataSourceFactory::registerFactory("mysql", factory); + HostDataSourceFactory::registerFactory("mysql", factory, true); } // Destructor deregisters ~MySqlHostDataSourceInit() { - HostDataSourceFactory::deregisterFactory("mysql"); + HostDataSourceFactory::deregisterFactory("mysql", true); } // Factory class method static HostDataSourcePtr factory(const DatabaseConnection::ParameterMap& parameters) { - LOG_INFO(dhcpsrv_logger, DHCPSRV_MYSQL_HOST_DB) + LOG_INFO(hosts_logger, DHCPSRV_MYSQL_HOST_DB) .arg(DatabaseConnection::redactedAccessString(parameters)); return (HostDataSourcePtr(new MySqlHostDataSource(parameters))); } @@ -158,18 +177,18 @@ MySqlHostDataSourceInit mysql_init_; struct PgSqlHostDataSourceInit { // Constructor registers PgSqlHostDataSourceInit() { - HostDataSourceFactory::registerFactory("postgresql", factory); + HostDataSourceFactory::registerFactory("postgresql", factory, true); } // Destructor deregisters ~PgSqlHostDataSourceInit() { - HostDataSourceFactory::deregisterFactory("postgresql"); + HostDataSourceFactory::deregisterFactory("postgresql", true); } // Factory class method static HostDataSourcePtr factory(const DatabaseConnection::ParameterMap& parameters) { - LOG_INFO(dhcpsrv_logger, DHCPSRV_PGSQL_HOST_DB) + LOG_INFO(hosts_logger, DHCPSRV_PGSQL_HOST_DB) .arg(DatabaseConnection::redactedAccessString(parameters)); return (HostDataSourcePtr(new PgSqlHostDataSource(parameters))); } @@ -183,12 +202,12 @@ PgSqlHostDataSourceInit pgsql_init_; struct CqlHostDataSourceInit { // Constructor registers CqlHostDataSourceInit() { - HostDataSourceFactory::registerFactory("cql", factory); + HostDataSourceFactory::registerFactory("cql", factory, true); } // Destructor deregisters ~CqlHostDataSourceInit() { - HostDataSourceFactory::deregisterFactory("cql"); + HostDataSourceFactory::deregisterFactory("cql", true); } // Factory class method @@ -205,4 +224,3 @@ CqlHostDataSourceInit cql_init_; #endif } // end of anonymous namespace - diff --git a/src/lib/dhcpsrv/host_data_source_factory.h b/src/lib/dhcpsrv/host_data_source_factory.h index 11c40dde02..b28f291d0b 100644 --- a/src/lib/dhcpsrv/host_data_source_factory.h +++ b/src/lib/dhcpsrv/host_data_source_factory.h @@ -14,6 +14,7 @@ #include #include +#include #include namespace isc { @@ -83,22 +84,35 @@ public: /// @brief Register a host data source factory /// /// Associate the factory to a database type in the map. + /// The no_log is to avoid logging before the logger is initialized + /// as when called at global object initialization. /// /// @param db_type database type /// @param factory host data source factory + /// @param no_log do not log (default false) /// @return true if the factory was successfully added to the map, false /// if it already exists. static bool registerFactory(const std::string& db_type, - const Factory& factory); + const Factory& factory, bool no_log = false); /// @brief Deregister a host data source factory /// /// Disassociate the factory to a database type in the map. + /// The no_log is to avoid logging during global object deinitialization. /// /// @param db_type database type + /// @param no_log do not log (default false) /// @return true if the factory was successfully removed from the map, /// false if it was not found. - static bool deregisterFactory(const std::string& db_type); + static bool deregisterFactory(const std::string& db_type, + bool no_log = false); + + /// @brief Prints out all registered backends. + /// + /// We need a dedicated method for this, because we sometimes can't log + /// the backend type when doing early initialization for backends + /// initialized statically. + static void printRegistered(); private: /// @brief Factory map diff --git a/src/lib/dhcpsrv/hosts_messages.mes b/src/lib/dhcpsrv/hosts_messages.mes index 54975efee1..cf370ed31a 100644 --- a/src/lib/dhcpsrv/hosts_messages.mes +++ b/src/lib/dhcpsrv/hosts_messages.mes @@ -6,14 +6,18 @@ $NAMESPACE isc::dhcp -% HOSTS_BACKEND_DEREGISTER deregistered backend type: %1 +% HOSTS_BACKEND_DEREGISTER deregistered host backend type: %1 This debug message is issued when a backend factory was deregistered. It is no longer possible to use host backend of this type. -% HOSTS_BACKEND_REGISTER registered backend type: %1 +% HOSTS_BACKEND_REGISTER registered host backend type: %1 This debug message is issued when a backend factory was successfully registered. It is now possible to use host backend of this type. +% HOSTS_BACKENDS_REGISTERED the following host backend types are available: %1 +This informational message lists all possible host backends that could +be used in hosts-database[s]. + % HOSTS_CFG_ADD_HOST add the host for reservations: %1 This debug message is issued when new host (with reservations) is added to the server's configuration. The argument describes the host and its