]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5469] Moved to composite index in C++ code too
authorFrancis Dupont <fdupont@isc.org>
Wed, 17 Jan 2018 18:28:57 +0000 (19:28 +0100)
committerFrancis Dupont <fdupont@isc.org>
Wed, 17 Jan 2018 18:28:57 +0000 (19:28 +0100)
13 files changed:
src/hooks/dhcp/lease_cmds/lease_cmds.cc
src/lib/dhcpsrv/cql_lease_mgr.cc
src/lib/dhcpsrv/cql_lease_mgr.h
src/lib/dhcpsrv/dhcpsrv_messages.mes
src/lib/dhcpsrv/lease_mgr.h
src/lib/dhcpsrv/memfile_lease_mgr.cc
src/lib/dhcpsrv/memfile_lease_mgr.h
src/lib/dhcpsrv/mysql_lease_mgr.cc
src/lib/dhcpsrv/mysql_lease_mgr.h
src/lib/dhcpsrv/pgsql_lease_mgr.cc
src/lib/dhcpsrv/pgsql_lease_mgr.h
src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/lease_mgr_unittest.cc

index 0c48e2046de43991e1779fa86785b24d5eed87a7..7c8b01aa73b4e1cfb47f14ffe82065cc5de399b2 100644 (file)
@@ -503,11 +503,26 @@ LeaseCmdsImpl::leaseGetAllHandler(CalloutHandle& handle) {
                         }
                     } else {
                         Lease6Collection leases =
-                            LeaseMgrFactory::instance().getLeases6((*subnet_id)->intValue());
+                            LeaseMgrFactory::instance().getLeases6((*subnet_id)->intValue(),
+                                                                   Lease::TYPE_NA);
                         for (auto lease = leases.begin(); lease != leases.end(); ++lease) {
                             ElementPtr lease_json = (*lease)->toElement();
                             leases_json->add(lease_json);
                         }
+
+                        leases = LeaseMgrFactory::instance().getLeases6((*subnet_id)->intValue(),
+                                                                   Lease::TYPE_TA);
+                        for (auto lease = leases.begin(); lease != leases.end(); ++lease) {
+                            ElementPtr lease_json = (*lease)->toElement();
+                            leases_json->add(lease_json);
+                        }
+
+                        leases = LeaseMgrFactory::instance().getLeases6((*subnet_id)->intValue(),
+                                                                   Lease::TYPE_PD);
+                        for (auto lease = leases.begin(); lease != leases.end(); ++lease) {
+                            ElementPtr lease_json = (*lease)->toElement();
+                            leases_json->add(lease_json);
+                        }                           
                     }
                 }
 
index 5dcdfd8f9b4b56910ef23737834fb2dc073c376d..fb114dfdf5623a8b3b7874f5e7115bc700e538bb 100644 (file)
@@ -1719,7 +1719,7 @@ CqlLeaseMgr::getLeases6(Lease::Type lease_type, const DUID &duid, uint32_t iaid,
 }
 
 Lease6Collection
-CqlLeaseMgr::getLeases6(SubnetID) const {
+CqlLeaseMgr::getLeases6(SubnetID, Lease::Type) const {
     isc_throw(NotImplemented, "getLeases6(subnet_id) is not implemented");
 }
 
index af0097289cae4b86de4034416b3d55453734c763..c699577d893dfa84c23c4be920d61feac0afa6b8 100644 (file)
@@ -268,12 +268,15 @@ public:
                                         uint32_t iaid,
                                         SubnetID subnet_id) const override;
 
-    /// @brief Returns all IPv6 leases for the particular subnet identifier.
+    /// @brief Returns all IPv6 leases for the particular subnet identifier
+    /// and lease type.
     ///
     /// @param subnet_id subnet identifier.
+    /// @param type specifies lease type: (NA, TA or PD)
     ///
     /// @return Lease collection (may be empty if no IPv6 lease found).
-    virtual Lease6Collection getLeases6(SubnetID subnet_id) const;
+    virtual Lease6Collection getLeases6(SubnetID subnet_id,
+                                        Lease::Type type) const;
 
     /// @brief Returns all IPv6 leases.
     ///
index 8e3c7cfebd765cdbf24ae285ead2cda05627efe1..2fc38426d5a74fca4a602b47a3ed07e776956482 100644 (file)
@@ -514,9 +514,10 @@ lease from the memory file database for a client with the specified IAID
 A debug message issued when the server is attempting to obtain all IPv4
 leases for a given subnet identifier from the memory file database.
 
-% DHCPSRV_MEMFILE_GET_SUBID6 obtaining IPv6 leases for subnet ID %1
+% DHCPSRV_MEMFILE_GET_SUBID_TYPE6 obtaining IPv6 leases for subnet ID %1 and type %2
 A debug message issued when the server is attempting to obtain all IPv6
-leases for a given subnet identifier from the memory file database.
+leases for a given subnet identifier and lease type from the memory file
+database.
 
 % DHCPSRV_MEMFILE_GET_SUBID_CLIENTID obtaining IPv4 lease for subnet ID %1 and client ID %2
 A debug message issued when the server is attempting to obtain an IPv4
@@ -751,9 +752,9 @@ lease from the MySQL database for a client with the specified IAID
 A debug message issued when the server is attempting to obtain all IPv4
 leases for a given subnet identifier from the MySQL database.
 
-% DHCPSRV_MYSQL_GET_SUBID6 obtaining IPv6 leases for subnet ID %1
+% DHCPSRV_MYSQL_GET_SUBID_TYPE6 obtaining IPv6 leases for subnet ID %1 and type %2
 A debug message issued when the server is attempting to obtain all IPv6
-leases for a given subnet identifier from the MySQL database.
+leases for a given subnet identifier and lease type from the MySQL database.
 
 % DHCPSRV_MYSQL_GET_SUBID_CLIENTID obtaining IPv4 lease for subnet ID %1 and client ID %2
 A debug message issued when the server is attempting to obtain an IPv4
@@ -921,9 +922,10 @@ lease from the PostgreSQL database for a client with the specified IAID
 A debug message issued when the server is attempting to obtain all IPv4
 leases for a given subnet identifier from the PostgreSQL database.
 
-% DHCPSRV_PGSQL_GET_SUBID6 obtaining IPv6 leases for subnet ID %1
+% DHCPSRV_PGSQL_GET_SUBID_TYPE6 obtaining IPv6 leases for subnet ID %1 and type %2
 A debug message issued when the server is attempting to obtain all IPv6
-leases for a given subnet identifier from the PostgreSQL database.
+leases for a given subnet identifier and lease type from the PostgreSQL
+database.
 
 % DHCPSRV_PGSQL_GET_SUBID_CLIENTID obtaining IPv4 lease for subnet ID %1 and client ID %2
 A debug message issued when the server is attempting to obtain an IPv4
index f7775845bd80467cf1d50d03fe6caff4e7f93231..c4bbf4829283311f64a1c68265ccdae5a8ca7116 100644 (file)
@@ -341,12 +341,15 @@ public:
     Lease6Ptr getLease6(Lease::Type type, const DUID& duid,
                         uint32_t iaid, SubnetID subnet_id) const;
 
-    /// @brief Returns all IPv6 leases for the particular subnet identifier.
+    /// @brief Returns all IPv6 leases for the particular subnet identifier
+    /// and lease type.
     ///
     /// @param subnet_id subnet identifier.
+    /// @param type specifies lease type: (NA, TA or PD)
     ///
     /// @return Lease collection (may be empty if no IPv6 lease found).
-    virtual Lease6Collection getLeases6(SubnetID subnet_id) const = 0;
+    virtual Lease6Collection getLeases6(SubnetID subnet_id,
+                                        Lease::Type type) const = 0;
 
     /// @brief Returns all IPv6 leases.
     ///
index 61aaf577b1f73c1de33f054c3ad65524b1b38468..871905b57fbb919cf31d01b52c0b55b3b24b6f15 100644 (file)
@@ -832,9 +832,10 @@ Memfile_LeaseMgr::getLeases6(Lease::Type type,
 }
 
 Lease6Collection
-Memfile_LeaseMgr::getLeases6(SubnetID subnet_id) const {
-    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET_SUBID6)
-        .arg(subnet_id);
+Memfile_LeaseMgr::getLeases6(SubnetID subnet_id, Lease::Type type) const {
+    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MEMFILE_GET_SUBID_TYPE6)
+        .arg(subnet_id)
+        .arg(Lease::typeToText(type));
 
     Lease6Collection collection;
     const Lease6StorageSubnetIdIndex& idx = storage6_.get<SubnetIdIndexTag>();
@@ -843,7 +844,10 @@ Memfile_LeaseMgr::getLeases6(SubnetID subnet_id) const {
         idx.equal_range(subnet_id);
 
     for (auto lease = l.first; lease != l.second; ++lease) {
-        collection.push_back(Lease6Ptr(new Lease6(**lease)));
+        // Filter out the leases which lease type doesn't match.
+        if ((*lease)->type_ == type) {
+            collection.push_back(Lease6Ptr(new Lease6(**lease)));
+        }
     }
 
     return (collection);
index 0cb5bc829b42a2d3bb3cc074c5b83f7ab34519fe..c42d799b91d9440009e360b0c6f066ff94bb9271 100644 (file)
@@ -271,12 +271,15 @@ public:
                                         uint32_t iaid,
                                         SubnetID subnet_id) const;
 
-    /// @brief Returns all IPv6 leases for the particular subnet identifier.
+    /// @brief Returns all IPv6 leases for the particular subnet identifier
+    /// and lease type.
     ///
     /// @param subnet_id subnet identifier.
+    /// @param type specifies lease type: (NA, TA or PD)
     ///
     /// @return Lease collection (may be empty if no IPv6 lease found).
-    virtual Lease6Collection getLeases6(SubnetID subnet_id) const;
+    virtual Lease6Collection getLeases6(SubnetID subnet_id,
+                                        Lease::Type type) const;
 
     /// @brief Returns all IPv6 leases.
     ///
index 9f035564886677a2ae2b813b204fbb8dedef28a9..19dd8e44befbaaac6689cdf29bb2d97a615ac723 100644 (file)
@@ -189,7 +189,7 @@ tagged_statements = { {
                             "FROM lease6 "
                             "WHERE duid = ? AND iaid = ? AND subnet_id = ? "
                             "AND lease_type = ?"},
-    {MySqlLeaseMgr::GET_LEASE6_SUBID,
+    {MySqlLeaseMgr::GET_LEASE6_SUBID_TYPE,
                     "SELECT address, duid, valid_lifetime, "
                         "expire, subnet_id, pref_lifetime, "
                         "lease_type, iaid, prefix_len, "
@@ -197,7 +197,7 @@ tagged_statements = { {
                         "hwaddr, hwtype, hwaddr_source, "
                         "state "
                             "FROM lease6 "
-                            "WHERE subnet_id = ?"},
+                            "WHERE subnet_id = ? and lease_type = ?"},
     {MySqlLeaseMgr::GET_LEASE6_EXPIRE,
                     "SELECT address, duid, valid_lifetime, "
                         "expire, subnet_id, pref_lifetime, "
@@ -1927,12 +1927,14 @@ MySqlLeaseMgr::getLeases6(Lease::Type lease_type,
 }
 
 Lease6Collection
-MySqlLeaseMgr::getLeases6(SubnetID subnet_id) const {
-    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_MYSQL_GET_SUBID6)
-        .arg(subnet_id);
+MySqlLeaseMgr::getLeases6(SubnetID subnet_id, Lease::Type type) const {
+    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
+              DHCPSRV_MYSQL_GET_SUBID_TYPE6)
+        .arg(subnet_id)
+        .arg(Lease::typeToText(type));
 
     // Set up the WHERE clause value
-    MYSQL_BIND inbind[1];
+    MYSQL_BIND inbind[2];
     memset(inbind, 0, sizeof(inbind));
 
     // Subnet ID
@@ -1940,9 +1942,14 @@ MySqlLeaseMgr::getLeases6(SubnetID subnet_id) const {
     inbind[0].buffer = reinterpret_cast<char*>(&subnet_id);
     inbind[0].is_unsigned = MLM_TRUE;
 
+    // LEASE_TYPE
+    inbind[1].buffer_type = MYSQL_TYPE_TINY;
+    inbind[1].buffer = reinterpret_cast<char*>(&type);
+    inbind[1].is_unsigned = MLM_TRUE;
+
     // ... and get the data
     Lease6Collection result;
-    getLeaseCollection(GET_LEASE6_SUBID, inbind, result);
+    getLeaseCollection(GET_LEASE6_SUBID_TYPE, inbind, result);
 
     return (result);
 }
index 91265cc72ba5ca12e6d0cad356ddfb3f80e42c58..bafafbd8c17c61775ab39a5fb2791af125273a87 100644 (file)
@@ -268,12 +268,15 @@ public:
     virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid,
                                         uint32_t iaid, SubnetID subnet_id) const;
 
-    /// @brief Returns all IPv6 leases for the particular subnet identifier.
+    /// @brief Returns all IPv6 leases for the particular subnet identifier
+    /// and lease type.
     ///
     /// @param subnet_id subnet identifier.
+    /// @param type specifies lease type: (NA, TA or PD)
     ///
     /// @return Lease collection (may be empty if no IPv6 lease found).
-    virtual Lease6Collection getLeases6(SubnetID subnet_id) const;
+    virtual Lease6Collection getLeases6(SubnetID subnet_id,
+                                        Lease::Type type) const;
 
     /// @brief Returns all IPv6 leases.
     ///
@@ -452,7 +455,7 @@ public:
         GET_LEASE6_ADDR,             // Get lease6 by address
         GET_LEASE6_DUID_IAID,        // Get lease6 by DUID and IAID
         GET_LEASE6_DUID_IAID_SUBID,  // Get lease6 by DUID, IAID and subnet ID
-        GET_LEASE6_SUBID,            // Get IPv6 leases by subnet ID
+        GET_LEASE6_SUBID_TYPE,       // Get IPv6 leases by subnet ID and type
         GET_LEASE6_EXPIRE,           // Get lease6 by expiration.
         GET_VERSION,                 // Obtain version number
         INSERT_LEASE4,               // Add entry to lease4 table
index c9e68499dd31682490bb554aedbc475d7fd141fa..156a54290fa9f3ed692e2579d9b2f0d200e8d1cd 100644 (file)
@@ -168,15 +168,15 @@ PgSqlTaggedStatement tagged_statements[] = {
       "WHERE lease_type = $1 "
         "AND duid = $2 AND iaid = $3 AND subnet_id = $4"},
 
-    // GET_LEASE6_SUBID
-    { 1, { OID_INT8 },
+    // GET_LEASE6_SUBID_TYPE
+    { 2, { OID_INT8, OID_INT2 },
       "get_lease6_subid",
       "SELECT address, duid, valid_lifetime, "
         "extract(epoch from expire)::bigint, subnet_id, pref_lifetime, "
         "lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname, "
         "state "
       "FROM lease6 "
-      "WHERE subnet_id = $1"},
+      "WHERE subnet_id = $1 AND lease_type = $2"},
 
     // GET_LEASE6_EXPIRE
     { 3, { OID_INT8, OID_TIMESTAMP, OID_INT8 },
@@ -1225,9 +1225,10 @@ PgSqlLeaseMgr::getLeases6(Lease::Type lease_type, const DUID& duid,
 }
 
 Lease6Collection
-PgSqlLeaseMgr::getLeases6(SubnetID subnet_id) const {
-    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_PGSQL_GET_SUBID6)
-        .arg(subnet_id);
+PgSqlLeaseMgr::getLeases6(SubnetID subnet_id, Lease::Type type) const {
+    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_PGSQL_GET_SUBID_TYPE6)
+        .arg(subnet_id)
+        .arg(Lease::typeToText(type));
 
     // Set up the WHERE clause value
     PsqlBindArray bind_array;
@@ -1236,9 +1237,13 @@ PgSqlLeaseMgr::getLeases6(SubnetID subnet_id) const {
     std::string subnet_id_str = boost::lexical_cast<std::string>(subnet_id);
     bind_array.add(subnet_id_str);
 
+    // LEASE_TYPE
+    std::string lease_type_str = boost::lexical_cast<std::string>(type);
+    bind_array.add(lease_type_str);
+
     // ... and get the data
     Lease6Collection result;
-    getLeaseCollection(GET_LEASE6_SUBID, bind_array, result);
+    getLeaseCollection(GET_LEASE6_SUBID_TYPE, bind_array, result);
 
     return (result);
 }
index 54ca6df8ecbe585cc4115cedfd9b7e36e54caaeb..9f41350c9cfdb0546f310281a14ca1984f3388da 100644 (file)
@@ -242,12 +242,15 @@ public:
     virtual Lease6Collection getLeases6(Lease::Type type, const DUID& duid,
                                         uint32_t iaid, SubnetID subnet_id) const;
 
-    /// @brief Returns all IPv6 leases for the particular subnet identifier.
+    /// @brief Returns all IPv6 leases for the particular subnet identifier
+    /// and lease type.
     ///
     /// @param subnet_id subnet identifier.
+    /// @param type specifies lease type: (NA, TA or PD)
     ///
     /// @return Lease collection (may be empty if no IPv6 lease found).
-    virtual Lease6Collection getLeases6(SubnetID subnet_id) const;
+    virtual Lease6Collection getLeases6(SubnetID subnet_id,
+                                        Lease::Type type) const;
 
     /// @brief Returns all IPv6 leases.
     ///
@@ -443,7 +446,7 @@ public:
         GET_LEASE6_ADDR,            // Get lease6 by address
         GET_LEASE6_DUID_IAID,       // Get lease6 by DUID and IAID
         GET_LEASE6_DUID_IAID_SUBID, // Get lease6 by DUID, IAID and subnet ID
-        GET_LEASE6_SUBID,           // Get IPv6 leases by subnet ID
+        GET_LEASE6_SUBID_TYPE,      // Get IPv6 leases by subnet ID and type
         GET_LEASE6_EXPIRE,          // Get expired lease6
         GET_VERSION,                // Obtain version number
         INSERT_LEASE4,              // Add entry to lease4 table
index 3b1850d5275d86f91684d74c9333b4e2d38ad9e3..8ff4c4ecdd79375877a49fca19f90eaa490779d0 100644 (file)
@@ -1255,9 +1255,14 @@ GenericLeaseMgrTest::testGetLeases6SubnetId() {
     }
 
     // There should be exactly two leases for the subnet id that the second
-    // lease belongs to.
-    Lease6Collection returned = lmptr_->getLeases6(leases[1]->subnet_id_);
-    ASSERT_EQ(2, returned.size());
+    // lease belongs to, one TA and one PD.
+    Lease6Collection returned =
+      lmptr_->getLeases6(leases[1]->subnet_id_, Lease::TYPE_NA);
+    EXPECT_EQ(0, returned.size());
+    returned = lmptr_->getLeases6(leases[1]->subnet_id_,Lease::TYPE_TA);
+    EXPECT_EQ(1, returned.size());
+    returned = lmptr_->getLeases6(leases[1]->subnet_id_,Lease::TYPE_PD);
+    EXPECT_EQ(1, returned.size());
 }
 
 void
index 88ea5a064a38d16f06c6ed3cf91a4cc85ff31bd9..3a20e7b58ecf7639361ae881c6039fa0ebf53b45 100644 (file)
@@ -181,9 +181,10 @@ public:
     /// @brief Returns all IPv6 leases for the particular subnet identifier.
     ///
     /// @param subnet_id subnet identifier.
+    /// @param type lease type.
     ///
     /// @return Lease collection (may be empty if no IPv6 lease found).
-    virtual Lease6Collection getLeases6(SubnetID) const {
+    virtual Lease6Collection getLeases6(SubnetID,  Lease::Type) const {
         return (Lease6Collection());
     }