From: Michal 'vorner' Vaner Date: Tue, 23 Oct 2012 15:00:29 +0000 (+0200) Subject: [2209] Hack the ZoneTableSegment into MemoryClient X-Git-Tag: trac2487_base~23^2~27^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a92defd1deceebc13a7bcc93cee6579ed42be41e;p=thirdparty%2Fkea.git [2209] Hack the ZoneTableSegment into MemoryClient 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. --- diff --git a/src/lib/datasrc/memory/memory_client.cc b/src/lib/datasrc/memory/memory_client.cc index 2f5fe67d97..7a367e2bba 100644 --- a/src/lib/datasrc/memory/memory_client.cc +++ b/src/lib/datasrc/memory/memory_client.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -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 diff --git a/src/lib/datasrc/memory/memory_client.h b/src/lib/datasrc/memory/memory_client.h index 3313c5bc77..dd74a728c2 100644 --- a/src/lib/datasrc/memory/memory_client.h +++ b/src/lib/datasrc/memory/memory_client.h @@ -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 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_; diff --git a/src/lib/datasrc/memory/zone_table_segment.cc b/src/lib/datasrc/memory/zone_table_segment.cc index 7a80e3c4c1..db8ea26aa6 100644 --- a/src/lib/datasrc/memory/zone_table_segment.cc +++ b/src/lib/datasrc/memory/zone_table_segment.cc @@ -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; diff --git a/src/lib/datasrc/memory/zone_table_segment.h b/src/lib/datasrc/memory/zone_table_segment.h index 8731718f61..0e728b8d07 100644 --- a/src/lib/datasrc/memory/zone_table_segment.h +++ b/src/lib/datasrc/memory/zone_table_segment.h @@ -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 diff --git a/src/lib/datasrc/memory/zone_table_segment_local.h b/src/lib/datasrc/memory/zone_table_segment_local.h index b83bd49fa2..903bbe652c 100644 --- a/src/lib/datasrc/memory/zone_table_segment_local.h +++ b/src/lib/datasrc/memory/zone_table_segment_local.h @@ -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 diff --git a/src/lib/datasrc/tests/memory/memory_client_unittest.cc b/src/lib/datasrc/tests/memory/memory_client_unittest.cc index c1c3404173..6b41d84fa7 100644 --- a/src/lib/datasrc/tests/memory/memory_client_unittest.cc +++ b/src/lib/datasrc/tests/memory/memory_client_unittest.cc @@ -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()); +} + }