From: Thomas Markwalder Date: Thu, 25 Aug 2016 11:15:26 +0000 (-0400) Subject: [4294] Changed Memfile stats recount to use existing per-address index X-Git-Tag: trac4631_base~6^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=52ff5a4e463007103ae970cc520be7d7a87d64f4;p=thirdparty%2Fkea.git [4294] Changed Memfile stats recount to use existing per-address index src/lib/dhcpsrv/memfile_lease_mgr.cc MemfileLeaseStatsQuery4::start() MemfileLeaseStatsQuery6::start() - both now rely on per-address index, rather than adding per subnet_id index. src/lib/dhcpsrv/memfile_lease_storage.h Removed per subnet_id indexes --- diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc index 79c4020f90..4ff78be9d1 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@ -329,10 +329,15 @@ public: /// @brief Creates the IPv4 lease statistical data result set /// - /// The result is populated by iterating over the IPv4 leases in storage, - /// in ascending order by subnet ID, accumulating the lease state counts. + /// The result set is populated by iterating over the IPv4 leases in + /// storage, in ascending order by address, accumulating the lease state + /// counts per subnet. Note that walking the leases by address should + /// inherently group them by subnet, and while this does not gaurantee + /// ascending order of subnet id, it should be sufficient to accumulate + /// state counts per subnet. This avoids introducing an additional + /// subnet_id index. /// At the completion of all entries for a given subnet, the counts are - /// used to create AddressStatsRow4 instances which are appended to an + /// used to create LeaseStatsRow instances which are appended to an /// internal vector. The process results in a vector containing one entry /// per state per subnet. /// @@ -341,9 +346,8 @@ public: /// - Lease::STATE_DEFAULT (i.e. assigned) /// - Lease::STATE_DECLINED void start() { - // Get the subnet_id index - const Lease4StorageSubnetIdIndex& idx - = storage4_.get(); + const Lease4StorageAddressIndex& idx + = storage4_.get(); // Iterate over the leases in order by subnet, accumulating per // subnet counts for each state of interest. As we finish each @@ -351,12 +355,11 @@ public: SubnetID cur_id = 0; int64_t assigned = 0; int64_t declined = 0; - for(Lease4StorageSubnetIdIndex::const_iterator lease = idx.begin(); + for(Lease4StorageAddressIndex::const_iterator lease = idx.begin(); lease != idx.end(); ++lease) { - // If we've hit the next subnet, add rows for the current subnet // and wipe the accumulators - if ((*lease)->subnet_id_ > cur_id) { + if ((*lease)->subnet_id_ != cur_id) { if (cur_id > 0) { rows_.push_back(LeaseStatsRow(cur_id, Lease::STATE_DEFAULT, assigned)); @@ -419,12 +422,17 @@ public: /// @brief Creates the IPv6 lease statistical data result set /// - /// The result is populated by iterating over the IPv6 leases in storage, - /// in ascending order by subnet ID, accumulating the lease state counts - /// per lease type. At the completion of all entries for a given subnet, - /// the counts are used to create AddressStatsRow5 instances which are - /// appended to an internal vector. The process results in a vector - /// containing one entry per state per lease type per subnet. + /// The result set is populated by iterating over the IPv6 leases in + /// storage, in ascending order by address, accumulating the lease state + /// counts per subnet. Note that walking the leases by address should + /// inherently group them by subnet, and while this does not gaurantee + /// ascending order of subnet id, it should be sufficient to accumulate + /// state counts per subnet. This avoids introducing an additional + /// subnet_id index. + /// At the completion of all entries for a given subnet, the counts + /// are used to create LeaseStatsRow instances which are appended to an + /// internal vector. The process results in a vector containing one entry + /// per state per lease type per subnet. /// /// Currently the states counted are: /// @@ -432,8 +440,8 @@ public: /// - Lease::STATE_DECLINED virtual void start() { // Get the subnet_id index - const Lease6StorageSubnetIdIndex& idx - = storage6_.get(); + const Lease6StorageAddressIndex& idx + = storage6_.get(); // Iterate over the leases in order by subnet, accumulating per // subnet counts for each state of interest. As we finish each @@ -443,12 +451,12 @@ public: int64_t declined = 0; int64_t assigned_pds = 0; - for(Lease6StorageSubnetIdIndex::const_iterator lease = idx.begin(); + for(Lease6StorageAddressIndex::const_iterator lease = idx.begin(); lease != idx.end(); ++lease) { // If we've hit the next subnet, add rows for the current subnet // and wipe the accumulators - if ((*lease)->subnet_id_ > cur_id) { + if ((*lease)->subnet_id_ != cur_id) { if (cur_id > 0) { rows_.push_back(LeaseStatsRow(cur_id, Lease::TYPE_NA, Lease::STATE_DEFAULT, diff --git a/src/lib/dhcpsrv/memfile_lease_storage.h b/src/lib/dhcpsrv/memfile_lease_storage.h index 5c09f35d56..3b07fad238 100644 --- a/src/lib/dhcpsrv/memfile_lease_storage.h +++ b/src/lib/dhcpsrv/memfile_lease_storage.h @@ -1,4 +1,4 @@ -// Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -27,9 +27,6 @@ namespace dhcp { /// @brief Tag for indexes by address. struct AddressIndexTag { }; -/// @brief Tag for indexes by subnet id. -struct SubnetIdIndexTag { }; - /// @brief Tag for indexes by DUID, IAID, lease type tuple. struct DuidIaidTypeIndexTag { }; @@ -106,17 +103,7 @@ typedef boost::multi_index_container< boost::multi_index::const_mem_fun > - >, - - boost::multi_index::ordered_non_unique< - boost::multi_index::tag, - // The subnet id is held in the subnet_id_ member of Lease6 - // class. Note that the subnet_id_ is defined in the base - // class (Lease) so we have to point to this class rather - // than derived class: Lease6. - boost::multi_index::member > - > > Lease6Storage; // Specify the type name of this container. @@ -148,15 +135,6 @@ typedef boost::multi_index_container< boost::multi_index::member >, - boost::multi_index::ordered_non_unique< - boost::multi_index::tag, - // The subnet id is held in the subnet_id_ member of Lease4 - // class. Note that the subnet_id_ is defined in the base - // class (Lease) so we have to point to this class rather - // than derived class: Lease4. - boost::multi_index::member - >, - // Specification of the second index starts here. boost::multi_index::ordered_non_unique< boost::multi_index::tag, @@ -251,15 +229,9 @@ typedef Lease6Storage::index::type Lease6StorageDuidIaidTy /// @brief DHCPv6 lease storage index by expiration time. typedef Lease6Storage::index::type Lease6StorageExpirationIndex; -/// @brief DHCPv6 lease storage index by subnet id. -typedef Lease6Storage::index::type Lease6StorageSubnetIdIndex; - /// @brief DHCPv4 lease storage index by address. typedef Lease4Storage::index::type Lease4StorageAddressIndex; -/// @brief DHCPv4 lease storage index by subnet id. -typedef Lease4Storage::index::type Lease4StorageSubnetIdIndex; - /// @brief DHCPv4 lease storage index by exiration time. typedef Lease4Storage::index::type Lease4StorageExpirationIndex;