}
}
+ /// @brief Flag which indicates if connection is unusable.
+ ///
+ /// @return true if the connection is unusable, false otherwise
+ bool isUnusable() {
+ return (unusable_);
+ }
+
protected:
/// @brief Sets the unusable flag to true.
void markUnusable() { unusable_ = true; }
/// @return true if the new setting was accepted by the backend or false
/// otherwise.
virtual bool setIPReservationsUnique(const bool unique) = 0;
+
+ /// @brief Flag which indicates if the host manager has at least one
+ /// unusable connection.
+ ///
+ /// @return true if there is at least one unusable connection, false
+ /// otherwise
+ virtual bool isUnusable() {
+ return (false);
+ }
};
/// @brief HostDataSource pointer
bool
HostDataSourceFactory::del(HostDataSourceList& sources,
const string& db_type,
- const string& dbaccess) {
+ const string& dbaccess,
+ bool if_unusable) {
DatabaseConnection::ParameterMap parameters =
DatabaseConnection::parse(dbaccess);
bool result = false;
if ((*it)->getType() != db_type || (*it)->getParameters() != parameters) {
continue;
}
+ if (if_unusable && (!(*it)->isUnusable())) {
+ continue;
+ }
LOG_DEBUG(hosts_logger, DHCPSRV_DBG_TRACE, HOSTS_CFG_CLOSE_HOST_DATA_SOURCE)
.arg((*it)->getType());
sources.erase(it);
/// "keyword=value" pairs, separated by spaces. They are backend-
/// -end specific, although must include the "type" keyword which
/// gives the backend in use.
+ /// @param if_unusable flag which indicates if the host data source should
+ /// be deleted only if it is unusable.
/// @return true when found and removed, false when not found.
static bool del(HostDataSourceList& sources, const std::string& db_type,
- const std::string& dbaccess);
+ const std::string& dbaccess, bool if_unusable = true);
/// @brief Type of host data source factory
///
getHostMgrPtr()->cache_ptr_->getType() == db_type) {
getHostMgrPtr()->cache_ptr_.reset();
}
- return (HostDataSourceFactory::del(getHostMgrPtr()->alternate_sources_, db_type));
+ return (HostDataSourceFactory::del(getHostMgrPtr()->alternate_sources_,
+ db_type));
}
bool
-HostMgr::delBackend(const std::string& db_type, const std::string& access) {
- return (HostDataSourceFactory::del(getHostMgrPtr()->alternate_sources_, db_type, access));
+HostMgr::delBackend(const std::string& db_type, const std::string& access,
+ bool if_unusable) {
+ return (HostDataSourceFactory::del(getHostMgrPtr()->alternate_sources_,
+ db_type, access, if_unusable));
}
void
/// @param db_type database backend type.
/// @param access Host backend access parameters for the alternate
/// host backend. It holds "keyword=value" pairs, separated by spaces.
+ /// @param if_unusable flag which indicates if the host data source should
+ /// be deleted only if it is unusable.
/// @return true when found and removed, false when not found.
- static bool delBackend(const std::string& db_type, const std::string& access);
+ static bool delBackend(const std::string& db_type,
+ const std::string& access,
+ bool if_unusable = false);
/// @brief Delete all alternate backends.
static void delAllBackends();
}
protected:
+
/// @brief The negative caching flag.
///
/// When true and the first backend is a cache
/// @brief The pool of contexts
MySqlHostContextPoolPtr pool_;
+
+ /// @brief Indicates if there is at least one connection that can no longer
+ /// be used for normal operations.
+ bool unusable_;
};
namespace {
// MySqlHostContextAlloc Constructor and Destructor
MySqlHostDataSource::MySqlHostContextAlloc::MySqlHostContextAlloc(
- const MySqlHostDataSourceImpl& mgr) : ctx_(), mgr_(mgr) {
+ MySqlHostDataSourceImpl& mgr) : ctx_(), mgr_(mgr) {
if (MultiThreadingMgr::instance().getMode()) {
// multi-threaded
// multi-threaded
lock_guard<mutex> lock(mgr_.pool_->mutex_);
mgr_.pool_->pool_.push_back(ctx_);
+ if (ctx_->conn_.isUnusable()) {
+ mgr_.unusable_ = true;
+ }
+ } else if (ctx_->conn_.isUnusable()) {
+ mgr_.unusable_ = true;
}
- // If running in single-threaded mode, there's nothing to do here.
}
MySqlHostDataSourceImpl::MySqlHostDataSourceImpl(const DatabaseConnection::ParameterMap& parameters)
- : parameters_(parameters), ip_reservations_unique_(true) {
+ : parameters_(parameters), ip_reservations_unique_(true), unusable_(false) {
// Validate the schema version first.
std::pair<uint32_t, uint32_t> code_version(MYSQL_SCHEMA_VERSION_MAJOR,
std::list<std::string> host_db_access_list = cfg_db->getHostDbAccessStringList();
for (std::string& hds : host_db_access_list) {
auto parameters = DatabaseConnection::parse(hds);
- if (HostMgr::delBackend("mysql", hds)) {
+ if (HostMgr::delBackend("mysql", hds, true)) {
HostMgr::addBackend(hds);
}
}
return (true);
}
+bool
+MySqlHostDataSource::isUnusable() {
+ return (impl_->unusable_);
+}
} // namespace dhcp
} // namespace isc
/// the addresses must be unique and when they may be non-unique.
virtual bool setIPReservationsUnique(const bool unique);
+ /// @brief Flag which indicates if the host manager has at least one
+ /// unusable connection.
+ ///
+ /// @return true if there is at least one unusable connection, false
+ /// otherwise
+ virtual bool isUnusable();
+
/// @brief Context RAII Allocator.
class MySqlHostContextAlloc {
public:
/// or creates a new one.
///
/// @param mgr A parent instance
- MySqlHostContextAlloc(const MySqlHostDataSourceImpl& mgr);
+ MySqlHostContextAlloc(MySqlHostDataSourceImpl& mgr);
/// @brief Destructor
///
private:
/// @brief The manager
- const MySqlHostDataSourceImpl& mgr_;
+ MySqlHostDataSourceImpl& mgr_;
};
private:
/// @brief The pool of contexts
PgSqlHostContextPoolPtr pool_;
+
+ /// @brief Indicates if there is at least one connection that can no longer
+ /// be used for normal operations.
+ bool unusable_;
};
namespace {
// PgSqlHostContextAlloc Constructor and Destructor
PgSqlHostDataSource::PgSqlHostContextAlloc::PgSqlHostContextAlloc(
- const PgSqlHostDataSourceImpl& mgr) : ctx_(), mgr_(mgr) {
+ PgSqlHostDataSourceImpl& mgr) : ctx_(), mgr_(mgr) {
if (MultiThreadingMgr::instance().getMode()) {
// multi-threaded
// multi-threaded
lock_guard<mutex> lock(mgr_.pool_->mutex_);
mgr_.pool_->pool_.push_back(ctx_);
+ if (ctx_->conn_.isUnusable()) {
+ mgr_.unusable_ = true;
+ }
+ } else if (ctx_->conn_.isUnusable()) {
+ mgr_.unusable_ = true;
}
- // If running in single-threaded mode, there's nothing to do here.
}
PgSqlHostDataSourceImpl::PgSqlHostDataSourceImpl(const DatabaseConnection::ParameterMap& parameters)
- : parameters_(parameters), ip_reservations_unique_(true) {
+ : parameters_(parameters), ip_reservations_unique_(true), unusable_(false) {
// Validate the schema version first.
std::pair<uint32_t, uint32_t> code_version(PG_SCHEMA_VERSION_MAJOR,
std::list<std::string> host_db_access_list = cfg_db->getHostDbAccessStringList();
for (std::string& hds : host_db_access_list) {
auto parameters = DatabaseConnection::parse(hds);
- if (HostMgr::delBackend("postgresql", hds)) {
+ if (HostMgr::delBackend("postgresql", hds, true)) {
HostMgr::addBackend(hds);
}
}
return (true);
}
+bool
+PgSqlHostDataSource::isUnusable() {
+ return (impl_->unusable_);
+}
+
} // namespace dhcp
} // namespace isc
/// the addresses must be unique and when they may be non-unique.
virtual bool setIPReservationsUnique(const bool unique);
+ /// @brief Flag which indicates if the host manager has at least one
+ /// unusable connection.
+ ///
+ /// @return true if there is at least one unusable connection, false
+ /// otherwise
+ virtual bool isUnusable();
+
/// @brief Context RAII Allocator.
class PgSqlHostContextAlloc {
public:
/// or creates a new one.
///
/// @param mgr A parent instance
- PgSqlHostContextAlloc(const PgSqlHostDataSourceImpl& mgr);
+ PgSqlHostContextAlloc(PgSqlHostDataSourceImpl& mgr);
/// @brief Destructor
///
private:
/// @brief The manager
- const PgSqlHostDataSourceImpl& mgr_;
+ PgSqlHostDataSourceImpl& mgr_;
};
private:
void
MySqlConnection::openDatabase() {
-
// Set up the values of the parameters
const char* host = "localhost";
string shost;
}
}
-
} // namespace isc::db
} // namespace isc