/// @param single A boolean value indicating if a single host is
/// expected to be returned, or multiple hosts.
void getHostCollection(StatementIndex stindex, MYSQL_BIND* bind,
- boost::shared_ptr<MySqlHostExchange> exchange,
+ std::shared_ptr<MySqlHostExchange> exchange,
ConstHostCollection& result, bool single) const;
/// @brief Retrieves a host by subnet and client's unique identifier.
const uint8_t* identifier_begin,
const size_t identifier_len,
StatementIndex stindex,
- boost::shared_ptr<MySqlHostExchange> exchange) const;
+ std::shared_ptr<MySqlHostExchange> exchange) const;
/// @brief Throws exception if database is read only.
///
/// @throw DbReadOnly if backend is operating in read only mode.
void checkReadOnly() const;
- /// @brief Pointer to the object representing an exchange which
- /// can be used to retrieve hosts and DHCPv4 options.
- boost::shared_ptr<MySqlHostWithOptionsExchange> host_exchange_;
-
- /// @brief Pointer to an object representing an exchange which can
- /// be used to retrieve hosts, DHCPv6 options and IPv6 reservations.
- boost::shared_ptr<MySqlHostIPv6Exchange> host_ipv6_exchange_;
-
- /// @brief Pointer to an object representing an exchange which can
- /// be used to retrieve hosts, DHCPv4 and DHCPv6 options, and
- /// IPv6 reservations using a single query.
- boost::shared_ptr<MySqlHostIPv6Exchange> host_ipv46_exchange_;
-
- /// @brief Pointer to an object representing an exchange which can
- /// be used to insert new IPv6 reservation.
- boost::shared_ptr<MySqlIPv6ReservationExchange> host_ipv6_reservation_exchange_;
-
- /// @brief Pointer to an object representing an exchange which can
- /// be used to insert DHCPv4 or DHCPv6 option into dhcp4_options
- /// or dhcp6_options table.
- boost::shared_ptr<MySqlOptionExchange> host_option_exchange_;
-
/// @brief MySQL connection
MySqlConnection conn_;
"h.dhcp_identifier_type, h.dhcp4_subnet_id, "
"h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
"h.dhcp4_client_classes, h.dhcp6_client_classes, h.user_context, "
-
"h.dhcp4_next_server, h.dhcp4_server_hostname, "
"h.dhcp4_boot_file_name, h.auth_key, "
"o.option_id, o.code, o.value, o.formatted_value, o.space, "
"h.dhcp_identifier_type, h.dhcp4_subnet_id, "
"h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
"h.dhcp4_client_classes, h.dhcp6_client_classes, h.user_context, "
-
"h.dhcp4_next_server, h.dhcp4_server_hostname, "
"h.dhcp4_boot_file_name, h.auth_key, "
"o.option_id, o.code, o.value, o.formatted_value, o.space, "
"h.dhcp_identifier_type, h.dhcp4_subnet_id, "
"h.dhcp6_subnet_id, h.ipv4_address, h.hostname, "
"h.dhcp4_client_classes, h.dhcp6_client_classes, h.user_context, "
-
"h.dhcp4_next_server, h.dhcp4_server_hostname, "
"h.dhcp4_boot_file_name, h.auth_key, "
"o.option_id, o.code, o.value, o.formatted_value, o.space, "
}; // anonymous namespace
MySqlHostDataSourceImpl::
-MySqlHostDataSourceImpl(const MySqlConnection::ParameterMap& parameters)
- : host_exchange_(new MySqlHostWithOptionsExchange(MySqlHostWithOptionsExchange::DHCP4_ONLY)),
- host_ipv6_exchange_(new MySqlHostIPv6Exchange(MySqlHostWithOptionsExchange::DHCP6_ONLY)),
- host_ipv46_exchange_(new MySqlHostIPv6Exchange(MySqlHostWithOptionsExchange::
- DHCP4_AND_DHCP6)),
- host_ipv6_reservation_exchange_(new MySqlIPv6ReservationExchange()),
- host_option_exchange_(new MySqlOptionExchange()),
- conn_(parameters),
- is_readonly_(false) {
+MySqlHostDataSourceImpl(const MySqlConnection::ParameterMap& parameters) :
+ conn_(parameters), is_readonly_(false) {
// Open the database.
conn_.openDatabase();
const char* version_sql = "SELECT version, minor FROM schema_version";
int status = mysql_stmt_prepare(stmt, version_sql, strlen(version_sql));
if (status != 0) {
+ mysql_stmt_close(stmt);
isc_throw(DbOperationError, "unable to prepare MySQL statement <"
<< version_sql << ">, reason: " << mysql_errno(conn_.mysql_));
}
// Execute the prepared statement.
if (mysql_stmt_execute(stmt) != 0) {
+ mysql_stmt_close(stmt);
isc_throw(DbOperationError, "cannot execute schema version query <"
<< version_sql << ">, reason: " << mysql_errno(conn_.mysql_));
}
return (std::make_pair(major, minor));
}
-
void
MySqlHostDataSourceImpl::addStatement(StatementIndex stindex,
std::vector<MYSQL_BIND>& bind) {
void
MySqlHostDataSourceImpl::addResv(const IPv6Resrv& resv,
const HostID& id) {
+ thread_local std::shared_ptr<MySqlIPv6ReservationExchange> host_ipv6_reservation_exchange(
+ std::make_shared<MySqlIPv6ReservationExchange>());
+
std::vector<MYSQL_BIND> bind =
- host_ipv6_reservation_exchange_->createBindForSend(resv, id);
+ host_ipv6_reservation_exchange->createBindForSend(resv, id);
addStatement(INSERT_V6_RESRV, bind);
}
const std::string& opt_space,
const Optional<SubnetID>& subnet_id,
const HostID& id) {
+ thread_local std::shared_ptr<MySqlOptionExchange> host_option_exchange(
+ std::make_shared<MySqlOptionExchange>());
+
std::vector<MYSQL_BIND> bind =
- host_option_exchange_->createBindForSend(opt_desc, opt_space,
- subnet_id, id);
+ host_option_exchange->createBindForSend(opt_desc, opt_space, subnet_id, id);
addStatement(stindex, bind);
}
void
MySqlHostDataSourceImpl::
getHostCollection(StatementIndex stindex, MYSQL_BIND* bind,
- boost::shared_ptr<MySqlHostExchange> exchange,
+ std::shared_ptr<MySqlHostExchange> exchange,
ConstHostCollection& result, bool single) const {
// Bind the selection parameters to the statement
const uint8_t* identifier_begin,
const size_t identifier_len,
StatementIndex stindex,
- boost::shared_ptr<MySqlHostExchange> exchange) const {
+ std::shared_ptr<MySqlHostExchange> exchange) const {
// Set up the WHERE clause value
MYSQL_BIND inbind[3];
// Return single record if present, else clear the host.
ConstHostPtr result;
- if (!collection.empty())
+ if (!collection.empty()) {
result = *collection.begin();
+ }
return (result);
}
// If operating in read-only mode, throw exception.
impl_->checkReadOnly();
+ thread_local std::shared_ptr<MySqlHostWithOptionsExchange> host_ipv4_exchange(
+ std::make_shared<MySqlHostWithOptionsExchange>(MySqlHostWithOptionsExchange::DHCP4_ONLY));
+
// Initiate MySQL transaction as we will have to make multiple queries
// to insert host information into multiple tables. If that fails on
// any stage, the transaction will be rolled back by the destructor of
MySqlTransaction transaction(impl_->conn_);
// Create the MYSQL_BIND array for the host
- std::vector<MYSQL_BIND> bind = impl_->host_exchange_->createBindForSend(host);
+ std::vector<MYSQL_BIND> bind = host_ipv4_exchange->createBindForSend(host);
// ... and insert the host.
impl_->addStatement(MySqlHostDataSourceImpl::INSERT_HOST, bind);
}
// v6
- ConstHostPtr host = get6(subnet_id, addr);
+ ConstHostPtr host(get6(subnet_id, addr));
if (!host) {
return (false);
}
MySqlHostDataSource::getAll(const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
const size_t identifier_len) const {
+ thread_local std::shared_ptr<MySqlHostIPv6Exchange> host_ipv46_exchange(
+ std::make_shared<MySqlHostIPv6Exchange>(MySqlHostWithOptionsExchange::DHCP4_AND_DHCP6));
+
// Set up the WHERE clause value
MYSQL_BIND inbind[2];
memset(inbind, 0, sizeof(inbind));
inbind[0].length = &length;
ConstHostCollection result;
- impl_->getHostCollection(MySqlHostDataSourceImpl::GET_HOST_DHCPID, inbind,
- impl_->host_ipv46_exchange_,
- result, false);
+ impl_->getHostCollection(MySqlHostDataSourceImpl::GET_HOST_DHCPID,
+ inbind, host_ipv46_exchange, result, false);
return (result);
}
ConstHostCollection
MySqlHostDataSource::getAll4(const SubnetID& subnet_id) const {
+ thread_local std::shared_ptr<MySqlHostWithOptionsExchange> host_ipv4_exchange(
+ std::make_shared<MySqlHostWithOptionsExchange>(MySqlHostWithOptionsExchange::DHCP4_ONLY));
+
// Set up the WHERE clause value
MYSQL_BIND inbind[1];
memset(inbind, 0, sizeof(inbind));
ConstHostCollection result;
impl_->getHostCollection(MySqlHostDataSourceImpl::GET_HOST_SUBID4,
- inbind, impl_->host_exchange_,
- result, false);
+ inbind, host_ipv4_exchange, result, false);
return (result);
}
ConstHostCollection
MySqlHostDataSource::getAll6(const SubnetID& subnet_id) const {
+ thread_local std::shared_ptr<MySqlHostIPv6Exchange> host_ipv6_exchange(
+ std::make_shared<MySqlHostIPv6Exchange>(MySqlHostWithOptionsExchange::DHCP6_ONLY));
+
// Set up the WHERE clause value
MYSQL_BIND inbind[1];
memset(inbind, 0, sizeof(inbind));
ConstHostCollection result;
impl_->getHostCollection(MySqlHostDataSourceImpl::GET_HOST_SUBID6,
- inbind, impl_->host_ipv6_exchange_,
- result, false);
+ inbind, host_ipv6_exchange, result, false);
return (result);
}
ConstHostCollection
MySqlHostDataSource::getAllbyHostname(const std::string& hostname) const {
+ thread_local std::shared_ptr<MySqlHostIPv6Exchange> host_ipv46_exchange(
+ std::make_shared<MySqlHostIPv6Exchange>(MySqlHostWithOptionsExchange::DHCP4_AND_DHCP6));
+
// Set up the WHERE clause value
MYSQL_BIND inbind[1];
memset(inbind, 0, sizeof(inbind));
ConstHostCollection result;
impl_->getHostCollection(MySqlHostDataSourceImpl::GET_HOST_HOSTNAME,
- inbind, impl_->host_ipv46_exchange_,
- result, false);
+ inbind, host_ipv46_exchange, result, false);
return (result);
}
ConstHostCollection
MySqlHostDataSource::getAllbyHostname4(const std::string& hostname,
const SubnetID& subnet_id) const {
+ thread_local std::shared_ptr<MySqlHostWithOptionsExchange> host_ipv4_exchange(
+ std::make_shared<MySqlHostWithOptionsExchange>(MySqlHostWithOptionsExchange::DHCP4_ONLY));
+
// Set up the WHERE clause value
MYSQL_BIND inbind[2];
memset(inbind, 0, sizeof(inbind));
ConstHostCollection result;
impl_->getHostCollection(MySqlHostDataSourceImpl::GET_HOST_HOSTNAME_SUBID4,
- inbind, impl_->host_exchange_,
- result, false);
+ inbind, host_ipv4_exchange, result, false);
return (result);
}
ConstHostCollection
MySqlHostDataSource::getAllbyHostname6(const std::string& hostname,
const SubnetID& subnet_id) const {
+ thread_local std::shared_ptr<MySqlHostIPv6Exchange> host_ipv6_exchange(
+ std::make_shared<MySqlHostIPv6Exchange>(MySqlHostWithOptionsExchange::DHCP6_ONLY));
+
// Set up the WHERE clause value
MYSQL_BIND inbind[2];
memset(inbind, 0, sizeof(inbind));
ConstHostCollection result;
impl_->getHostCollection(MySqlHostDataSourceImpl::GET_HOST_HOSTNAME_SUBID6,
- inbind, impl_->host_ipv6_exchange_,
- result, false);
+ inbind, host_ipv6_exchange, result, false);
return (result);
}
size_t& /*source_index*/,
uint64_t lower_host_id,
const HostPageSize& page_size) const {
+ thread_local std::shared_ptr<MySqlHostWithOptionsExchange> host_ipv4_exchange(
+ std::make_shared<MySqlHostWithOptionsExchange>(MySqlHostWithOptionsExchange::DHCP4_ONLY));
+
// Set up the WHERE clause value
MYSQL_BIND inbind[3];
memset(inbind, 0, sizeof(inbind));
ConstHostCollection result;
impl_->getHostCollection(MySqlHostDataSourceImpl::GET_HOST_SUBID4_PAGE,
- inbind, impl_->host_exchange_,
- result, false);
+ inbind, host_ipv4_exchange, result, false);
return (result);
}
size_t& /*source_index*/,
uint64_t lower_host_id,
const HostPageSize& page_size) const {
+ thread_local std::shared_ptr<MySqlHostIPv6Exchange> host_ipv6_exchange(
+ std::make_shared<MySqlHostIPv6Exchange>(MySqlHostWithOptionsExchange::DHCP6_ONLY));
+
// Set up the WHERE clause value
MYSQL_BIND inbind[3];
memset(inbind, 0, sizeof(inbind));
ConstHostCollection result;
impl_->getHostCollection(MySqlHostDataSourceImpl::GET_HOST_SUBID6_PAGE,
- inbind, impl_->host_ipv6_exchange_,
- result, false);
+ inbind, host_ipv6_exchange, result, false);
return (result);
}
ConstHostCollection
MySqlHostDataSource::getAll4(const asiolink::IOAddress& address) const {
+ thread_local std::shared_ptr<MySqlHostWithOptionsExchange> host_ipv4_exchange(
+ std::make_shared<MySqlHostWithOptionsExchange>(MySqlHostWithOptionsExchange::DHCP4_ONLY));
// Set up the WHERE clause value
MYSQL_BIND inbind[1];
inbind[0].is_unsigned = MLM_TRUE;
ConstHostCollection result;
- impl_->getHostCollection(MySqlHostDataSourceImpl::GET_HOST_ADDR, inbind,
- impl_->host_exchange_, result, false);
+ impl_->getHostCollection(MySqlHostDataSourceImpl::GET_HOST_ADDR,
+ inbind, host_ipv4_exchange, result, false);
return (result);
}
const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
const size_t identifier_len) const {
+ thread_local std::shared_ptr<MySqlHostWithOptionsExchange> host_ipv4_exchange(
+ std::make_shared<MySqlHostWithOptionsExchange>(MySqlHostWithOptionsExchange::DHCP4_ONLY));
return (impl_->getHost(subnet_id, identifier_type, identifier_begin,
identifier_len, MySqlHostDataSourceImpl::GET_HOST_SUBID4_DHCPID,
- impl_->host_exchange_));
+ host_ipv4_exchange));
}
ConstHostPtr
MySqlHostDataSource::get4(const SubnetID& subnet_id,
const asiolink::IOAddress& address) const {
- // Check that address is IPv4, not IPv6.
if (!address.isV4()) {
- isc_throw(BadValue, "MySqlHostDataSource::get4(2): wrong address type, "
- "address supplied is not an IPv4 address");
+ isc_throw(BadValue, "MySqlHostDataSource::get4(id, address): "
+ "wrong address type, address supplied is an IPv6 address");
}
+ thread_local std::shared_ptr<MySqlHostWithOptionsExchange> host_ipv4_exchange(
+ std::make_shared<MySqlHostWithOptionsExchange>(MySqlHostWithOptionsExchange::DHCP4_ONLY));
+
// Set up the WHERE clause value
MYSQL_BIND inbind[2];
uint32_t subnet = subnet_id;
ConstHostCollection collection;
impl_->getHostCollection(MySqlHostDataSourceImpl::GET_HOST_SUBID_ADDR,
- inbind, impl_->host_exchange_, collection, true);
+ inbind, host_ipv4_exchange, collection, true);
// Return single record if present, else clear the host.
ConstHostPtr result;
- if (!collection.empty())
+ if (!collection.empty()) {
result = *collection.begin();
+ }
return (result);
}
const Host::IdentifierType& identifier_type,
const uint8_t* identifier_begin,
const size_t identifier_len) const {
+ thread_local std::shared_ptr<MySqlHostIPv6Exchange> host_ipv6_exchange(
+ std::make_shared<MySqlHostIPv6Exchange>(MySqlHostWithOptionsExchange::DHCP6_ONLY));
return (impl_->getHost(subnet_id, identifier_type, identifier_begin,
identifier_len, MySqlHostDataSourceImpl::GET_HOST_SUBID6_DHCPID,
- impl_->host_ipv6_exchange_));
+ host_ipv6_exchange));
}
ConstHostPtr
MySqlHostDataSource::get6(const asiolink::IOAddress& prefix,
const uint8_t prefix_len) const {
- /// @todo: Check that prefix is v6 address, not v4.
+ if (!prefix.isV6()) {
+ isc_throw(BadValue, "MySqlHostDataSource::get6(prefix, prefix_len): "
+ "wrong address type, address supplied is an IPv4 address");
+ }
+
+ thread_local std::shared_ptr<MySqlHostIPv6Exchange> host_ipv6_exchange(
+ std::make_shared<MySqlHostIPv6Exchange>(MySqlHostWithOptionsExchange::DHCP6_ONLY));
// Set up the WHERE clause value
MYSQL_BIND inbind[2];
ConstHostCollection collection;
impl_->getHostCollection(MySqlHostDataSourceImpl::GET_HOST_PREFIX,
- inbind, impl_->host_ipv6_exchange_,
- collection, true);
+ inbind, host_ipv6_exchange, collection, true);
// Return single record if present, else clear the host.
ConstHostPtr result;
ConstHostPtr
MySqlHostDataSource::get6(const SubnetID& subnet_id,
const asiolink::IOAddress& address) const {
+ if (!address.isV6()) {
+ isc_throw(BadValue, "MySqlHostDataSource::get6(id, address): "
+ "wrong address type, address supplied is an IPv4 address");
+ }
+
+ thread_local std::shared_ptr<MySqlHostIPv6Exchange> host_ipv6_exchange(
+ std::make_shared<MySqlHostIPv6Exchange>(MySqlHostWithOptionsExchange::DHCP6_ONLY));
+
// Set up the WHERE clause value
MYSQL_BIND inbind[2];
memset(inbind, 0, sizeof(inbind));
ConstHostCollection collection;
impl_->getHostCollection(MySqlHostDataSourceImpl::GET_HOST_SUBID6_ADDR,
- inbind, impl_->host_ipv6_exchange_,
- collection, true);
+ inbind, host_ipv6_exchange, collection, true);
// Return single record if present, else clear the host.
ConstHostPtr result;
// Miscellaneous database methods.
-std::string MySqlHostDataSource::getName() const {
+std::string
+MySqlHostDataSource::getName() const {
std::string name = "";
try {
name = impl_->conn_.getParameter("name");
return (name);
}
-std::string MySqlHostDataSource::getDescription() const {
+std::string
+MySqlHostDataSource::getDescription() const {
return (std::string("Host data source that stores host information"
"in MySQL database"));
}
{MySqlLeaseMgr::ALL_LEASE6_STATS,
"SELECT subnet_id, lease_type, state, leases as state_count"
- " FROM lease6_stat ORDER BY subnet_id, lease_type, state" },
+ " FROM lease6_stat ORDER BY subnet_id, lease_type, state"},
{MySqlLeaseMgr::SUBNET_LEASE6_STATS,
"SELECT subnet_id, lease_type, state, leases as state_count"
" FROM lease6_stat "
" WHERE subnet_id = ? "
- " ORDER BY lease_type, state" },
+ " ORDER BY lease_type, state"},
{MySqlLeaseMgr::SUBNET_RANGE_LEASE6_STATS,
"SELECT subnet_id, lease_type, state, leases as state_count"
" FROM lease6_stat "
" WHERE subnet_id >= ? and subnet_id <= ? "
- " ORDER BY subnet_id, lease_type, state" }
+ " ORDER BY subnet_id, lease_type, state"}
}
};
bind_[2].buffer_length = client_id_length_;
bind_[2].length = &client_id_length_;
// bind_[2].is_null = &MLM_FALSE; // commented out for performance
- // reasons, see memset() above
+ // reasons, see memset() above
} else {
bind_[2].buffer_type = MYSQL_TYPE_NULL;
// According to http://dev.mysql.com/doc/refman/5.5/en/
// bind_[8].is_null = &MLM_FALSE; // commented out for performance
// reasons, see memset() above
- // state: uint32_t.
+ // state: uint32_t
bind_[9].buffer_type = MYSQL_TYPE_LONG;
bind_[9].buffer = reinterpret_cast<char*>(&lease_->state_);
bind_[9].is_unsigned = MLM_TRUE;
// bind_[8].is_null = &MLM_FALSE; // commented out for performance
// reasons, see memset() above
- // state: uint32_t
+ // state: uint32_t
bind_[9].buffer_type = MYSQL_TYPE_LONG;
bind_[9].buffer = reinterpret_cast<char*>(&state_);
bind_[9].is_unsigned = MLM_TRUE;
bind_[14].is_null = &hwaddr_null_;
}
- // state: uint32_t
+ // state: uint32_t
bind_[15].buffer_type = MYSQL_TYPE_LONG;
bind_[15].buffer = reinterpret_cast<char*>(&lease_->state_);
bind_[15].is_unsigned = MLM_TRUE;
bind_[14].buffer = reinterpret_cast<char*>(&hwaddr_source_);
bind_[14].is_unsigned = MLM_TRUE;
- // state: uint32_t
+ // state: uint32_t
bind_[15].buffer_type = MYSQL_TYPE_LONG;
bind_[15].buffer = reinterpret_cast<char*>(&state_);
bind_[15].is_unsigned = MLM_TRUE;
// MySqlLeaseMgr Constructor and Destructor
-MySqlLeaseMgr::MySqlLeaseMgr(const MySqlConnection::ParameterMap& parameters)
- : conn_(parameters) {
+MySqlLeaseMgr::MySqlLeaseMgr(const MySqlConnection::ParameterMap& parameters) :
+ conn_(parameters) {
// Open the database.
conn_.openDatabase();
MYSQL_SCHEMA_VERSION_MINOR);
std::pair<uint32_t, uint32_t> db_version = getVersion();
if (code_version != db_version) {
- isc_throw(DbOpenError,
- "MySQL schema version mismatch: need version: "
- << code_version.first << "." << code_version.second
- << " found version: " << db_version.first << "."
- << db_version.second);
+ isc_throw(DbOpenError, "MySQL schema version mismatch: need version: "
+ << code_version.first << "." << code_version.second
+ << " found version: " << db_version.first << "."
+ << db_version.second);
}
// Enable autocommit. To avoid a flush to disk on every commit, the global
// Prepare all statements likely to be used.
conn_.prepareStatements(tagged_statements.begin(), tagged_statements.end());
-
- // Create the exchange objects for use in exchanging data between the
- // program and the database.
- exchange4_.reset(new MySqlLease4Exchange());
- exchange6_.reset(new MySqlLease6Exchange());
}
MySqlLeaseMgr::~MySqlLeaseMgr() {
bool
MySqlLeaseMgr::addLease(const Lease4Ptr& lease) {
+ thread_local std::shared_ptr<MySqlLease4Exchange> exchange4(
+ std::make_shared<MySqlLease4Exchange>());
+
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
DHCPSRV_MYSQL_ADD_ADDR4).arg(lease->addr_.toText());
// Create the MYSQL_BIND array for the lease
- std::vector<MYSQL_BIND> bind = exchange4_->createBindForSend(lease);
+ std::vector<MYSQL_BIND> bind = exchange4->createBindForSend(lease);
// ... and drop to common code.
return (addLeaseCommon(INSERT_LEASE4, bind));
bool
MySqlLeaseMgr::addLease(const Lease6Ptr& lease) {
+ thread_local std::shared_ptr<MySqlLease6Exchange> exchange6(
+ std::make_shared<MySqlLease6Exchange>());
+
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
DHCPSRV_MYSQL_ADD_ADDR6).arg(lease->addr_.toText())
.arg(lease->type_);
// Create the MYSQL_BIND array for the lease
- std::vector<MYSQL_BIND> bind = exchange6_->createBindForSend(lease);
+ std::vector<MYSQL_BIND> bind = exchange6->createBindForSend(lease);
// ... and drop to common code.
return (addLeaseCommon(INSERT_LEASE6, bind));
}
}
+void MySqlLeaseMgr::getLeaseCollection(StatementIndex stindex, MYSQL_BIND* bind,
+ Lease4Collection& result) const {
+ thread_local std::shared_ptr<MySqlLease4Exchange> exchange4(
+ std::make_shared<MySqlLease4Exchange>());
+ getLeaseCollection(stindex, bind, exchange4, result);
+}
+
+void MySqlLeaseMgr::getLeaseCollection(StatementIndex stindex, MYSQL_BIND* bind,
+ Lease6Collection& result) const {
+ thread_local std::shared_ptr<MySqlLease6Exchange> exchange6(
+ std::make_shared<MySqlLease6Exchange>());
+ getLeaseCollection(stindex, bind, exchange6, result);
+}
+
void MySqlLeaseMgr::getLease(StatementIndex stindex, MYSQL_BIND* bind,
Lease4Ptr& result) const {
+ thread_local std::shared_ptr<MySqlLease4Exchange> exchange4(
+ std::make_shared<MySqlLease4Exchange>());
+
// Create appropriate collection object and get all leases matching
// the selection criteria. The "single" parameter is true to indicate
// that the called method should throw an exception if multiple
// matching records are found: this particular method is called when only
// one or zero matches is expected.
Lease4Collection collection;
- getLeaseCollection(stindex, bind, exchange4_, collection, true);
+ getLeaseCollection(stindex, bind, exchange4, collection, true);
// Return single record if present, else clear the lease.
if (collection.empty()) {
void MySqlLeaseMgr::getLease(StatementIndex stindex, MYSQL_BIND* bind,
Lease6Ptr& result) const {
+ thread_local std::shared_ptr<MySqlLease6Exchange> exchange6(
+ std::make_shared<MySqlLease6Exchange>());
+
// Create appropriate collection object and get all leases matching
// the selection criteria. The "single" parameter is true to indicate
// that the called method should throw an exception if multiple
// matching records are found: this particular method is called when only
// one or zero matches is expected.
Lease6Collection collection;
- getLeaseCollection(stindex, bind, exchange6_, collection, true);
+ getLeaseCollection(stindex, bind, exchange6, collection, true);
// Return single record if present, else clear the lease.
if (collection.empty()) {
void
MySqlLeaseMgr::updateLease4(const Lease4Ptr& lease) {
+ thread_local std::shared_ptr<MySqlLease4Exchange> exchange4(
+ std::make_shared<MySqlLease4Exchange>());
+
const StatementIndex stindex = UPDATE_LEASE4;
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
DHCPSRV_MYSQL_UPDATE_ADDR4).arg(lease->addr_.toText());
// Create the MYSQL_BIND array for the data being updated
- std::vector<MYSQL_BIND> bind = exchange4_->createBindForSend(lease);
+ std::vector<MYSQL_BIND> bind = exchange4->createBindForSend(lease);
// Set up the WHERE clause and append it to the MYSQL_BIND array
MYSQL_BIND where;
void
MySqlLeaseMgr::updateLease6(const Lease6Ptr& lease) {
+ thread_local std::shared_ptr<MySqlLease6Exchange> exchange6(
+ std::make_shared<MySqlLease6Exchange>());
+
const StatementIndex stindex = UPDATE_LEASE6;
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
.arg(lease->type_);
// Create the MYSQL_BIND array for the data being updated
- std::vector<MYSQL_BIND> bind = exchange6_->createBindForSend(lease);
+ std::vector<MYSQL_BIND> bind = exchange6->createBindForSend(lease);
// Set up the WHERE clause value
MYSQL_BIND where;
const char* version_sql = "SELECT version, minor FROM schema_version";
int status = mysql_stmt_prepare(stmt, version_sql, strlen(version_sql));
if (status != 0) {
+ mysql_stmt_close(stmt);
isc_throw(DbOperationError, "unable to prepare MySQL statement <"
<< version_sql << ">, reason: " << mysql_error(conn_.mysql_));
}
// Execute the prepared statement.
if (mysql_stmt_execute(stmt) != 0) {
+ mysql_stmt_close(stmt);
isc_throw(DbOperationError, "cannot execute schema version query <"
<< version_sql << ">, reason: " << mysql_errno(conn_.mysql_));
}