Parcourir la source

[1605] Get in-memory data source to use RBNodeRRset objects

Stephen Morris il y a 13 ans
Parent
commit
e07c5a1459

+ 10 - 3
src/lib/datasrc/memory_datasrc.cc

@@ -34,6 +34,8 @@
 
 #include <datasrc/memory_datasrc.h>
 #include <datasrc/rbtree.h>
+#include <datasrc/rbnode_rrset.h>
+#include <datasrc/rbnode_rrset.h>
 #include <datasrc/logger.h>
 #include <datasrc/iterator.h>
 #include <datasrc/data_source.h>
@@ -419,14 +421,19 @@ struct InMemoryZoneFinder::InMemoryZoneFinderImpl {
      * access is without the impl_-> and it will get inlined anyway.
      */
     // Implementation of InMemoryZoneFinder::add
-    result::Result add(const ConstRRsetPtr& rrset, ZoneData& zone_data) {
+    result::Result add(const ConstRRsetPtr& rawrrset, ZoneData& zone_data) {
         // Sanitize input.  This will cause an exception to be thrown
         // if the input RRset is empty.
-        addValidation(rrset);
+        addValidation(rawrrset);
 
         // OK, can add the RRset.
         LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_ADD_RRSET).
-            arg(rrset->getName()).arg(rrset->getType()).arg(origin_);
+            arg(rawrrset->getName()).arg(rawrrset->getType()).arg(origin_);
+
+        // ... although instead of loading the RRset directly, we encapsulate
+        // it within an RBNodeRRset.  This contains additional information that
+        // speeds up queries.
+        ConstRRsetPtr rrset(new RBNodeRRset(rawrrset));
 
         if (rrset->getType() == RRType::NSEC3()) {
             return (addNSEC3(rrset, zone_data));

+ 8 - 3
src/lib/datasrc/tests/memory_datasrc_unittest.cc

@@ -175,10 +175,15 @@ TEST_F(InMemoryClientTest, iterator) {
     // Check it with full zone, one by one.
     // It should be in ascending order in case of InMemory data source
     // (isn't guaranteed in general)
+    // Since the in-memory data source uses objects that encapsulate the
+    // RRsets stored, the iterator does not iterate over the RRsets stored -
+    // it iterates over the encapsulating objects.  This means that we cannot
+    // directly compare pointer values: instead, we compare the actual data
+    // stored.
     iterator = memory_client.getIterator(Name("a"));
-    EXPECT_EQ(aRRsetA, iterator->getNextRRset());
-    EXPECT_EQ(aRRsetAAAA, iterator->getNextRRset());
-    EXPECT_EQ(subRRsetA, iterator->getNextRRset());
+    EXPECT_EQ(aRRsetA->toText(), iterator->getNextRRset()->toText());
+    EXPECT_EQ(aRRsetAAAA->toText(), iterator->getNextRRset()->toText());
+    EXPECT_EQ(subRRsetA->toText(), iterator->getNextRRset()->toText());
     EXPECT_EQ(ConstRRsetPtr(), iterator->getNextRRset());
 }