]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2209] Hack the ZoneTableSegment into MemoryClient
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Tue, 23 Oct 2012 15:00:29 +0000 (17:00 +0200)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Tue, 23 Oct 2012 15:00:29 +0000 (17:00 +0200)
This branch needs the MemoryClient to have its Zonetablesegment. But it
doesn't have one now and it is not the task of this branch to put it in
there. So I added it inside in somewhat ad-hoc manner.

This is hairy and adds bunch of temporary methods. If there's a better
approach, let's use it. But taking this for now to be cleaned up in some
follow-up ticket.

src/lib/datasrc/memory/memory_client.cc
src/lib/datasrc/memory/memory_client.h
src/lib/datasrc/memory/zone_table_segment.cc
src/lib/datasrc/memory/zone_table_segment.h
src/lib/datasrc/memory/zone_table_segment_local.h
src/lib/datasrc/tests/memory/memory_client_unittest.cc

index 2f5fe67d97a9ab42ffbb9735101207b7f9c6f8a3..7a367e2bbaccbd065894d537f06ae8bb576d12ed 100644 (file)
@@ -22,6 +22,7 @@
 #include <datasrc/memory/treenode_rrset.h>
 #include <datasrc/memory/zone_finder.h>
 #include <datasrc/memory/zone_data_loader.h>
+#include <datasrc/memory/zone_table_segment.h>
 
 #include <util/memory_segment_local.h>
 
@@ -66,7 +67,14 @@ public:
 
 InMemoryClient::InMemoryClient(util::MemorySegment& mem_sgmt,
                                RRClass rrclass) :
-    mem_sgmt_(mem_sgmt),
+    // FIXME: We currently use the temporary and "unsupported"
+    // constructor of the zone table segment. Once we clarify
+    // how the config thing, we want to change it.
+    zone_table_segment_(ZoneTableSegment::create(mem_sgmt)),
+    // Use the memory segment from the zone table segment. Currently,
+    // it is the same one as the one in parameter, but that will
+    // probably change.
+    mem_sgmt_(zone_table_segment_->getMemorySegment()),
     rrclass_(rrclass),
     zone_count_(0)
 {
@@ -76,13 +84,19 @@ InMemoryClient::InMemoryClient(util::MemorySegment& mem_sgmt,
     file_name_tree_ = FileNameTree::create(mem_sgmt_, false);
 
     zone_table_ = holder.release();
+    // TODO: Once the table is created inside the zone table segment, use that
+    // one.
+    zone_table_segment_->getHeader().setTable(zone_table_);
 }
 
 InMemoryClient::~InMemoryClient() {
     FileNameDeleter deleter;
     FileNameTree::destroy(mem_sgmt_, file_name_tree_, deleter);
 
+    // TODO: Once the table is created inside the zone table segment, do not
+    // destroy it here.
     ZoneTable::destroy(mem_sgmt_, zone_table_, rrclass_);
+    ZoneTableSegment::destroy(zone_table_segment_);
 }
 
 result::Result
index 3313c5bc777c9837cfce0fd688c15ceb84518ce3..dd74a728c26d49349aa09153f3a0d27c89aa39b7 100644 (file)
@@ -34,6 +34,8 @@ class RRsetList;
 namespace datasrc {
 namespace memory {
 
+class ZoneTableSegment;
+
 /// \brief A data source client that holds all necessary data in memory.
 ///
 /// The \c InMemoryClient class provides an access to a conceptual data
@@ -175,6 +177,18 @@ public:
     getJournalReader(const isc::dns::Name& zone, uint32_t begin_serial,
                      uint32_t end_serial) const;
 
+    /// \brief Get the zone table segment used
+    ///
+    /// This is a low-level function, used to some internal handling when,
+    /// for example, reloading the data inside the in-memory data source.
+    /// It should not be generally used.
+    ///
+    /// \todo Consider making this private and add a friend declaration
+    ///     for the ClientList.
+    ZoneTableSegment& getZoneTableSegment() {
+        return (*zone_table_segment_);
+    }
+
 private:
     // Some type aliases
     typedef DomainTree<std::string> FileNameTree;
@@ -186,6 +200,7 @@ private:
                                 const std::string& filename,
                                 ZoneData* zone_data);
 
+    ZoneTableSegment* zone_table_segment_;
     util::MemorySegment& mem_sgmt_;
     const isc::dns::RRClass rrclass_;
     unsigned int zone_count_;
index 7a80e3c4c1c3b59ca5b9af8b4c4884eb48bf239d..db8ea26aa61dfa85b52d53a75ea448baa94c7652 100644 (file)
@@ -28,6 +28,11 @@ ZoneTableSegment::create(const isc::data::Element&) {
     return (new ZoneTableSegmentLocal);
 }
 
+ZoneTableSegment*
+ZoneTableSegment::create(isc::util::MemorySegment& segment) {
+    return (new ZoneTableSegmentLocal(segment));
+}
+
 void
 ZoneTableSegment::destroy(ZoneTableSegment *segment) {
     delete segment;
index 8731718f618ffe4ebc45ca9f7ab76439b3cb029c..0e728b8d07733808f2c89a38aa6c434fdd030243 100644 (file)
@@ -121,6 +121,18 @@ public:
     /// \return Returns a ZoneTableSegment object
     static ZoneTableSegment* create(const isc::data::Element& config);
 
+    /// \brief Temporary/Testing version of create.
+    ///
+    /// This exists as a temporary solution during the migration phase
+    /// towards using the ZoneTableSegment. It doesn't take a config,
+    /// but a memory segment instead. If you can, you should use the
+    /// other version, this one will be gone soon.
+    ///
+    /// \param segment The memory segment to use.
+    /// \return Returns a new ZoneTableSegment object.
+    /// \todo Remove this method.
+    static ZoneTableSegment* create(isc::util::MemorySegment& segment);
+
     /// \brief Destroy a ZoneTableSegment
     ///
     /// This method destroys the passed ZoneTableSegment. It must be
index b83bd49fa2aaef6d8fb81c587a0ef7565defdece..903bbe652c0686566fc731a7b91f269adf74ec74 100644 (file)
@@ -37,7 +37,13 @@ protected:
     /// Instances are expected to be created by the factory method
     /// (\c ZoneTableSegment::create()), so this constructor is
     /// protected.
-    ZoneTableSegmentLocal()
+    ZoneTableSegmentLocal() :
+        mem_sgmt_(mem_sgmt_local_)
+    {}
+    // TODO: A temporary constructor, for tests for now. Needs to
+    // be removed.
+    ZoneTableSegmentLocal(isc::util::MemorySegment& segment) :
+        mem_sgmt_(segment)
     {}
 public:
     /// \brief Destructor
@@ -60,7 +66,8 @@ public:
                                       const dns::RRClass& rrclass);
 private:
     ZoneTableHeader header_;
-    isc::util::MemorySegmentLocal mem_sgmt_;
+    isc::util::MemorySegmentLocal mem_sgmt_local_;
+    isc::util::MemorySegment& mem_sgmt_;
 };
 
 } // namespace memory
index c1c340417355548f65ae589be93ffe257524eb79..6b41d84fa7ff5d98021af26f3766411b52975160 100644 (file)
@@ -765,4 +765,12 @@ TEST_F(MemoryClientTest, getJournalReaderNotImplemented) {
                  isc::NotImplemented);
 }
 
+TEST_F(MemoryClientTest, getZoneTableSegment) {
+    // It's hard to test this method. It returns a reference, so we can't even
+    // check for non-NULL. Checking it doesn't throw/crash is good enough for
+    // now, the method will be used in other functions, so checked it works
+    // implicitly.
+    EXPECT_NO_THROW(client_->getZoneTableSegment());
+}
+
 }