mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 14:05:33 +00:00
[3965] deleteExpiredReclaimed returns number of deleted leases.
This commit is contained in:
@@ -369,14 +369,18 @@ public:
|
||||
/// @param secs Number of seconds since expiration of leases before
|
||||
/// they can be removed. Leases which have expired later than this
|
||||
/// time will not be deleted.
|
||||
virtual void deleteExpiredReclaimedLeases4(const uint32_t secs) = 0;
|
||||
///
|
||||
/// @return Number of leases deleted.
|
||||
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs) = 0;
|
||||
|
||||
/// @brief Deletes all expired and reclaimed DHCPv6 leases.
|
||||
///
|
||||
/// @param secs Number of seconds since expiration of leases before
|
||||
/// they can be removed. Leases which have expired later than this
|
||||
/// time will not be deleted.
|
||||
virtual void deleteExpiredReclaimedLeases6(const uint32_t secs) = 0;
|
||||
///
|
||||
/// @return Number of leases deleted.
|
||||
virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs) = 0;
|
||||
|
||||
/// @brief Return backend type
|
||||
///
|
||||
|
@@ -646,27 +646,29 @@ Memfile_LeaseMgr::deleteLease(const isc::asiolink::IOAddress& addr) {
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
uint64_t
|
||||
Memfile_LeaseMgr::deleteExpiredReclaimedLeases4(const uint32_t secs) {
|
||||
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
|
||||
DHCPSRV_MEMFILE_DELETE_EXPIRED_RECLAIMED4)
|
||||
.arg(secs);
|
||||
deleteExpiredReclaimedLeases<Lease4StorageExpirationIndex, Lease4>(secs, V4, storage4_,
|
||||
lease_file4_);
|
||||
return (deleteExpiredReclaimedLeases<
|
||||
Lease4StorageExpirationIndex, Lease4
|
||||
>(secs, V4, storage4_, lease_file4_));
|
||||
}
|
||||
|
||||
void
|
||||
uint64_t
|
||||
Memfile_LeaseMgr::deleteExpiredReclaimedLeases6(const uint32_t secs) {
|
||||
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
|
||||
DHCPSRV_MEMFILE_DELETE_EXPIRED_RECLAIMED6)
|
||||
.arg(secs);
|
||||
deleteExpiredReclaimedLeases<Lease6StorageExpirationIndex, Lease6>(secs, V6, storage6_,
|
||||
lease_file6_);
|
||||
return (deleteExpiredReclaimedLeases<
|
||||
Lease6StorageExpirationIndex, Lease6
|
||||
>(secs, V6, storage6_, lease_file6_));
|
||||
}
|
||||
|
||||
template<typename IndexType, typename LeaseType, typename StorageType,
|
||||
typename LeaseFileType>
|
||||
void
|
||||
uint64_t
|
||||
Memfile_LeaseMgr::deleteExpiredReclaimedLeases(const uint32_t secs,
|
||||
const Universe& universe,
|
||||
StorageType& storage,
|
||||
@@ -722,6 +724,8 @@ Memfile_LeaseMgr::deleteExpiredReclaimedLeases(const uint32_t secs,
|
||||
// Erase leases from memory.
|
||||
index.erase(lower_limit, upper_limit);
|
||||
}
|
||||
// Return number of leases deleted.
|
||||
return (num_leases);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -319,14 +319,18 @@ public:
|
||||
/// @param secs Number of seconds since expiration of leases before
|
||||
/// they can be removed. Leases which have expired later than this
|
||||
/// time will not be deleted.
|
||||
virtual void deleteExpiredReclaimedLeases4(const uint32_t secs);
|
||||
///
|
||||
/// @return Number of leases deleted.
|
||||
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs);
|
||||
|
||||
/// @brief Deletes all expired-reclaimed DHCPv6 leases.
|
||||
///
|
||||
/// @param secs Number of seconds since expiration of leases before
|
||||
/// they can be removed. Leases which have expired later than this
|
||||
/// time will not be deleted.
|
||||
virtual void deleteExpiredReclaimedLeases6(const uint32_t secs);
|
||||
///
|
||||
/// @return Number of leases deleted.
|
||||
virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs);
|
||||
|
||||
private:
|
||||
|
||||
@@ -346,6 +350,8 @@ private:
|
||||
/// @param lease_file Reference to a DHCPv4 or DHCPv6 lease file
|
||||
/// instance where leases should be marked as deleted.
|
||||
///
|
||||
/// @return Number of leases deleted.
|
||||
///
|
||||
/// @tparam IndexType Index type to be used to search for the
|
||||
/// expired-reclaimed leases, i.e.
|
||||
/// @c Lease4StorageExpirationIndex or @c Lease6StorageExpirationIndex.
|
||||
@@ -356,10 +362,10 @@ private:
|
||||
/// DHCPv6 lease file type.
|
||||
template<typename IndexType, typename LeaseType, typename StorageType,
|
||||
typename LeaseFileType>
|
||||
void deleteExpiredReclaimedLeases(const uint32_t secs,
|
||||
const Universe& universe,
|
||||
StorageType& storage,
|
||||
LeaseFileType& lease_file) const;
|
||||
uint64_t deleteExpiredReclaimedLeases(const uint32_t secs,
|
||||
const Universe& universe,
|
||||
StorageType& storage,
|
||||
LeaseFileType& lease_file) const;
|
||||
|
||||
public:
|
||||
|
||||
|
@@ -2086,13 +2086,13 @@ MySqlLeaseMgr::deleteLease(const isc::asiolink::IOAddress& addr) {
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
uint64_t
|
||||
MySqlLeaseMgr::deleteExpiredReclaimedLeases4(const uint32_t) {
|
||||
isc_throw(NotImplemented, "MySqlLeaseMgr::deleteExpiredReclaimedLeases4"
|
||||
" is not implemented");
|
||||
}
|
||||
|
||||
void
|
||||
uint64_t
|
||||
MySqlLeaseMgr::deleteExpiredReclaimedLeases6(const uint32_t) {
|
||||
isc_throw(NotImplemented, "MySqlLeaseMgr::deleteExpiredReclaimedLeases6"
|
||||
" is not implemented");
|
||||
|
@@ -386,14 +386,18 @@ public:
|
||||
/// @param secs Number of seconds since expiration of leases before
|
||||
/// they can be removed. Leases which have expired later than this
|
||||
/// time will not be deleted.
|
||||
virtual void deleteExpiredReclaimedLeases4(const uint32_t secs);
|
||||
///
|
||||
/// @return Number of leases deleted.
|
||||
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs);
|
||||
|
||||
/// @brief Deletes all expired-reclaimed DHCPv6 leases.
|
||||
///
|
||||
/// @param secs Number of seconds since expiration of leases before
|
||||
/// they can be removed. Leases which have expired later than this
|
||||
/// time will not be deleted.
|
||||
virtual void deleteExpiredReclaimedLeases6(const uint32_t secs);
|
||||
///
|
||||
/// @return Number of leases deleted.
|
||||
virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs);
|
||||
|
||||
/// @brief Return backend type
|
||||
///
|
||||
|
@@ -1507,13 +1507,13 @@ PgSqlLeaseMgr::deleteLease(const isc::asiolink::IOAddress& addr) {
|
||||
return (deleteLeaseCommon(DELETE_LEASE6, bind_array));
|
||||
}
|
||||
|
||||
void
|
||||
uint64_t
|
||||
PgSqlLeaseMgr::deleteExpiredReclaimedLeases4(const uint32_t) {
|
||||
isc_throw(NotImplemented, "PgSqlLeaseMgr::deleteExpiredReclaimedLeases4"
|
||||
" is not implemented");
|
||||
}
|
||||
|
||||
void
|
||||
uint64_t
|
||||
PgSqlLeaseMgr::deleteExpiredReclaimedLeases6(const uint32_t) {
|
||||
isc_throw(NotImplemented, "PgSqlLeaseMgr::deleteExpiredReclaimedLeases6"
|
||||
" is not implemented");
|
||||
|
@@ -391,14 +391,18 @@ public:
|
||||
/// @param secs Number of seconds since expiration of leases before
|
||||
/// they can be removed. Leases which have expired later than this
|
||||
/// time will not be deleted.
|
||||
virtual void deleteExpiredReclaimedLeases4(const uint32_t secs);
|
||||
///
|
||||
/// @return Number of leases deleted.
|
||||
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t secs);
|
||||
|
||||
/// @brief Deletes all expired-reclaimed DHCPv6 leases.
|
||||
///
|
||||
/// @param secs Number of seconds since expiration of leases before
|
||||
/// they can be removed. Leases which have expired later than this
|
||||
/// time will not be deleted.
|
||||
virtual void deleteExpiredReclaimedLeases6(const uint32_t secs);
|
||||
///
|
||||
/// @return Number of leases deleted.
|
||||
virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t secs);
|
||||
|
||||
/// @brief Return backend type
|
||||
///
|
||||
|
@@ -1924,7 +1924,11 @@ GenericLeaseMgrTest::testDeleteExpiredReclaimedLeases4() {
|
||||
|
||||
// Delete expired and reclaimed leases which have expired earlier than
|
||||
// 15 seconds ago. This should affect leases with index 2, 3, 4 etc.
|
||||
ASSERT_NO_THROW(lmptr_->deleteExpiredReclaimedLeases4(lease_affinity_time));
|
||||
uint64_t deleted_num;
|
||||
uint64_t should_delete_num = 0;
|
||||
ASSERT_NO_THROW(
|
||||
deleted_num = lmptr_->deleteExpiredReclaimedLeases4(lease_affinity_time)
|
||||
);
|
||||
|
||||
for (size_t i = 0; i < leases.size(); ++i) {
|
||||
// Obtain lease from the server.
|
||||
@@ -1936,6 +1940,7 @@ GenericLeaseMgrTest::testDeleteExpiredReclaimedLeases4() {
|
||||
((leases[i]->getExpirationTime() + lease_affinity_time) < current_time)) {
|
||||
EXPECT_FALSE(lease) << "The following lease should have been"
|
||||
" deleted: " << leases[i]->toText();
|
||||
++should_delete_num;
|
||||
|
||||
} else {
|
||||
// If the lease is not reclaimed or it has expired less than
|
||||
@@ -1944,10 +1949,16 @@ GenericLeaseMgrTest::testDeleteExpiredReclaimedLeases4() {
|
||||
" deleted: " << leases[i]->toText();
|
||||
}
|
||||
}
|
||||
// Check that the number of leases deleted is correct.
|
||||
EXPECT_EQ(deleted_num, should_delete_num);
|
||||
|
||||
// Make sure we can make another attempt, when there are no more leases
|
||||
// to be deleted.
|
||||
ASSERT_NO_THROW(lmptr_->deleteExpiredReclaimedLeases4(lease_affinity_time));
|
||||
ASSERT_NO_THROW(
|
||||
deleted_num = lmptr_->deleteExpiredReclaimedLeases4(lease_affinity_time)
|
||||
);
|
||||
// No lease should have been deleted.
|
||||
EXPECT_EQ(0, deleted_num);
|
||||
|
||||
// Reopen the database. This to ensure that the leases have been deleted
|
||||
// from the persistent storage.
|
||||
@@ -2013,7 +2024,11 @@ GenericLeaseMgrTest::testDeleteExpiredReclaimedLeases6() {
|
||||
|
||||
// Delete expired and reclaimed leases which have expired earlier than
|
||||
// 15 seconds ago. This should affect leases with index 2, 3, 4 etc.
|
||||
ASSERT_NO_THROW(lmptr_->deleteExpiredReclaimedLeases6(lease_affinity_time));
|
||||
uint64_t deleted_num;
|
||||
uint64_t should_delete_num = 0;
|
||||
ASSERT_NO_THROW(
|
||||
deleted_num = lmptr_->deleteExpiredReclaimedLeases6(lease_affinity_time)
|
||||
);
|
||||
|
||||
for (size_t i = 0; i < leases.size(); ++i) {
|
||||
// Obtain lease from the server.
|
||||
@@ -2025,6 +2040,7 @@ GenericLeaseMgrTest::testDeleteExpiredReclaimedLeases6() {
|
||||
((leases[i]->getExpirationTime() + lease_affinity_time) < current_time)) {
|
||||
EXPECT_FALSE(lease) << "The following lease should have been"
|
||||
" deleted: " << leases[i]->toText();
|
||||
++should_delete_num;
|
||||
|
||||
} else {
|
||||
// If the lease is not reclaimed or it has expired less than
|
||||
@@ -2033,10 +2049,16 @@ GenericLeaseMgrTest::testDeleteExpiredReclaimedLeases6() {
|
||||
" deleted: " << leases[i]->toText();
|
||||
}
|
||||
}
|
||||
// Check that the number of deleted leases is correct.
|
||||
EXPECT_EQ(should_delete_num, deleted_num);
|
||||
|
||||
// Make sure we can make another attempt, when there are no more leases
|
||||
// to be deleted.
|
||||
ASSERT_NO_THROW(lmptr_->deleteExpiredReclaimedLeases6(lease_affinity_time));
|
||||
ASSERT_NO_THROW(
|
||||
deleted_num = lmptr_->deleteExpiredReclaimedLeases6(lease_affinity_time)
|
||||
);
|
||||
// No lease should have been deleted.
|
||||
EXPECT_EQ(0, deleted_num);
|
||||
|
||||
// Reopen the database. This to ensure that the leases have been deleted
|
||||
// from the persistent storage.
|
||||
|
@@ -219,7 +219,7 @@ public:
|
||||
/// @param secs Number of seconds since expiration of leases before
|
||||
/// they can be removed. Leases which have expired later than this
|
||||
/// time will not be deleted.
|
||||
virtual void deleteExpiredReclaimedLeases4(const uint32_t) {
|
||||
virtual uint64_t deleteExpiredReclaimedLeases4(const uint32_t) {
|
||||
isc_throw(NotImplemented, "ConcreteLeaseMgr::deleteExpiredReclaimedLeases4"
|
||||
" is not implemented");
|
||||
}
|
||||
@@ -229,7 +229,7 @@ public:
|
||||
/// @param secs Number of seconds since expiration of leases before
|
||||
/// they can be removed. Leases which have expired later than this
|
||||
/// time will not be deleted.
|
||||
virtual void deleteExpiredReclaimedLeases6(const uint32_t) {
|
||||
virtual uint64_t deleteExpiredReclaimedLeases6(const uint32_t) {
|
||||
isc_throw(NotImplemented, "ConcreteLeaseMgr::deleteExpiredReclaimedLeases6"
|
||||
" is not implemented");
|
||||
}
|
||||
|
Reference in New Issue
Block a user