Commit b8525204 authored by Razvan Becheriu's avatar Razvan Becheriu

[#1040] delete lease only if expire time has not changed

parent 46da5677
......@@ -107,8 +107,8 @@ public:
/// @brief Default constructor.
Parameters()
:addr("::"), query_type(TYPE_ADDR), lease_type(Lease::TYPE_NA),
iaid(0) {
: addr("::"), query_type(TYPE_ADDR), lease_type(Lease::TYPE_NA),
iaid(0) {
}
};
......@@ -303,11 +303,12 @@ public:
///
/// @param parameters parameters extracted from the command.
///
/// @return Address of the lease to be deleted.
/// @return Lease of the lease to be deleted.
///
/// @throw InvalidParameter if the DUID is not found when needed to
/// find the lease or if the query type is by HW address.
/// @throw InvalidOperation if the query type is unknown.
IOAddress getIPv6AddressForDelete(const Parameters& parameters) const;
Lease6Ptr getIPv6LeaseForDelete(const Parameters& parameters) const;
/// @brief Returns a map holding brief information about a lease which
/// failed to be deleted, updated or added.
......@@ -1018,19 +1019,21 @@ int
LeaseCmdsImpl::lease4DelHandler(CalloutHandle& handle) {
Parameters p;
Lease4Ptr lease4;
IOAddress addr(IOAddress::IPV4_ZERO_ADDRESS());
try {
extractCommand(handle);
p = getParameters(false, cmd_args_);
switch (p.query_type) {
case Parameters::TYPE_ADDR: {
// If address was specified explicitly, let's use it as is.
addr = p.addr;
lease4 = LeaseMgrFactory::instance().getLease4(p.addr);
if (!lease4) {
setErrorResponse(handle, "IPv4 lease not found.", CONTROL_RESULT_EMPTY);
return (0);
}
break;
}
case Parameters::TYPE_HWADDR:
case Parameters::TYPE_HWADDR: {
if (!p.hwaddr) {
isc_throw(InvalidParameter, "Program error: Query by hw-address "
"requires hwaddr to be specified");
......@@ -1042,12 +1045,9 @@ LeaseCmdsImpl::lease4DelHandler(CalloutHandle& handle) {
setErrorResponse(handle, "IPv4 lease not found.", CONTROL_RESULT_EMPTY);
return (0);
}
// Found it, can use it as is.
addr = lease4->addr_;
break;
case Parameters::TYPE_CLIENT_ID:
}
case Parameters::TYPE_CLIENT_ID: {
if (!p.client_id) {
isc_throw(InvalidParameter, "Program error: Query by client-id "
"requires client-id to be specified");
......@@ -1059,25 +1059,19 @@ LeaseCmdsImpl::lease4DelHandler(CalloutHandle& handle) {
setErrorResponse(handle, "IPv4 lease not found.", CONTROL_RESULT_EMPTY);
return (0);
}
// Found it, can use it as is.
addr = lease4->addr_;
break;
case Parameters::TYPE_DUID:
}
case Parameters::TYPE_DUID: {
isc_throw(InvalidParameter, "Delete by duid is not allowed in v4.");
break;
}
default: {
isc_throw(InvalidOperation, "Unknown query type: " << static_cast<int>(p.query_type));
break;
}
}
Lease4Ptr lease(new Lease4());
lease->addr_ = addr;
if (LeaseMgrFactory::instance().deleteLease(lease)) {
if (LeaseMgrFactory::instance().deleteLease(lease4)) {
setSuccessResponse(handle, "IPv4 lease deleted.");
} else {
setErrorResponse (handle, "IPv4 lease not found.", CONTROL_RESULT_EMPTY);
......@@ -1122,7 +1116,7 @@ LeaseCmdsImpl::lease6BulkApplyHandler(CalloutHandle& handle) {
// Parse deleted leases without deleting them from the database
// yet. If any of the deleted leases or new leases appears to be
// malformed we can easily rollback.
std::list<std::pair<Parameters, IOAddress> > parsed_deleted_list;
std::list<std::pair<Parameters, Lease6Ptr> > parsed_deleted_list;
if (deleted_leases) {
auto leases_list = deleted_leases->listValue();
......@@ -1130,9 +1124,9 @@ LeaseCmdsImpl::lease6BulkApplyHandler(CalloutHandle& handle) {
for (auto lease_params : leases_list) {
// Parsing the lease may throw and it means that the lease
// information is malformed.
Parameters p = getParameters(true, lease_params);
auto lease_addr = getIPv6AddressForDelete(p);
parsed_deleted_list.push_back(std::make_pair(p, lease_addr));
Parameters p = getParameters(true, lease_params);
auto lease = getIPv6AddressForDelete(p);
parsed_deleted_list.push_back(std::make_pair(p, lease));
}
}
......@@ -1167,17 +1161,14 @@ LeaseCmdsImpl::lease6BulkApplyHandler(CalloutHandle& handle) {
// This part is outside of the try-catch because an exception
// indicates that the command is malformed.
Parameters p = lease_params_pair.first;
auto lease_addr = lease_params_pair.second;
Parameters p = lease_params_pair.first;
auto lease = lease_params_pair.second;
try {
if (!lease_addr.isV6Zero()) {
if (lease) {
// This may throw if the lease couldn't be deleted for
// any reason, but we still want to proceed with other
// leases.
Lease6Ptr lease(new Lease6());
lease->addr_ = lease_addr;
if (LeaseMgrFactory::instance().deleteLease(lease)) {
++success_count;
......@@ -1292,16 +1283,21 @@ LeaseCmdsImpl::lease6DelHandler(CalloutHandle& handle) {
switch (p.query_type) {
case Parameters::TYPE_ADDR: {
// If address was specified explicitly, let's use it as is.
addr = p.addr;
// Let's see if there's such a lease at all.
lease6 = LeaseMgrFactory::instance().getLease6(p.lease_type, p.addr);
if (!lease6) {
setErrorResponse(handle, "IPv6 lease not found.", CONTROL_RESULT_EMPTY);
return (0);
}
break;
}
case Parameters::TYPE_HWADDR:
case Parameters::TYPE_HWADDR: {
isc_throw(InvalidParameter, "Delete by hw-address is not allowed in v6.");
break;
case Parameters::TYPE_DUID:
}
case Parameters::TYPE_DUID: {
if (!p.duid) {
isc_throw(InvalidParameter, "Program error: Query by duid "
"requires duid to be specified");
......@@ -1314,21 +1310,15 @@ LeaseCmdsImpl::lease6DelHandler(CalloutHandle& handle) {
setErrorResponse(handle, "IPv6 lease not found.", CONTROL_RESULT_EMPTY);
return (0);
}
// Found it, can use it as is.
addr = lease6->addr_;
break;
}
default: {
isc_throw(InvalidOperation, "Unknown query type: " << static_cast<int>(p.query_type));
break;
}
}
Lease6Ptr lease(new Lease6());
lease->addr_ = addr;
if (LeaseMgrFactory::instance().deleteLease(lease)) {
if (LeaseMgrFactory::instance().deleteLease(lease6)) {
setSuccessResponse(handle, "IPv6 lease deleted.");
} else {
setErrorResponse (handle, "IPv6 lease not found.", CONTROL_RESULT_EMPTY);
......@@ -1509,23 +1499,28 @@ LeaseCmdsImpl::lease6WipeHandler(CalloutHandle& handle) {
return (0);
}
IOAddress
LeaseCmdsImpl::getIPv6AddressForDelete(const Parameters& parameters) const {
IOAddress addr = IOAddress::IPV6_ZERO_ADDRESS();
Lease6Ptr
LeaseCmdsImpl::getIPv6LeaseForDelete(const Parameters& parameters) const {
Lease6Ptr lease6;
switch (parameters.query_type) {
case Parameters::TYPE_ADDR: {
// If address was specified explicitly, let's use it as is.
addr = parameters.addr;
// Let's see if there's such a lease at all.
lease6 = LeaseMgrFactory::instance().getLease6(parameters.lease_type,
parameters.addr);
if (!lease6) {
lease6.reset(new Lease6());
lease6->addr_ = parameters.addr;
}
break;
}
case Parameters::TYPE_HWADDR:
case Parameters::TYPE_HWADDR: {
isc_throw(InvalidParameter, "Delete by hw-address is not allowed in v6.");
break;
case Parameters::TYPE_DUID:
}
case Parameters::TYPE_DUID: {
if (!parameters.duid) {
isc_throw(InvalidParameter, "Program error: Query by duid "
"requires duid to be specified");
......@@ -1536,18 +1531,14 @@ LeaseCmdsImpl::getIPv6AddressForDelete(const Parameters& parameters) const {
*parameters.duid,
parameters.iaid,
parameters.subnet_id);
if (lease6) {
addr = lease6->addr_;
}
break;
break;
}
default:
isc_throw(InvalidOperation, "Unknown query type: "
<< static_cast<int>(parameters.query_type));
}
return (addr);
return (lease6);
}
ElementPtr
......
......@@ -30,6 +30,7 @@
#include <hooks/hooks_manager.h>
#include <boost/foreach.hpp>
#include <boost/make_shared.hpp>
#include <algorithm>
#include <cstring>
......@@ -3674,8 +3675,8 @@ AllocEngine::renewLease4(const Lease4Ptr& lease,
// (the lease returned points directly to the lease4 object in the database)
// We'll need it if we want to skip update (i.e. roll back renewal)
/// @todo: remove this?
Lease4 old_values = *lease;
ctx.old_lease_.reset(new Lease4(old_values));
Lease4Ptr old_values = boost::make_shared<Lease4>(*lease);
ctx.old_lease_.reset(new Lease4(*old_values));
// Update the lease with the information from the context.
updateLease4Information(lease, ctx);
......@@ -3686,7 +3687,6 @@ AllocEngine::renewLease4(const Lease4Ptr& lease,
// involves execution of hooks and DNS update.
if (ctx.old_lease_->expired()) {
reclaimExpiredLease(ctx.old_lease_, ctx.callout_handle_);
}
lease->state_ = Lease::STATE_DEFAULT;
......@@ -3756,7 +3756,7 @@ AllocEngine::renewLease4(const Lease4Ptr& lease,
if (skip) {
// Rollback changes (really useful only for memfile)
/// @todo: remove this?
*lease = old_values;
*lease = *old_values;
}
return (lease);
......
......@@ -26,10 +26,11 @@
#include <dhcp/hwaddr.h>
#include <asiolink/io_address.h>
#include <boost/make_shared.hpp>
using namespace isc::data;
using namespace isc::db;
using isc::asiolink::IOAddress;
using namespace isc::asiolink;
namespace isc {
namespace dhcp {
......@@ -46,11 +47,12 @@ static constexpr char NULL_USER_CONTEXT[] = "";
/// base to both of them, containing some common methods.
class CqlLeaseExchange : public CqlExchange {
public:
/// @brief Constructor
///
/// @param connection already open Cassandra connection.
CqlLeaseExchange(const CqlConnection &connection)
: connection_(connection), valid_lifetime_(0), expire_(0),
: connection_(connection), valid_lifetime_(0), expire_(0), old_expire_(0),
subnet_id_(0), fqdn_fwd_(cass_false), fqdn_rev_(cass_false),
state_(0), user_context_(NULL_USER_CONTEXT) {
}
......@@ -75,6 +77,7 @@ public:
virtual boost::any retrieve() override = 0;
protected:
/// @brief Database connection
const CqlConnection &connection_;
......@@ -87,6 +90,9 @@ protected:
/// @brief Lease expiry time
cass_int64_t expire_;
/// @brief Expiration time of lease before update
cass_int64_t old_expire_;
/// @brief Subnet identifier
cass_int32_t subnet_id_;
......@@ -120,6 +126,7 @@ protected:
/// in all CqlLeaseMgr::xxx4() calls where it is used.
class CqlLease4Exchange : public CqlLeaseExchange {
public:
/// @brief Constructor
///
/// The initialization of the variables here is only to satisfy
......@@ -236,6 +243,7 @@ public:
/// @}
private:
// Pointer to lease object
Lease4Ptr lease_;
// IPv4 address
......@@ -270,7 +278,8 @@ StatementMap CqlLease4Exchange::tagged_statements_{
") VALUES ( "
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? "
") "
"IF NOT EXISTS "}},
"IF NOT EXISTS "
}},
// Updates existing IPv4 lease
{UPDATE_LEASE4,
......@@ -287,14 +296,16 @@ StatementMap CqlLease4Exchange::tagged_statements_{
"state = ?, "
"user_context = ? "
"WHERE address = ? "
"IF EXISTS "}},
"IF expire = ? "
}},
// Deletes existing IPv4 lease
{DELETE_LEASE4,
{DELETE_LEASE4,
"DELETE FROM lease4 "
"WHERE address = ? "
"IF EXISTS "}},
"IF expire = ? "
}},
// Gets up to a certain number of expired IPv4 leases
{GET_LEASE4_EXPIRE,
......@@ -307,7 +318,8 @@ StatementMap CqlLease4Exchange::tagged_statements_{
"AND valid_lifetime < 4294967295 "
"AND expire < ? "
"LIMIT ? "
"ALLOW FILTERING "}},
"ALLOW FILTERING "
}},
// Gets an IPv4 lease(s)
{GET_LEASE4,
......@@ -315,7 +327,8 @@ StatementMap CqlLease4Exchange::tagged_statements_{
"SELECT "
"address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, state, user_context "
"FROM lease4 "}},
"FROM lease4 "
}},
// Gets an IPv4 lease with specified IPv4 address
{GET_LEASE4_ADDR,
......@@ -324,7 +337,8 @@ StatementMap CqlLease4Exchange::tagged_statements_{
"address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
"fqdn_fwd, fqdn_rev, hostname, state, user_context "
"FROM lease4 "
"WHERE address = ? "}},
"WHERE address = ? "
}},
// Gets an IPv4 lease(s) with specified client-id
{GET_LEASE4_CLIENTID,
......@@ -334,7 +348,8 @@ StatementMap CqlLease4Exchange::tagged_statements_{
"fqdn_fwd, fqdn_rev, hostname, state, user_context "
"FROM lease4 "
"WHERE client_id = ? "
"ALLOW FILTERING "}},
"ALLOW FILTERING "
}},
// Gets an IPv4 lease with specified client-id and subnet-id
{GET_LEASE4_CLIENTID_SUBID,
......@@ -345,7 +360,8 @@ StatementMap CqlLease4Exchange::tagged_statements_{
"FROM lease4 "
"WHERE client_id = ? "
"AND subnet_id = ? "
"ALLOW FILTERING "}},
"ALLOW FILTERING "
}},
// Gets all IPv4 leases with specified hardware address
{GET_LEASE4_HWADDR,
......@@ -355,7 +371,8 @@ StatementMap CqlLease4Exchange::tagged_statements_{
"fqdn_fwd, fqdn_rev, hostname, state, user_context "
"FROM lease4 "
"WHERE hwaddr = ? "
"ALLOW FILTERING "}},
"ALLOW FILTERING "
}},
// Gets an IPv4 lease with specified hardware addr and subnet-id
{GET_LEASE4_HWADDR_SUBID,
......@@ -366,7 +383,8 @@ StatementMap CqlLease4Exchange::tagged_statements_{
"FROM lease4 "
"WHERE hwaddr = ? "
"AND subnet_id = ? "
"ALLOW FILTERING "}},
"ALLOW FILTERING "
}},
// Get range of lease4 from first lease with a limit (paging)
{GET_LEASE4_LIMIT,
......@@ -376,7 +394,8 @@ StatementMap CqlLease4Exchange::tagged_statements_{
"fqdn_fwd, fqdn_rev, hostname, state, user_context "
"FROM lease4 "
"LIMIT ? "
"ALLOW FILTERING "}},
"ALLOW FILTERING "
}},
// Get range of lease4 from address with a limit (paging)
{GET_LEASE4_PAGE,
......@@ -387,7 +406,8 @@ StatementMap CqlLease4Exchange::tagged_statements_{
"FROM lease4 "
"WHERE TOKEN(address) > TOKEN(?) "
"LIMIT ? "
"ALLOW FILTERING "}},
"ALLOW FILTERING "
}},
// Gets an IPv4 lease(s) with specified subnet-id
{GET_LEASE4_SUBID,
......@@ -407,7 +427,8 @@ StatementMap CqlLease4Exchange::tagged_statements_{
"fqdn_fwd, fqdn_rev, hostname, state, user_context "
"FROM lease4 "
"WHERE hostname = ? "
"ALLOW FILTERING "}}
"ALLOW FILTERING "
}}
};
CqlLease4Exchange::CqlLease4Exchange(const CqlConnection &connection)
......@@ -462,8 +483,7 @@ CqlLease4Exchange::createBindForInsert(const Lease4Ptr &lease, AnyArray &data) {
// For convenience for external tools, this is converted to lease
// expiry time (expire). The relationship is given by:
// expire = cltt_ + valid_lft_
CqlExchange::convertToDatabaseTime(lease_->cltt_, lease_->valid_lft_,
expire_);
CqlExchange::convertToDatabaseTime(lease_->cltt_, lease_->valid_lft_, expire_);
// subnet_id: int
subnet_id_ = static_cast<cass_int32_t>(lease_->subnet_id_);
......@@ -565,8 +585,7 @@ CqlLease4Exchange::createBindForUpdate(const Lease4Ptr &lease, AnyArray &data,
// For convenience for external tools, this is converted to lease
// expiry time (expire). The relationship is given by:
// expire = cltt_ + valid_lft_
CqlExchange::convertToDatabaseTime(lease_->cltt_, lease_->valid_lft_,
expire_);
CqlExchange::convertToDatabaseTime(lease_->cltt_, lease_->valid_lft_, expire_);
// subnet_id: int
subnet_id_ = static_cast<cass_int32_t>(lease_->subnet_id_);
......@@ -612,6 +631,8 @@ CqlLease4Exchange::createBindForUpdate(const Lease4Ptr &lease, AnyArray &data,
data.add(&user_context_);
data.add(&address_);
CqlExchange::convertToDatabaseTime(lease_->old_cltt_, lease_->old_valid_lft_, old_expire_);
data.add(&old_expire_);
} catch (const Exception &ex) {
isc_throw(DbOperationError,
"CqlLease4Exchange::createBindUpdate(): "
......@@ -640,6 +661,8 @@ CqlLease4Exchange::createBindForDelete(const Lease4Ptr &lease, AnyArray &data,
data.clear();
data.add(&address_);
CqlExchange::convertToDatabaseTime(lease_->old_cltt_, lease_->old_valid_lft_, old_expire_);
data.add(&old_expire_);
} catch (const Exception &ex) {
isc_throw(DbOperationError,
"CqlLease4Exchange::createBindForDelete(): "
......@@ -650,7 +673,6 @@ CqlLease4Exchange::createBindForDelete(const Lease4Ptr &lease, AnyArray &data,
void
CqlLease4Exchange::createBindForSelect(AnyArray &data, StatementTag /* unused */) {
// Start with a fresh array.
data.clear();
......@@ -718,7 +740,7 @@ CqlLease4Exchange::retrieve() {
time_t cltt = 0;
CqlExchange::convertFromDatabaseTime(expire_, valid_lifetime_, cltt);
HWAddrPtr hwaddr(new HWAddr(hwaddr_, HTYPE_ETHER));
HWAddrPtr hwaddr = boost::make_shared<HWAddr>(hwaddr_, HTYPE_ETHER);
uint32_t addr4 = static_cast<uint32_t>(address_);
......@@ -731,10 +753,10 @@ CqlLease4Exchange::retrieve() {
}
}
Lease4Ptr result(new Lease4(addr4, hwaddr, client_id_.data(),
client_id_.size(), valid_lifetime_,
cltt, subnet_id_, fqdn_fwd_, fqdn_rev_,
hostname_));
Lease4Ptr result(boost::make_shared<Lease4>(addr4, hwaddr, client_id_.data(),
client_id_.size(), valid_lifetime_,
cltt, subnet_id_, fqdn_fwd_, fqdn_rev_,
hostname_));
result->state_ = state_;
......@@ -809,8 +831,7 @@ CqlLease4Exchange::getExpiredLeases(const size_t &max_leases,
// Retrieve leases from the database.
Lease4Collection temp_collection;
getLeaseCollection(CqlLease4Exchange::GET_LEASE4_EXPIRE, data,
temp_collection);
getLeaseCollection(CqlLease4Exchange::GET_LEASE4_EXPIRE, data, temp_collection);
for (Lease4Ptr &lease : temp_collection) {
expired_leases.push_back(lease);
......@@ -832,6 +853,7 @@ CqlLease4Exchange::getExpiredLeases(const size_t &max_leases,
/// in all CqlLeaseMgr::xxx6() calls where it is used.
class CqlLease6Exchange : public CqlLeaseExchange {
public:
/// @brief Constructor
///
/// The initialization of the variables here is only to satisfy
......@@ -931,6 +953,7 @@ public:
// @}
private:
/// @brief Lease
Lease6Ptr lease_;
......@@ -983,7 +1006,8 @@ StatementMap CqlLease6Exchange::tagged_statements_ = {
") VALUES ("
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?"
") "
"IF NOT EXISTS "}},
"IF NOT EXISTS "
}},
// Updates existing IPv6 lease
{UPDATE_LEASE6,
......@@ -1006,14 +1030,16 @@ StatementMap CqlLease6Exchange::tagged_statements_ = {
"state = ?, "
"user_context = ? "
"WHERE address = ? "
"IF EXISTS "}},
"IF expire = ? "
}},
// Deletes existing IPv6 lease
{DELETE_LEASE6,
{DELETE_LEASE6,
"DELETE FROM lease6 "
"WHERE address = ? "
"IF EXISTS "}},
"IF expire = ? "
}},
// Gets up to a certain number of expired IPv6 leases
{GET_LEASE6_EXPIRE,
......@@ -1027,7 +1053,8 @@ StatementMap CqlLease6Exchange::tagged_statements_ = {
"AND valid_lifetime < 4294967295 "
"AND expire < ? "
"LIMIT ? "
"ALLOW FILTERING "}},
"ALLOW FILTERING "
}},
// Gets an IPv6 lease with specified IPv6 address
{GET_LEASE6_ADDR,
......@@ -1039,7 +1066,8 @@ StatementMap CqlLease6Exchange::tagged_statements_ = {
"FROM lease6 "
"WHERE address = ? "
"AND lease_type = ? "
"ALLOW FILTERING "}},
"ALLOW FILTERING "
}},
// Gets an IPv6 lease with specified duid
{GET_LEASE6_DUID,
......@@ -1050,7 +1078,8 @@ StatementMap CqlLease6Exchange::tagged_statements_ = {
"hwaddr_source, state, user_context "
"FROM lease6 "
"WHERE duid = ? "
"ALLOW FILTERING "}},
"ALLOW FILTERING "
}},
// Gets an IPv6 lease(s) with specified duid and iaid
{GET_LEASE6_DUID_IAID,
......@@ -1062,7 +1091,8 @@ StatementMap CqlLease6Exchange::tagged_statements_ = {
"FROM lease6 "
"WHERE duid = ? AND iaid = ? "
"AND lease_type = ? "
"ALLOW FILTERING "}},
"ALLOW FILTERING "
}},
// Gets an IPv6 lease with specified duid, iaid and subnet-id
{GET_LEASE6_DUID_IAID_SUBID,
......@@ -1075,7 +1105,8 @@ StatementMap CqlLease6Exchange::tagged_statements_ = {
"WHERE duid = ? AND iaid = ? "
"AND lease_type = ? "
"AND subnet_id = ? "
"ALLOW FILTERING "}},
"ALLOW FILTERING "
}},
// Get range of IPv6 leases from first lease with a limit (paging)
{GET_LEASE6_LIMIT,
......@@ -1086,7 +1117,8 @@ StatementMap CqlLease6Exchange::tagged_statements_ = {
"hwaddr_source, state, user_context "
"FROM lease6 "
"LIMIT ? "
"ALLOW FILTERING "}},
"ALLOW FILTERING "
}},
// Get range of IPv6 leases from address with a limit (paging)
{GET_LEASE6_PAGE,
......@@ -1098,7 +1130,8 @@ StatementMap CqlLease6Exchange::tagged_statements_ = {
"FROM lease6 "
"WHERE TOKEN(address) > TOKEN(?) "
"LIMIT ? "
"ALLOW FILTERING "}},
"ALLOW FILTERING "
}},
// Gets an IPv6 lease(s) with specified hostname
{GET_LEASE6_HOSTNAME,
......@@ -1109,9 +1142,8 @@ StatementMap CqlLease6Exchange::tagged_statements_ = {
"hwaddr_source, state, user_context "
"FROM lease6 "
"WHERE hostname = ? "
"ALLOW FILTERING "}},
"ALLOW FILTERING "
}}
};
CqlLease6Exchange::CqlLease6Exchange(const CqlConnection &connection)
......@@ -1282,8 +1314,7 @@ CqlLease6Exchange::createBindForUpdate(const Lease6Ptr &lease, AnyArray &data,
// For convenience for external tools, this is converted to lease
// expiry time (expire). The relationship is given by:
// expire = cltt_ + valid_lft_
CqlExchange::convertToDatabaseTime(lease_->cltt_, lease_->valid_lft_,
expire_);
CqlExchange::convertToDatabaseTime(lease_->cltt_, lease_->valid_lft_, expire_);
// subnet_id: int
subnet_id_ = static_cast<cass_int32_t>(lease_->subnet_id_);
......@@ -1386,6 +1417,8 @@ CqlLease6Exchange::createBindForUpdate(const Lease6Ptr &lease, AnyArray &data,
data.add(&user_context_);
data.add(&address_);
CqlExchange::convertToDatabaseTime(lease_->old_cltt_, lease_->old_valid_lft_, old_expire_);
data.add(&old_expire_);
} catch (const Exception &ex) {
isc_throw(DbOperationError,
"CqlLease6Exchange::createBindForUpdate(): "
......@@ -1420,6 +1453,8 @@ CqlLease6Exchange::createBindForDelete(const Lease6Ptr &lease, AnyArray &data,
data.clear();
data.add(&address_);
CqlExchange::convertToDatabaseTime(lease_->old_cltt_, lease_->old_valid_lft_, old_expire_);
data.add(&old_expire_);
} catch (const Exception &ex) {
isc_throw(DbOperationError,
"CqlLease6Exchange::createBindForDelete(): "
......@@ -1430,7 +1465,6 @@ CqlLease6Exchange::createBindForDelete(const Lease6Ptr &lease, AnyArray &data,
void
CqlLease6Exchange::createBindForSelect(AnyArray &data, StatementTag /* unused */) {
// Start with a fresh array.
data.clear();
......@@ -1527,11 +1561,11 @@ CqlLease6Exchange::retrieve() {
IOAddress addr(address_);
DuidPtr duid(new DUID(duid_));
DuidPtr duid(boost::make_shared<DUID>(duid_));
HWAddrPtr hwaddr;
if (hwaddr_.size()) {
hwaddr.reset(new HWAddr(hwaddr_, hwtype_));
hwaddr = boost::make_shared<HWAddr>(hwaddr_, hwtype_);
hwaddr->source_ = hwaddr_source_;
}
......@@ -1546,14 +1580,15 @@ CqlLease6Exchange::retrieve() {
// Create the lease and set the cltt (after converting from the
// expire time retrieved from the database).
Lease6Ptr result(new Lease6(static_cast<Lease::Type>(lease_type_), addr, duid,
iaid_, pref_lifetime_, valid_lifetime_,
subnet_id_, fqdn_fwd_, fqdn_rev_, hostname_,
hwaddr, prefix_len_));
Lease6Ptr result(boost::make_shared<Lease6>(static_cast<Lease::Type>(lease_type_), addr, duid,
iaid_, pref_lifetime_, valid_lifetime_,
subnet_id_, fqdn_fwd_, fqdn_rev_, hostname_,
hwaddr, prefix_len_));
time_t cltt = 0;
CqlExchange::convertFromDatabaseTime(expire_, valid_lifetime_, cltt);
result->cltt_ = cltt;
result->old_cltt_ = cltt;
result->state_ = state_;
......@@ -1629,8 +1664,7 @@ CqlLease6Exchange::getExpiredLeases(const size_t &max_leases,
// Retrieve leases from the database.
Lease6Collection temp_collection;
getLeaseCollection(CqlLease6Exchange::GET_LEASE6_EXPIRE, data,
temp_collection);
getLeaseCollection(CqlLease6Exchange::GET_LEASE6_EXPIRE, data, temp_collection);
for (Lease6Ptr &lease : temp_collection) {
expired_leases.push_back(lease);
......@@ -1645,6 +1679,7 @@ CqlLease6Exchange::getExpiredLeases(const size_t &max_leases,
///
class CqlLeaseStatsQuery : public LeaseStatsQuery {
public:
/// @brief Constructor to query for all subnets' stats
///
/// The query created will return statistics for all subnets
......@@ -1781,6 +1816,7 @@ public:
static StatementMap tagged_statements_;
private:
/// @brief Database connection to use to execute the query