]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1247] Checkpoint before rebase and resume
authorFrancis Dupont <fdupont@isc.org>
Sat, 20 Jun 2020 16:02:31 +0000 (18:02 +0200)
committerFrancis Dupont <fdupont@isc.org>
Mon, 6 Jul 2020 13:05:13 +0000 (15:05 +0200)
14 files changed:
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.h
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.h
src/hooks/dhcp/mysql_cb/mysql_cb_impl.h
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc
src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc
src/lib/database/audit_entry.h
src/lib/database/tests/audit_entry_unittest.cc
src/lib/dhcpsrv/config_backend_dhcp4.h
src/lib/dhcpsrv/config_backend_dhcp6.h
src/lib/dhcpsrv/config_backend_pool_dhcp4.h
src/lib/dhcpsrv/config_backend_pool_dhcp6.h
src/lib/dhcpsrv/testutils/test_config_backend_dhcp4.h
src/lib/dhcpsrv/testutils/test_config_backend_dhcp6.h
src/lib/process/cb_ctl_base.h

index f5fd30b40bddd704e919894bcaad6157be1647cb..4f729822fe16773269bd7ebab9dfd75c534aaa40 100644 (file)
@@ -231,7 +231,8 @@ public:
     /// @param modification_time Timestamp being a lower limit for the returned
     /// result set, i.e. entries later than specified time are returned.
     /// @param modification_id Identifier being a lower limit for the returned
-    /// result set, used when two (or more) entries have modification_time.
+    /// result set, used when two (or more) entries have the same
+    /// modification_time.
     /// @return Collection of audit entries.
     virtual db::AuditEntryCollection
     getRecentAuditEntries(const db::ServerSelector& server_selector,
index 3f35e838c7956bfd831b5e11082bd74a23d58286..babeb76d78e83b55da1ff0b41b846cc494ec4dd7 100644 (file)
@@ -231,7 +231,8 @@ public:
     /// @param modification_time Timestamp being a lower limit for the returned
     /// result set, i.e. entries later than specified time are returned.
     /// @param modification_id Identifier being a lower limit for the returned
-    /// result set, used when two (or more) entries have modification_time.
+    /// result set, used when two (or more) entries have the same
+    /// modification_time.
     /// @return Collection of audit entries.
     virtual db::AuditEntryCollection
     getRecentAuditEntries(const db::ServerSelector& server_selector,
index 9c3639d77caefb21279e0d52b1d701e8df46c3a8..d6b444b575be1a2c021c396eac44070b93848744 100644 (file)
@@ -240,7 +240,8 @@ public:
     /// @param modification_time Timestamp being a lower limit for the returned
     /// result set, i.e. entries later than specified time are returned.
     /// @param modification_id Identifier being a lower limit for the returned
-    /// result set, used when two (or more) entries have modification_time.
+    /// result set, used when two (or more) entries have the same
+    /// modification_time.
     /// @param [out] audit_entries Reference to the container where fetched audit
     /// entries will be inserted.
     void getRecentAuditEntries(const int index,
index 0a09237b9a52ef4195069ca1046900d43d1ad986..16d9577155703263b79a06e5694bea6f19073873 100644 (file)
@@ -442,7 +442,7 @@ public:
               << audit_entry->getObjectId() << ", "
               << static_cast<int>(audit_entry->getModificationType()) << ", "
               << audit_entry->getModificationTime() << ", "
-              << audit_entry->getEntryId() << ", "
+              << audit_entry->getModificationId() << ", "
               << audit_entry->getLogMessage()
               << std::endl;
         }
index 9a7a0e8ae3c5edc79726354d8a86597728c06157..bf5948011ce76f970dcf9431fa9d421298c27a8f 100644 (file)
@@ -490,7 +490,7 @@ public:
               << audit_entry->getObjectId() << ", "
               << static_cast<int>(audit_entry->getModificationType()) << ", "
               << audit_entry->getModificationTime() << ", "
-              << audit_entry->getEntryId() << ", "
+              << audit_entry->getModificationId() << ", "
               << audit_entry->getLogMessage()
               << std::endl;
         }
index f115fb1982161464be172643ef8f02ae20c13c5a..3dc46b982da6ddc35da71113e377d5d3fa7f0919 100644 (file)
@@ -10,6 +10,7 @@
 #include <boost/date_time/posix_time/posix_time.hpp>
 #include <boost/multi_index/composite_key.hpp>
 #include <boost/multi_index_container.hpp>
+#include <boost/multi_index/hashed_index.hpp>
 #include <boost/multi_index/mem_fun.hpp>
 #include <boost/multi_index/ordered_index.hpp>
 #include <boost/shared_ptr.hpp>
@@ -40,7 +41,7 @@ typedef boost::shared_ptr<AuditEntry> AuditEntryPtr;
 /// entries with later modification time than stored. That way the
 /// server queries only for the audit entries it hasn't fetched yet.
 /// In the case two (or more) successive audit entries have the same
-/// modification time the strictly increasing id is used.
+/// modification time the strictly increasing modification id is used.
 ///
 /// When the modification type of the entry is set to
 /// @c AuditEntry::ModificationType::DELETE, the corresponding
@@ -180,7 +181,7 @@ public:
     /// @brief Returns entry id.
     ///
     /// @return Identifier of the entry.
-    uint64_t getEntryId() const {
+    uint64_t getModificationId() const {
         return (id_);
     }
 
@@ -224,6 +225,9 @@ struct AuditEntryObjectTypeTag { };
 /// @brief Tag used to access index by modification time.
 struct AuditEntryModificationTimeIdTag { };
 
+/// @brief Tag used to access index by object id.
+struct AuditEntryObjectIdTag { };
+
 /// @brief Multi index container holding @c AuditEntry instances.
 ///
 /// This container provides indexes to access the audit entries
@@ -263,9 +267,19 @@ typedef boost::multi_index_container<
                 boost::multi_index::const_mem_fun<
                     AuditEntry,
                     uint64_t,
-                    &AuditEntry::getEntryId
+                    &AuditEntry::getModificationId
                 >
             >
+        >,
+
+        // Third index allows for accessing by the object id.
+        boost::multi_index::hashed_non_unique<
+            boost::multi_index::tag<AuditEntryObjectIdTag>,
+            boost::multi_index::const_mem_fun<
+                AuditEntry,
+                uint64_t,
+                &AuditEntry::getObjectId
+            >
         >
     >
 > AuditEntryCollection;
index fbfdc1d2ae6e9809a5617d34f818be18483cc1f2..8a61a2dd7689705f486d4b2f7a4f35a7510f2361 100644 (file)
@@ -96,7 +96,7 @@ TEST_F(AuditEntryTest, create) {
         EXPECT_EQ(10, audit_entry->getObjectId());
         EXPECT_EQ(AuditEntry::ModificationType::DELETE, audit_entry->getModificationType());
         EXPECT_EQ(fixedTime(), audit_entry->getModificationTime());
-        EXPECT_EQ(123, audit_entry->getEntryId());
+        EXPECT_EQ(123, audit_entry->getModificationId());
         EXPECT_EQ("deleted subnet 10", audit_entry->getLogMessage());
     }
 
@@ -110,7 +110,7 @@ TEST_F(AuditEntryTest, create) {
         EXPECT_EQ(123, audit_entry->getObjectId());
         EXPECT_EQ(AuditEntry::ModificationType::CREATE, audit_entry->getModificationType());
         EXPECT_TRUE(almostEqualTime(audit_entry->getModificationTime()));
-        EXPECT_EQ(234, audit_entry->getEntryId());
+        EXPECT_EQ(234, audit_entry->getModificationId());
         EXPECT_TRUE(audit_entry->getLogMessage().empty());
     }
 }
@@ -210,6 +210,32 @@ public:
         return (false);
     }
 
+    /// @brief Checks if the returned results range contains an @c AuditEntry
+    /// with a given object and modification types, and object identifier.
+    ///
+    /// @param object_type expected object type.
+    /// @param object_id expected object id.
+    /// @param modification_type expected modification type.
+    /// @param begin beginning of the results range to be examined.
+    /// @param end end of the results range to be examined.
+    template<typename Iterator>
+    bool includes(const std::string& object_type, const uint64_t object_id,
+                  const AuditEntry::ModificationType& modification_type,
+                  Iterator begin, Iterator end) {
+        // Iterate over the results range and look for the entry.
+        for (auto it = begin; it != end; ++it) {
+            if (((*it)->getObjectType() == object_type) &&
+                ((*it)->getObjectId() == object_id) &&
+                ((*it)->getModificationType() == modification_type)) {
+                // Entry found.
+                return (true);
+            }
+        }
+
+        // Entry not found.
+        return (false);
+    }
+
     /// @brief Audit entries used in the tests.
     AuditEntryCollection audit_entries_;
 
@@ -297,6 +323,40 @@ TEST_F(AuditEntryCollectionTest, getByModificationTimeAndId) {
     EXPECT_TRUE(includes("dhcp4_subnet", 1000, lb, mod_time_idx.end()));
     EXPECT_TRUE(includes("dhcp4_shared_network", 1, lb, mod_time_idx.end()));
     EXPECT_TRUE(includes("dhcp4_option", 15, lb, mod_time_idx.end()));
+
+    // Check the order is time first, id after.
+    create("dhcp4_subnet", 1000, AuditEntry::ModificationType::UPDATE,
+           diffTime(-8), 200, "updated subnet 1000");
+    lb = mod_time_idx.lower_bound(mod);
+    ASSERT_EQ(4, std::distance(lb, mod_time_idx.end()));
+    EXPECT_TRUE(includes("dhcp4_subnet", 120, lb, mod_time_idx.end()));
+    EXPECT_TRUE(includes("dhcp4_subnet", 1000, lb, mod_time_idx.end()));
+    EXPECT_TRUE(includes("dhcp4_shared_network", 1, lb, mod_time_idx.end()));
+    EXPECT_TRUE(includes("dhcp4_option", 15, lb, mod_time_idx.end()));
+}
+
+// Checks that entries can be found by object id.
+TEST_F(AuditEntryCollectionTest, getByObjectId) {
+    const auto& object_id_idx = audit_entries_.get<AuditEntryObjectIdTag>();
+
+    // Search for object id 10.
+    auto range =  object_id_idx.equal_range(10);
+    ASSERT_EQ(1, std::distance(range.first, range.second));
+    EXPECT_TRUE(includes("dhcp4_subnet", 10, range.first, range.second));
+
+    // Add another entry.
+    create("dhcp4_subnet", 10, AuditEntry::ModificationType::UPDATE,
+           diffTime(0), 111, "updated subnet 10");
+
+    // Now search should return two entries.
+    range =  object_id_idx.equal_range(10);
+    ASSERT_EQ(2, std::distance(range.first, range.second));
+    EXPECT_TRUE(includes("dhcp4_subnet", 10,
+                         AuditEntry::ModificationType::CREATE,
+                         range.first, range.second));
+    EXPECT_TRUE(includes("dhcp4_subnet", 10,
+                         AuditEntry::ModificationType::UPDATE,
+                         range.first, range.second));
 }
 
 }
index 4f8ee608e946139ff49003c90563e19160270dfd..f7aaaf8c8ebfcb0a15f926bc1bf5edbe5121f475 100644 (file)
@@ -302,7 +302,8 @@ public:
     /// @param modification_time Timestamp being a lower limit for the returned
     /// result set, i.e. entries later than specified time are returned.
     /// @param modification_id Identifier being a lower limit for the returned
-    /// result set, used when two (or more) entries have modification_time.
+    /// result set, used when two (or more) entries have the same
+    /// modification_time.
     /// @return Collection of audit entries.
     virtual db::AuditEntryCollection
     getRecentAuditEntries(const db::ServerSelector& server_selector,
index b11056e55e4ad51d510010ba67ca769667a8aaf1..dc4f6833f7760de511b3b46eb58b1b6a8b86d154 100644 (file)
@@ -303,7 +303,8 @@ public:
     /// @param modification_time Timestamp being a lower limit for the returned
     /// result set, i.e. entries later than specified time are returned.
     /// @param modification_id Identifier being a lower limit for the returned
-    /// result set, used when two (or more) entries have modification_time.
+    /// result set, used when two (or more) entries have the same
+    /// modification_time.
     /// @return Collection of audit entries.
     virtual db::AuditEntryCollection
     getRecentAuditEntries(const db::ServerSelector& server_selector,
index 8e6ba8b725a6107f1dbb6100c9301ae266931c74..c86d740a34db291e59c8384e66fc3caa17d238f9 100644 (file)
@@ -228,7 +228,8 @@ public:
     /// @param modification_time Timestamp being a lower limit for the returned
     /// result set, i.e. entries later than specified time are returned.
     /// @param modification_id Identifier being a lower limit for the returned
-    /// result set, used when two (or more) entries have modification_time.
+    /// result set, used when two (or more) entries have the same
+    /// modification_time.
     /// @return Collection of audit entries.
     virtual db::AuditEntryCollection
     getRecentAuditEntries(const db::BackendSelector& backend_selector,
index 2765acb9a29c91160dcf3984c277a332ae085b27..1805b3d328ee44b6f31a4f37acba7a5f93fc4d76 100644 (file)
@@ -227,7 +227,8 @@ public:
     /// @param modification_time Timestamp being a lower limit for the returned
     /// result set, i.e. entries later than specified time are returned.
     /// @param modification_id Identifier being a lower limit for the returned
-    /// result set, used when two (or more) entries have modification_time.
+    /// result set, used when two (or more) entries have the same
+    /// modification_time.
     /// @return Collection of audit entries.
     virtual db::AuditEntryCollection
     getRecentAuditEntries(const db::BackendSelector& backend_selector,
index fcda52b148a043add95620b0f261d2bd00d4b6df..02a1803d0f3bb30ac1ba61e823379562bdddb647 100644 (file)
@@ -221,7 +221,8 @@ public:
     /// @param modification_time Timestamp being a lower limit for the returned
     /// result set, i.e. entries later than specified time are returned.
     /// @param modification_id Identifier being a lower limit for the returned
-    /// result set, used when two (or more) entries have modification_time.
+    /// result set, used when two (or more) entries have the same
+    /// modification_time.
     /// @return Collection of audit entries.
     virtual db::AuditEntryCollection
     getRecentAuditEntries(const db::ServerSelector& server_selector,
index 9a1d25a10649e1985a81b99011441802ec0548dc..2e5d92cf4699be6d9d0e50162f90fb203e3080ec 100644 (file)
@@ -221,7 +221,8 @@ public:
     /// @param modification_time Timestamp being a lower limit for the returned
     /// result set, i.e. entries later than specified time are returned.
     /// @param modification_id Identifier being a lower limit for the returned
-    /// result set, used when two (or more) entries have modification_time.
+    /// result set, used when two (or more) entries have the same
+    /// modification_time.
     /// @return Collection of audit entries.
     virtual db::AuditEntryCollection
     getRecentAuditEntries(const db::ServerSelector& server_selector,
index 37daaaea9ae0e5fd0002bb34e982996e1fd4ccb2..c74140185f1ee4bcd76ef2da7065459785f058ab 100644 (file)
@@ -344,7 +344,7 @@ protected:
         // latest entry.
         const auto& index = audit_entries.get<db::AuditEntryModificationTimeIdTag>();
         last_audit_entry_time_ = (*index.rbegin())->getModificationTime();
-        last_audit_entry_id_ = (*index.rbegin())->getEntryId();
+        last_audit_entry_id_ = (*index.rbegin())->getModificationId();
     }
 
     /// @brief Stores the most recent audit entry timestamp.