mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-01 06:25:34 +00:00
[#1621] add lazy retrieval for connection IOService
This commit is contained in:
@@ -47,8 +47,10 @@ ScopedAuditRevision::~ScopedAuditRevision() {
|
|||||||
MySqlConfigBackendImpl::
|
MySqlConfigBackendImpl::
|
||||||
MySqlConfigBackendImpl(const DatabaseConnection::ParameterMap& parameters,
|
MySqlConfigBackendImpl(const DatabaseConnection::ParameterMap& parameters,
|
||||||
const DbCallback db_reconnect_callback)
|
const DbCallback db_reconnect_callback)
|
||||||
: conn_(parameters, MySqlConfigBackendImpl::getIOService(), db_reconnect_callback),
|
: conn_(parameters,
|
||||||
timer_name_(""), audit_revision_created_(false), parameters_(parameters) {
|
IOServiceAccessCallbackPtr(new IOServiceAccessCallback(MySqlConfigBackendImpl::getIOService)),
|
||||||
|
db_reconnect_callback), timer_name_(""),
|
||||||
|
audit_revision_created_(false), parameters_(parameters) {
|
||||||
// Test schema version first.
|
// Test schema version first.
|
||||||
std::pair<uint32_t, uint32_t> code_version(MYSQL_SCHEMA_VERSION_MAJOR,
|
std::pair<uint32_t, uint32_t> code_version(MYSQL_SCHEMA_VERSION_MAJOR,
|
||||||
MYSQL_SCHEMA_VERSION_MINOR);
|
MYSQL_SCHEMA_VERSION_MINOR);
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
#ifndef DATABASE_CONNECTION_H
|
#ifndef DATABASE_CONNECTION_H
|
||||||
#define DATABASE_CONNECTION_H
|
#define DATABASE_CONNECTION_H
|
||||||
|
|
||||||
|
#include <asiolink/io_service.h>
|
||||||
#include <cc/data.h>
|
#include <cc/data.h>
|
||||||
#include <boost/noncopyable.hpp>
|
#include <boost/noncopyable.hpp>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
@@ -160,6 +161,13 @@ typedef boost::shared_ptr<ReconnectCtl> ReconnectCtlPtr;
|
|||||||
/// @brief Defines a callback prototype for propagating events upward
|
/// @brief Defines a callback prototype for propagating events upward
|
||||||
typedef std::function<bool (ReconnectCtlPtr db_reconnect_ctl)> DbCallback;
|
typedef std::function<bool (ReconnectCtlPtr db_reconnect_ctl)> DbCallback;
|
||||||
|
|
||||||
|
/// @brief Callback which returns the IOService that can be used to recover the
|
||||||
|
/// connection.
|
||||||
|
typedef std::function<isc::asiolink::IOServicePtr ()> IOServiceAccessCallback;
|
||||||
|
|
||||||
|
/// @brief Pointer to an instance of IOServiceAccessCallbackPtr
|
||||||
|
typedef boost::shared_ptr<IOServiceAccessCallback> IOServiceAccessCallbackPtr;
|
||||||
|
|
||||||
/// @brief Common database connection class.
|
/// @brief Common database connection class.
|
||||||
///
|
///
|
||||||
/// This class provides functions that are common for establishing
|
/// This class provides functions that are common for establishing
|
||||||
|
@@ -1737,9 +1737,9 @@ bool MySqlLeaseStatsQuery::negative_count_ = false;
|
|||||||
// MySqlLeaseContext Constructor
|
// MySqlLeaseContext Constructor
|
||||||
|
|
||||||
MySqlLeaseContext::MySqlLeaseContext(const DatabaseConnection::ParameterMap& parameters,
|
MySqlLeaseContext::MySqlLeaseContext(const DatabaseConnection::ParameterMap& parameters,
|
||||||
const isc::asiolink::IOServicePtr& io_service,
|
IOServiceAccessCallbackPtr io_service_access_callback,
|
||||||
DbCallback db_reconnect_callback)
|
DbCallback db_reconnect_callback)
|
||||||
: conn_(parameters, io_service, db_reconnect_callback) {
|
: conn_(parameters, io_service_access_callback, db_reconnect_callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MySqlLeaseContextAlloc Constructor and Destructor
|
// MySqlLeaseContextAlloc Constructor and Destructor
|
||||||
@@ -1882,8 +1882,8 @@ MySqlLeaseMgr::dbReconnect(ReconnectCtlPtr db_reconnect_ctl) {
|
|||||||
MySqlLeaseContextPtr
|
MySqlLeaseContextPtr
|
||||||
MySqlLeaseMgr::createContext() const {
|
MySqlLeaseMgr::createContext() const {
|
||||||
MySqlLeaseContextPtr ctx(new MySqlLeaseContext(parameters_,
|
MySqlLeaseContextPtr ctx(new MySqlLeaseContext(parameters_,
|
||||||
LeaseMgr::getIOService(),
|
IOServiceAccessCallbackPtr(new IOServiceAccessCallback(&LeaseMgr::getIOService)),
|
||||||
&MySqlLeaseMgr::dbReconnect));
|
&MySqlLeaseMgr::dbReconnect));
|
||||||
|
|
||||||
// Open the database.
|
// Open the database.
|
||||||
ctx->conn_.openDatabase();
|
ctx->conn_.openDatabase();
|
||||||
|
@@ -44,10 +44,10 @@ public:
|
|||||||
/// @brief Constructor
|
/// @brief Constructor
|
||||||
///
|
///
|
||||||
/// @param parameters See MySqlLeaseMgr constructor.
|
/// @param parameters See MySqlLeaseMgr constructor.
|
||||||
/// @param io_service The IOService object, used for all ASIO operations.
|
/// @param io_service_access_callback The IOService access callback.
|
||||||
/// @param db_reconnect_callback The connection recovery callback.
|
/// @param db_reconnect_callback The connection recovery callback.
|
||||||
MySqlLeaseContext(const db::DatabaseConnection::ParameterMap& parameters,
|
MySqlLeaseContext(const db::DatabaseConnection::ParameterMap& parameters,
|
||||||
const isc::asiolink::IOServicePtr& io_service,
|
db::IOServiceAccessCallbackPtr io_service_access_callback,
|
||||||
db::DbCallback db_reconnect_callback);
|
db::DbCallback db_reconnect_callback);
|
||||||
|
|
||||||
/// The exchange objects are used for transfer of data to/from the database.
|
/// The exchange objects are used for transfer of data to/from the database.
|
||||||
|
@@ -1171,9 +1171,9 @@ bool PgSqlLeaseStatsQuery::negative_count_ = false;
|
|||||||
// PgSqlLeaseContext Constructor
|
// PgSqlLeaseContext Constructor
|
||||||
|
|
||||||
PgSqlLeaseContext::PgSqlLeaseContext(const DatabaseConnection::ParameterMap& parameters,
|
PgSqlLeaseContext::PgSqlLeaseContext(const DatabaseConnection::ParameterMap& parameters,
|
||||||
const isc::asiolink::IOServicePtr& io_service,
|
IOServiceAccessCallbackPtr io_service_access_callback,
|
||||||
DbCallback db_reconnect_callback)
|
DbCallback db_reconnect_callback)
|
||||||
: conn_(parameters, io_service, db_reconnect_callback) {
|
: conn_(parameters, io_service_access_callback, db_reconnect_callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// PgSqlLeaseContextAlloc Constructor and Destructor
|
// PgSqlLeaseContextAlloc Constructor and Destructor
|
||||||
@@ -1316,8 +1316,8 @@ PgSqlLeaseMgr::dbReconnect(ReconnectCtlPtr db_reconnect_ctl) {
|
|||||||
PgSqlLeaseContextPtr
|
PgSqlLeaseContextPtr
|
||||||
PgSqlLeaseMgr::createContext() const {
|
PgSqlLeaseMgr::createContext() const {
|
||||||
PgSqlLeaseContextPtr ctx(new PgSqlLeaseContext(parameters_,
|
PgSqlLeaseContextPtr ctx(new PgSqlLeaseContext(parameters_,
|
||||||
LeaseMgr::getIOService(),
|
IOServiceAccessCallbackPtr(new IOServiceAccessCallback(&LeaseMgr::getIOService)),
|
||||||
&PgSqlLeaseMgr::dbReconnect));
|
&PgSqlLeaseMgr::dbReconnect));
|
||||||
|
|
||||||
// Open the database.
|
// Open the database.
|
||||||
ctx->conn_.openDatabase();
|
ctx->conn_.openDatabase();
|
||||||
|
@@ -43,10 +43,10 @@ public:
|
|||||||
/// @brief Constructor
|
/// @brief Constructor
|
||||||
///
|
///
|
||||||
/// @param parameters See PgSqlLeaseMgr constructor.
|
/// @param parameters See PgSqlLeaseMgr constructor.
|
||||||
/// @param io_service The IOService object, used for all ASIO operations.
|
/// @param io_service_access_callback The IOService access callback.
|
||||||
/// @param db_reconnect_callback The connection recovery callback.
|
/// @param db_reconnect_callback The connection recovery callback.
|
||||||
PgSqlLeaseContext(const db::DatabaseConnection::ParameterMap& parameters,
|
PgSqlLeaseContext(const db::DatabaseConnection::ParameterMap& parameters,
|
||||||
const isc::asiolink::IOServicePtr& io_service,
|
db::IOServiceAccessCallbackPtr io_service_access_callback,
|
||||||
db::DbCallback db_reconnect_callback);
|
db::DbCallback db_reconnect_callback);
|
||||||
|
|
||||||
/// The exchange objects are used for transfer of data to/from the database.
|
/// The exchange objects are used for transfer of data to/from the database.
|
||||||
|
@@ -241,13 +241,14 @@ public:
|
|||||||
/// Initialize MySqlConnection object with parameters needed for connection.
|
/// Initialize MySqlConnection object with parameters needed for connection.
|
||||||
///
|
///
|
||||||
/// @param parameters Specify the connection details.
|
/// @param parameters Specify the connection details.
|
||||||
/// @param io_service The IOService object, used for all ASIO operations.
|
/// @param io_access_callback The IOService access callback.
|
||||||
/// @param callback The connection recovery callback.
|
/// @param callback The connection recovery callback.
|
||||||
MySqlConnection(const ParameterMap& parameters,
|
MySqlConnection(const ParameterMap& parameters,
|
||||||
const isc::asiolink::IOServicePtr& io_service = isc::asiolink::IOServicePtr(),
|
IOServiceAccessCallbackPtr io_access_callback = IOServiceAccessCallbackPtr(),
|
||||||
DbCallback callback = DbCallback())
|
DbCallback callback = DbCallback())
|
||||||
: DatabaseConnection(parameters), io_service_(io_service),
|
: DatabaseConnection(parameters),
|
||||||
callback_(callback) {
|
io_service_access_callback_(io_access_callback),
|
||||||
|
io_service_(), callback_(callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Destructor
|
/// @brief Destructor
|
||||||
@@ -657,6 +658,9 @@ public:
|
|||||||
///
|
///
|
||||||
/// @note The recover function must be run on the IO Service thread.
|
/// @note The recover function must be run on the IO Service thread.
|
||||||
void startRecoverDbConnection() {
|
void startRecoverDbConnection() {
|
||||||
|
if (!io_service_ && io_service_access_callback_) {
|
||||||
|
io_service_ = (*io_service_access_callback_)();
|
||||||
|
}
|
||||||
if (callback_ && io_service_) {
|
if (callback_ && io_service_) {
|
||||||
io_service_->post(std::bind(callback_, reconnectCtl()));
|
io_service_->post(std::bind(callback_, reconnectCtl()));
|
||||||
}
|
}
|
||||||
@@ -680,6 +684,10 @@ public:
|
|||||||
/// and will be from MySqlHostDataSource.
|
/// and will be from MySqlHostDataSource.
|
||||||
MySqlHolder mysql_;
|
MySqlHolder mysql_;
|
||||||
|
|
||||||
|
/// @brief Callback which returns the IOService that can be used to recover
|
||||||
|
/// the connection.
|
||||||
|
IOServiceAccessCallbackPtr io_service_access_callback_;
|
||||||
|
|
||||||
/// @brief IOService object, used for all ASIO operations.
|
/// @brief IOService object, used for all ASIO operations.
|
||||||
isc::asiolink::IOServicePtr io_service_;
|
isc::asiolink::IOServicePtr io_service_;
|
||||||
|
|
||||||
|
@@ -307,13 +307,14 @@ public:
|
|||||||
/// Initialize PgSqlConnection object with parameters needed for connection.
|
/// Initialize PgSqlConnection object with parameters needed for connection.
|
||||||
///
|
///
|
||||||
/// @param parameters Specify the connection details.
|
/// @param parameters Specify the connection details.
|
||||||
/// @param io_service The IOService object, used for all ASIO operations.
|
/// @param io_access_callback The IOService access callback.
|
||||||
/// @param callback The connection recovery callback.
|
/// @param callback The connection recovery callback.
|
||||||
PgSqlConnection(const ParameterMap& parameters,
|
PgSqlConnection(const ParameterMap& parameters,
|
||||||
const isc::asiolink::IOServicePtr& io_service = isc::asiolink::IOServicePtr(),
|
IOServiceAccessCallbackPtr io_access_callback = IOServiceAccessCallbackPtr(),
|
||||||
DbCallback callback = DbCallback())
|
DbCallback callback = DbCallback())
|
||||||
: DatabaseConnection(parameters), io_service_(io_service),
|
: DatabaseConnection(parameters),
|
||||||
callback_(callback) {
|
io_service_access_callback_(io_access_callback),
|
||||||
|
io_service_(), callback_(callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Destructor
|
/// @brief Destructor
|
||||||
@@ -425,6 +426,9 @@ public:
|
|||||||
///
|
///
|
||||||
/// @note The recover function must be run on the IO Service thread.
|
/// @note The recover function must be run on the IO Service thread.
|
||||||
void startRecoverDbConnection() {
|
void startRecoverDbConnection() {
|
||||||
|
if (!io_service_ && io_service_access_callback_) {
|
||||||
|
io_service_ = (*io_service_access_callback_)();
|
||||||
|
}
|
||||||
if (callback_ && io_service_) {
|
if (callback_ && io_service_) {
|
||||||
io_service_->post(std::bind(callback_, reconnectCtl()));
|
io_service_->post(std::bind(callback_, reconnectCtl()));
|
||||||
}
|
}
|
||||||
@@ -451,6 +455,10 @@ public:
|
|||||||
return (conn_);
|
return (conn_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Callback which returns the IOService that can be used to recover
|
||||||
|
/// the connection.
|
||||||
|
IOServiceAccessCallbackPtr io_service_access_callback_;
|
||||||
|
|
||||||
/// @brief IOService object, used for all ASIO operations.
|
/// @brief IOService object, used for all ASIO operations.
|
||||||
isc::asiolink::IOServicePtr io_service_;
|
isc::asiolink::IOServicePtr io_service_;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user