tagged_statements.end());
// tagged_statements.begin() + WRITE_STMTS_BEGIN);
+ // Create unique timer name per instance.
timer_name_ = "MySqlConfigBackend4[";
timer_name_ += boost::lexical_cast<std::string>(reinterpret_cast<uint64_t>(this));
timer_name_ += "]DbReconnectTimer";
+ // Create ReconnectCtl for this connection.
conn_.makeReconnectCtl(timer_name_);
}
tagged_statements.end());
// tagged_statements.begin() + WRITE_STMTS_BEGIN);
+ // Create unique timer name per instance.
timer_name_ = "MySqlConfigBackend6[";
timer_name_ += boost::lexical_cast<std::string>(reinterpret_cast<uint64_t>(this));
timer_name_ += "]DbReconnectTimer";
+ // Create ReconnectCtl for this connection.
conn_.makeReconnectCtl(timer_name_);
}
isc::dhcp::CfgMgr::instance().clear();
}
- ~MySqlConfigBackendDHCPv4DbLostCallbackTest() {
+ virtual ~MySqlConfigBackendDHCPv4DbLostCallbackTest() {
isc::db::DatabaseConnection::db_lost_callback_ = 0;
isc::db::DatabaseConnection::db_recovered_callback_ = 0;
isc::db::DatabaseConnection::db_failed_callback_ = 0;
/// appropriate schema and create a basic DB manager to
/// wipe out any prior instance
virtual void SetUp() {
- isc::dhcp::MySqlConfigBackendImpl::setIOService(io_service_);
- isc::db::DatabaseConnection::db_lost_callback_ = 0;
- isc::db::DatabaseConnection::db_recovered_callback_ = 0;
- isc::db::DatabaseConnection::db_failed_callback_ = 0;
// Ensure we have the proper schema with no transient data.
createMySQLSchema();
isc::dhcp::CfgMgr::instance().clear();
/// Invoked by gtest upon test exit, we destroy the schema
/// we created.
virtual void TearDown() {
- isc::dhcp::MySqlConfigBackendImpl::setIOService(isc::asiolink::IOServicePtr());
- isc::db::DatabaseConnection::db_lost_callback_ = 0;
- isc::db::DatabaseConnection::db_recovered_callback_ = 0;
- isc::db::DatabaseConnection::db_failed_callback_ = 0;
// If data wipe enabled, delete transient data otherwise destroy the schema
destroyMySQLSchema();
isc::dhcp::CfgMgr::instance().clear();
/// @brief Verifies the CB manager's behavior if DB connection is lost
///
/// This function creates a CB manager with a back end that supports
- /// connectivity lost callback (currently only MySQL and PostgreSQL). It
- /// verifies connectivity by issuing a known valid query. Next it simulates
- /// connectivity lost by identifying and closing the socket connection to
- /// the CB backend. It then reissues the query and verifies that:
+ /// connectivity lost callback. It verifies connectivity by issuing a known
+ /// valid query. Next it simulates connectivity lost by identifying and
+ /// closing the socket connection to the CB backend. It then reissues the
+ /// query and verifies that:
/// -# The Query throws DbOperationError (rather than exiting)
/// -# The registered DbLostCallback was invoked
/// -# The registered DbRecoveredCallback was invoked
/// @brief Verifies the CB manager's behavior if DB connection is lost
///
/// This function creates a CB manager with a back end that supports
- /// connectivity lost callback (currently only MySQL and PostgreSQL). It
- /// verifies connectivity by issuing a known valid query. Next it simulates
- /// connectivity lost by identifying and closing the socket connection to
- /// the CB backend. It then reissues the query and verifies that:
+ /// connectivity lost callback. It verifies connectivity by issuing a known
+ /// valid query. Next it simulates connectivity lost by identifying and
+ /// closing the socket connection to the CB backend. It then reissues the
+ /// query and verifies that:
/// -# The Query throws DbOperationError (rather than exiting)
/// -# The registered DbLostCallback was invoked
/// -# The registered DbFailedCallback was invoked
/// @brief Verifies the CB manager's behavior if DB connection is lost
///
/// This function creates a CB manager with a back end that supports
- /// connectivity lost callback (currently only MySQL and PostgreSQL). It
- /// verifies connectivity by issuing a known valid query. Next it simulates
- /// connectivity lost by identifying and closing the socket connection to
- /// the CB backend. It then reissues the query and verifies that:
+ /// connectivity lost callback. It verifies connectivity by issuing a known
+ /// valid query. Next it simulates connectivity lost by identifying and
+ /// closing the socket connection to the CB backend. It then reissues the
+ /// query and verifies that:
/// -# The Query throws DbOperationError (rather than exiting)
/// -# The registered DbLostCallback was invoked
/// -# The registered DbRecoveredCallback was invoked after two reconnect
/// @brief Verifies the CB manager's behavior if DB connection is lost
///
/// This function creates a CB manager with a back end that supports
- /// connectivity lost callback (currently only MySQL and PostgreSQL). It
- /// verifies connectivity by issuing a known valid query. Next it simulates
- /// connectivity lost by identifying and closing the socket connection to
- /// the CB backend. It then reissues the query and verifies that:
+ /// connectivity lost callback. It verifies connectivity by issuing a known
+ /// valid query. Next it simulates connectivity lost by identifying and
+ /// closing the socket connection to the CB backend. It then reissues the
+ /// query and verifies that:
/// -# The Query throws DbOperationError (rather than exiting)
/// -# The registered DbLostCallback was invoked
/// -# The registered DbFailedCallback was invoked after two reconnect
isc::dhcp::CfgMgr::instance().clear();
}
- ~MySqlConfigBackendDHCPv6DbLostCallbackTest() {
+ virtual ~MySqlConfigBackendDHCPv6DbLostCallbackTest() {
isc::db::DatabaseConnection::db_lost_callback_ = 0;
isc::db::DatabaseConnection::db_recovered_callback_ = 0;
isc::db::DatabaseConnection::db_failed_callback_ = 0;
/// appropriate schema and create a basic DB manager to
/// wipe out any prior instance
virtual void SetUp() {
- isc::dhcp::MySqlConfigBackendImpl::setIOService(io_service_);
- isc::db::DatabaseConnection::db_lost_callback_ = 0;
- isc::db::DatabaseConnection::db_recovered_callback_ = 0;
- isc::db::DatabaseConnection::db_failed_callback_ = 0;
// Ensure we have the proper schema with no transient data.
createMySQLSchema();
isc::dhcp::CfgMgr::instance().clear();
/// Invoked by gtest upon test exit, we destroy the schema
/// we created.
virtual void TearDown() {
- isc::dhcp::MySqlConfigBackendImpl::setIOService(isc::asiolink::IOServicePtr());
- isc::db::DatabaseConnection::db_lost_callback_ = 0;
- isc::db::DatabaseConnection::db_recovered_callback_ = 0;
- isc::db::DatabaseConnection::db_failed_callback_ = 0;
// If data wipe enabled, delete transient data otherwise destroy the schema
destroyMySQLSchema();
isc::dhcp::CfgMgr::instance().clear();
/// @brief Verifies the CB manager's behavior if DB connection is lost
///
/// This function creates a CB manager with a back end that supports
- /// connectivity lost callback (currently only MySQL and PostgreSQL). It
- /// verifies connectivity by issuing a known valid query. Next it simulates
- /// connectivity lost by identifying and closing the socket connection to
- /// the CB backend. It then reissues the query and verifies that:
+ /// connectivity lost callback. It verifies connectivity by issuing a known
+ /// valid query. Next it simulates connectivity lost by identifying and
+ /// closing the socket connection to the CB backend. It then reissues the
+ /// query and verifies that:
/// -# The Query throws DbOperationError (rather than exiting)
/// -# The registered DbLostCallback was invoked
/// -# The registered DbRecoveredCallback was invoked
/// @brief Verifies the CB manager's behavior if DB connection is lost
///
/// This function creates a CB manager with a back end that supports
- /// connectivity lost callback (currently only MySQL and PostgreSQL). It
- /// verifies connectivity by issuing a known valid query. Next it simulates
- /// connectivity lost by identifying and closing the socket connection to
- /// the CB backend. It then reissues the query and verifies that:
+ /// connectivity lost callback. It verifies connectivity by issuing a known
+ /// valid query. Next it simulates connectivity lost by identifying and
+ /// closing the socket connection to the CB backend. It then reissues the
+ /// query and verifies that:
/// -# The Query throws DbOperationError (rather than exiting)
/// -# The registered DbLostCallback was invoked
/// -# The registered DbFailedCallback was invoked
/// @brief Verifies the CB manager's behavior if DB connection is lost
///
/// This function creates a CB manager with a back end that supports
- /// connectivity lost callback (currently only MySQL and PostgreSQL). It
- /// verifies connectivity by issuing a known valid query. Next it simulates
- /// connectivity lost by identifying and closing the socket connection to
- /// the CB backend. It then reissues the query and verifies that:
+ /// connectivity lost callback. It verifies connectivity by issuing a known
+ /// valid query. Next it simulates connectivity lost by identifying and
+ /// closing the socket connection to the CB backend. It then reissues the
+ /// query and verifies that:
/// -# The Query throws DbOperationError (rather than exiting)
/// -# The registered DbLostCallback was invoked
/// -# The registered DbRecoveredCallback was invoked after two reconnect
/// @brief Verifies the CB manager's behavior if DB connection is lost
///
/// This function creates a CB manager with a back end that supports
- /// connectivity lost callback (currently only MySQL and PostgreSQL). It
- /// verifies connectivity by issuing a known valid query. Next it simulates
- /// connectivity lost by identifying and closing the socket connection to
- /// the CB backend. It then reissues the query and verifies that:
+ /// connectivity lost callback. It verifies connectivity by issuing a known
+ /// valid query. Next it simulates connectivity lost by identifying and
+ /// closing the socket connection to the CB backend. It then reissues the
+ /// query and verifies that:
/// -# The Query throws DbOperationError (rather than exiting)
/// -# The registered DbLostCallback was invoked
/// -# The registered DbFailedCallback was invoked after two reconnect
: parameters_(parameters), ip_reservations_unique_(true), unusable_(false),
timer_name_("") {
+ // Create unique timer name per instance.
timer_name_ = "MySqlHostMgr[";
timer_name_ += boost::lexical_cast<std::string>(reinterpret_cast<uint64_t>(this));
timer_name_ += "]DbReconnectTimer";
ctx->host_ipv6_reservation_exchange_.reset(new MySqlIPv6ReservationExchange());
ctx->host_option_exchange_.reset(new MySqlOptionExchange());
+ // Create ReconnectCtl for this connection.
ctx->conn_.makeReconnectCtl(timer_name_);
return (ctx);
HostMgr::addBackend(hds);
}
}
-
reopened = true;
} catch (const std::exception& ex) {
LOG_ERROR(dhcpsrv_logger, DHCPSRV_MYSQL_HOST_DB_RECONNECT_ATTEMPT_FAILED)
// Invoke application layer connection failed callback.
DatabaseConnection::invokeDbFailedCallback(db_reconnect_ctl);
-
return (false);
}
MySqlLeaseMgr::MySqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters)
: parameters_(parameters), timer_name_("") {
+ // Create unique timer name per instance.
timer_name_ = "MySqlLeaseMgr[";
timer_name_ += boost::lexical_cast<std::string>(reinterpret_cast<uint64_t>(this));
timer_name_ += "]DbReconnectTimer";
CfgDbAccessPtr cfg_db = CfgMgr::instance().getCurrentCfg()->getCfgDbAccess();
LeaseMgrFactory::destroy();
LeaseMgrFactory::create(cfg_db->getLeaseDbAccessString());
-
reopened = true;
} catch (const std::exception& ex) {
LOG_ERROR(dhcpsrv_logger, DHCPSRV_MYSQL_LEASE_DB_RECONNECT_ATTEMPT_FAILED)
// Invoke application layer connection failed callback.
DatabaseConnection::invokeDbFailedCallback(db_reconnect_ctl);
-
return (false);
}
ctx->exchange4_.reset(new MySqlLease4Exchange());
ctx->exchange6_.reset(new MySqlLease6Exchange());
+ // Create ReconnectCtl for this connection.
ctx->conn_.makeReconnectCtl(timer_name_);
return (ctx);
: parameters_(parameters), ip_reservations_unique_(true), unusable_(false),
timer_name_("") {
+ // Create unique timer name per instance.
timer_name_ = "PgSqlHostMgr[";
timer_name_ += boost::lexical_cast<std::string>(reinterpret_cast<uint64_t>(this));
timer_name_ += "]DbReconnectTimer";
ctx->host_ipv6_reservation_exchange_.reset(new PgSqlIPv6ReservationExchange());
ctx->host_option_exchange_.reset(new PgSqlOptionExchange());
+ // Create ReconnectCtl for this connection.
ctx->conn_.makeReconnectCtl(timer_name_);
return (ctx);
HostMgr::addBackend(hds);
}
}
-
reopened = true;
} catch (const std::exception& ex) {
LOG_ERROR(dhcpsrv_logger, DHCPSRV_PGSQL_HOST_DB_RECONNECT_ATTEMPT_FAILED)
// Invoke application layer connection failed callback.
DatabaseConnection::invokeDbFailedCallback(db_reconnect_ctl);
-
return (false);
}
PgSqlLeaseMgr::PgSqlLeaseMgr(const DatabaseConnection::ParameterMap& parameters)
: parameters_(parameters), timer_name_("") {
+ // Create unique timer name per instance.
timer_name_ = "PgSqlLeaseMgr[";
timer_name_ += boost::lexical_cast<std::string>(reinterpret_cast<uint64_t>(this));
timer_name_ += "]DbReconnectTimer";
CfgDbAccessPtr cfg_db = CfgMgr::instance().getCurrentCfg()->getCfgDbAccess();
LeaseMgrFactory::destroy();
LeaseMgrFactory::create(cfg_db->getLeaseDbAccessString());
-
reopened = true;
} catch (const std::exception& ex) {
LOG_ERROR(dhcpsrv_logger, DHCPSRV_PGSQL_LEASE_DB_RECONNECT_ATTEMPT_FAILED)
// Invoke application layer connection failed callback.
DatabaseConnection::invokeDbFailedCallback(db_reconnect_ctl);
-
return (false);
}
ctx->exchange4_.reset(new PgSqlLease4Exchange());
ctx->exchange6_.reset(new PgSqlLease6Exchange());
+ // Create ReconnectCtl for this connection.
ctx->conn_.makeReconnectCtl(timer_name_);
return (ctx);
isc::dhcp::CfgMgr::instance().clear();
}
- ~HostMgrDbLostCallbackTest() {
+ virtual ~HostMgrDbLostCallbackTest() {
isc::db::DatabaseConnection::db_lost_callback_ = 0;
isc::db::DatabaseConnection::db_recovered_callback_ = 0;
isc::db::DatabaseConnection::db_failed_callback_ = 0;
/// appropriate schema and create a basic host manager to
/// wipe out any prior instance
virtual void SetUp() {
- isc::dhcp::HostMgr::setIOService(io_service_);
- isc::db::DatabaseConnection::db_lost_callback_ = 0;
- isc::db::DatabaseConnection::db_recovered_callback_ = 0;
- isc::db::DatabaseConnection::db_failed_callback_ = 0;
// Ensure we have the proper schema with no transient data.
createSchema();
// Wipe out any pre-existing mgr
/// Invoked by gtest upon test exit, we destroy the schema
/// we created.
virtual void TearDown() {
- isc::dhcp::HostMgr::setIOService(isc::asiolink::IOServicePtr());
- isc::db::DatabaseConnection::db_lost_callback_ = 0;
- isc::db::DatabaseConnection::db_recovered_callback_ = 0;
- isc::db::DatabaseConnection::db_failed_callback_ = 0;
// If data wipe enabled, delete transient data otherwise destroy the schema
destroySchema();
isc::dhcp::CfgMgr::instance().clear();
///
/// @note The recover function must be run on the IO Service thread.
void startRecoverDbConnection() {
- if (!io_service_ && io_service_access_callback_) {
- io_service_ = (*io_service_access_callback_)();
- }
- if (callback_ && io_service_) {
- io_service_->post(std::bind(callback_, reconnectCtl()));
+ if (callback_) {
+ if (!io_service_ && io_service_access_callback_) {
+ io_service_ = (*io_service_access_callback_)();
+ io_service_access_callback_.reset();
+ }
+
+ if (io_service_) {
+ io_service_->post(std::bind(callback_, reconnectCtl()));
+ }
}
}
///
/// @note The recover function must be run on the IO Service thread.
void startRecoverDbConnection() {
- if (!io_service_ && io_service_access_callback_) {
- io_service_ = (*io_service_access_callback_)();
- }
- if (callback_ && io_service_) {
- io_service_->post(std::bind(callback_, reconnectCtl()));
+ if (callback_) {
+ if (!io_service_ && io_service_access_callback_) {
+ io_service_ = (*io_service_access_callback_)();
+ io_service_access_callback_.reset();
+ }
+
+ if (io_service_) {
+ io_service_->post(std::bind(callback_, reconnectCtl()));
+ }
}
}