BIND 10 trac2268, updated. f17651217197a8006509ef121f1a3d7a5eada1b4 [2268] Move ZoneDataLoader class out of its header

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Oct 12 04:25:44 UTC 2012


The branch, trac2268 has been updated
       via  f17651217197a8006509ef121f1a3d7a5eada1b4 (commit)
       via  e77ef46d0c78265ab0bd0ca12b541aaee2a52898 (commit)
       via  97a6125c538e5f44790b55ded90fccf363416496 (commit)
      from  2150123bd60f00e070198b9c9717eb685dd0eebe (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit f17651217197a8006509ef121f1a3d7a5eada1b4
Author: Mukund Sivaraman <muks at isc.org>
Date:   Fri Oct 12 09:54:54 2012 +0530

    [2268] Move ZoneDataLoader class out of its header

commit e77ef46d0c78265ab0bd0ca12b541aaee2a52898
Author: Mukund Sivaraman <muks at isc.org>
Date:   Fri Oct 12 09:51:30 2012 +0530

    [2268] Use loadZoneData() inside InMemoryClient

commit 97a6125c538e5f44790b55ded90fccf363416496
Author: Mukund Sivaraman <muks at isc.org>
Date:   Fri Oct 12 09:36:51 2012 +0530

    [2268] Implement loadZoneData() functions

-----------------------------------------------------------------------

Summary of changes:
 src/lib/datasrc/memory/memory_client.cc            |   74 ++--------
 src/lib/datasrc/memory/memory_client.h             |   33 +----
 src/lib/datasrc/memory/zone_data_loader.cc         |  145 ++++++++++++++++++++
 src/lib/datasrc/memory/zone_data_loader.h          |   63 +++------
 .../datasrc/tests/memory/memory_client_unittest.cc |    3 +-
 5 files changed, 177 insertions(+), 141 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/memory/memory_client.cc b/src/lib/datasrc/memory/memory_client.cc
index df15f6a..4ad87c8 100644
--- a/src/lib/datasrc/memory/memory_client.cc
+++ b/src/lib/datasrc/memory/memory_client.cc
@@ -21,7 +21,6 @@
 #include <datasrc/memory/segment_object_holder.h>
 #include <datasrc/memory/treenode_rrset.h>
 #include <datasrc/memory/zone_finder.h>
-#include <datasrc/memory/zone_data_updater.h>
 #include <datasrc/memory/zone_data_loader.h>
 
 #include <util/memory_segment_local.h>
@@ -33,9 +32,6 @@
 #include <dns/name.h>
 #include <dns/rdataclass.h>
 #include <dns/rrclass.h>
-#include <dns/masterload.h>
-
-#include <boost/bind.hpp>
 
 #include <algorithm>
 #include <utility>
@@ -84,36 +80,12 @@ InMemoryClient::~InMemoryClient() {
 }
 
 result::Result
-InMemoryClient::loadInternal(const Name& zone_name,
-                             const string& filename,
-                             boost::function<void(internal::LoadCallback)>
-                             rrset_installer)
+InMemoryClient::loadInternal(const isc::dns::Name& zone_name,
+                             const std::string& filename,
+                             ZoneData* zone_data)
 {
     SegmentObjectHolder<ZoneData, RRClass> holder(
-        mem_sgmt_, ZoneData::create(mem_sgmt_, zone_name), rrclass_);
-
-    ZoneDataLoader loader(mem_sgmt_, rrclass_, zone_name, *holder.get());
-    rrset_installer(boost::bind(&ZoneDataLoader::addFromLoad, &loader, _1));
-    // Add any last RRsets that were left
-    loader.flushNodeRRsets();
-
-    const ZoneNode* origin_node = holder.get()->getOriginNode();
-    const RdataSet* set = origin_node->getData();
-    // If the zone is NSEC3-signed, check if it has NSEC3PARAM
-    if (holder.get()->isNSEC3Signed()) {
-        if (RdataSet::find(set, RRType::NSEC3PARAM()) == NULL) {
-            LOG_WARN(logger, DATASRC_MEMORY_MEM_NO_NSEC3PARAM).
-                arg(zone_name).arg(rrclass_);
-        }
-    }
-
-    // When an empty zone file is loaded, the origin doesn't even have
-    // an SOA RR. This condition should be avoided, and hence load()
-    // should throw when an empty zone is loaded.
-    if (RdataSet::find(set, RRType::SOA()) == NULL) {
-        isc_throw(EmptyZone,
-                  "Won't create an empty zone for: " << zone_name);
-    }
+        mem_sgmt_, zone_data, rrclass_);
 
     LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEMORY_MEM_ADD_ZONE).
         arg(zone_name).arg(rrclass_);
@@ -152,32 +124,6 @@ InMemoryClient::loadInternal(const Name& zone_name,
     return (result.code);
 }
 
-namespace {
-// A wrapper for dns::masterLoad used by load() below.  Essentially it
-// converts the two callback types.  Note the mostly redundant wrapper of
-// boost::bind.  It converts function<void(ConstRRsetPtr)> to
-// function<void(RRsetPtr)> (masterLoad() expects the latter).  SunStudio
-// doesn't seem to do this conversion if we just pass 'callback'.
-void
-masterLoadWrapper(const char* const filename, const Name& origin,
-                  const RRClass& zone_class,
-                  internal::LoadCallback callback)
-{
-    masterLoad(filename, origin, zone_class, boost::bind(callback, _1));
-}
-
-// The installer called from load() for the iterator version of load().
-void
-generateRRsetFromIterator(ZoneIterator* iterator,
-                          internal::LoadCallback callback)
-{
-    ConstRRsetPtr rrset;
-    while ((rrset = iterator->getNextRRset()) != NULL) {
-        callback(rrset);
-    }
-}
-}
-
 RRClass
 InMemoryClient::getClass() const {
     return (rrclass_);
@@ -215,17 +161,17 @@ InMemoryClient::load(const isc::dns::Name& zone_name,
     LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEMORY_MEM_LOAD).arg(zone_name).
         arg(filename);
 
-    return (loadInternal(zone_name, filename,
-                         boost::bind(masterLoadWrapper, filename.c_str(),
-                                     zone_name, getClass(), _1)));
+    ZoneData* zone_data = loadZoneData(mem_sgmt_, rrclass_, zone_name,
+                                       filename);
+    return (loadInternal(zone_name, filename, zone_data));
 }
 
 result::Result
 InMemoryClient::load(const isc::dns::Name& zone_name,
                      ZoneIterator& iterator) {
-    return (loadInternal(zone_name, string(),
-                         boost::bind(generateRRsetFromIterator,
-                                     &iterator, _1)));
+    ZoneData* zone_data = loadZoneData(mem_sgmt_, rrclass_, zone_name,
+                                       iterator);
+    return (loadInternal(zone_name, string(), zone_data));
 }
 
 const std::string
diff --git a/src/lib/datasrc/memory/memory_client.h b/src/lib/datasrc/memory/memory_client.h
index 1a17613..b08e916 100644
--- a/src/lib/datasrc/memory/memory_client.h
+++ b/src/lib/datasrc/memory/memory_client.h
@@ -22,8 +22,6 @@
 #include <datasrc/memory/zone_table.h>
 #include <datasrc/memory/zone_data.h>
 
-#include <boost/function.hpp>
-
 #include <string>
 
 namespace isc {
@@ -36,14 +34,6 @@ class RRsetList;
 namespace datasrc {
 namespace memory {
 
-namespace internal {
-    // Please don't use anything from here outside the InMemoryClient
-    // implementation.
-
-    // A functor type used for loading.
-    typedef boost::function<void(isc::dns::ConstRRsetPtr)> LoadCallback;
-} // end of internal namespace
-
 /// \brief A data source client that holds all necessary data in memory.
 ///
 /// The \c InMemoryClient class provides an access to a conceptual data
@@ -87,16 +77,6 @@ public:
     /// \return The number of zones stored in the client.
     virtual unsigned int getZoneCount() const;
 
-    /// \brief Zone is empty exception.
-    ///
-    /// This is thrown if we have an empty zone created as a result of
-    /// load().
-    struct EmptyZone : public InvalidParameter {
-        EmptyZone(const char* file, size_t line, const char* what) :
-            InvalidParameter(file, line, what)
-        {}
-    };
-
     /// \brief Load zone from masterfile.
     ///
     /// This loads data from masterfile specified by filename. It replaces
@@ -200,18 +180,11 @@ private:
     typedef DomainTree<std::string> FileNameTree;
     typedef DomainTreeNode<std::string> FileNameNode;
 
-    // Common process for zone load.
-    // rrset_installer is a functor that takes another functor as an argument,
-    // and expected to call the latter for each RRset of the zone.  How the
-    // sequence of the RRsets is generated depends on the internal
-    // details  of the loader: either from a textual master file or from
-    // another data source.
-    // filename is the file name of the master file or empty if the zone is
-    // loaded from another data source.
+    // Common process for zone load. Registers filename internally and
+    // adds the ZoneData to the ZoneTable.
     result::Result loadInternal(const isc::dns::Name& zone_name,
 				const std::string& filename,
-				boost::function<void(internal::LoadCallback)>
-				rrset_installer);
+				ZoneData* zone_data);
 
     util::MemorySegment& mem_sgmt_;
     const isc::dns::RRClass rrclass_;
diff --git a/src/lib/datasrc/memory/zone_data_loader.cc b/src/lib/datasrc/memory/zone_data_loader.cc
index 86dc6da..cfb05d5 100644
--- a/src/lib/datasrc/memory/zone_data_loader.cc
+++ b/src/lib/datasrc/memory/zone_data_loader.cc
@@ -13,10 +13,19 @@
 // PERFORMANCE OF THIS SOFTWARE.
 
 #include <datasrc/memory/zone_data_loader.h>
+#include <datasrc/memory/zone_data_updater.h>
+#include <datasrc/memory/logger.h>
+#include <datasrc/memory/segment_object_holder.h>
 
 #include <dns/rdataclass.h>
+#include <dns/rrset.h>
+#include <dns/masterload.h>
 
 #include <boost/foreach.hpp>
+#include <boost/bind.hpp>
+#include <boost/noncopyable.hpp>
+
+#include <map>
 
 using namespace isc::dns;
 using namespace isc::dns::rdata;
@@ -25,6 +34,52 @@ namespace isc {
 namespace datasrc {
 namespace memory {
 
+using detail::SegmentObjectHolder;
+
+// A helper internal class for \c loadZoneData().  make it non-copyable
+// to avoid accidental copy.
+//
+// The current internal implementation expects that both a normal
+// (non RRSIG) RRset and (when signed) its RRSIG are added at once.
+// Also in the current implementation, the input sequence of RRsets
+// are grouped with their owner name (so once a new owner name is encountered,
+// no subsequent RRset has the previous owner name), but the ordering
+// in the same group is not fixed.  So we hold all RRsets of the same
+// owner name in node_rrsets_ and node_rrsigsets_, and add the matching
+// pairs of RRsets to the zone when we see a new owner name.
+//
+// The caller is responsible for adding the RRsets of the last group
+// in the input sequence by explicitly calling flushNodeRRsets() at the
+// end.  It's cleaner and more robust if we let the destructor of this class
+// do it, but since we cannot guarantee the adding operation is exception free,
+// we don't choose that option to maintain the common expectation for
+// destructors.
+class ZoneDataLoader : boost::noncopyable {
+public:
+    ZoneDataLoader(util::MemorySegment& mem_sgmt,
+                   const isc::dns::RRClass rrclass,
+                   const isc::dns::Name& zone_name, ZoneData& zone_data) :
+        updater_(mem_sgmt, rrclass, zone_name, zone_data)
+    {}
+
+    void addFromLoad(const isc::dns::ConstRRsetPtr& rrset);
+    void flushNodeRRsets();
+
+private:
+    typedef std::map<isc::dns::RRType, isc::dns::ConstRRsetPtr> NodeRRsets;
+    typedef NodeRRsets::value_type NodeRRsetsVal;
+
+    // A helper to identify the covered type of an RRSIG.
+    static isc::dns::RRType getCoveredType
+        (const isc::dns::ConstRRsetPtr& sig_rrset);
+    const isc::dns::Name& getCurrentName() const;
+
+private:
+    NodeRRsets node_rrsets_;
+    NodeRRsets node_rrsigsets_;
+    ZoneDataUpdater updater_;
+};
+
 void
 ZoneDataLoader::addFromLoad(const ConstRRsetPtr& rrset) {
     // If we see a new name, flush the temporary holders, adding the
@@ -103,6 +158,96 @@ ZoneDataLoader::getCurrentName() const {
     return (node_rrsigsets_.begin()->second->getName());
 }
 
+namespace { // unnamed namespace
+
+// A functor type used for loading.
+typedef boost::function<void(isc::dns::ConstRRsetPtr)> LoadCallback;
+
+ZoneData*
+loadZoneDataInternal(util::MemorySegment& mem_sgmt,
+                     const isc::dns::RRClass rrclass,
+                     const Name& zone_name,
+                     boost::function<void(LoadCallback)> rrset_installer)
+{
+    SegmentObjectHolder<ZoneData, RRClass> holder(
+        mem_sgmt, ZoneData::create(mem_sgmt, zone_name), rrclass);
+
+    ZoneDataLoader loader(mem_sgmt, rrclass, zone_name, *holder.get());
+    rrset_installer(boost::bind(&ZoneDataLoader::addFromLoad, &loader, _1));
+    // Add any last RRsets that were left
+    loader.flushNodeRRsets();
+
+    const ZoneNode* origin_node = holder.get()->getOriginNode();
+    const RdataSet* rdataset = origin_node->getData();
+    // If the zone is NSEC3-signed, check if it has NSEC3PARAM
+    if (holder.get()->isNSEC3Signed()) {
+        if (RdataSet::find(rdataset, RRType::NSEC3PARAM()) == NULL) {
+            LOG_WARN(logger, DATASRC_MEMORY_MEM_NO_NSEC3PARAM).
+                arg(zone_name).arg(rrclass);
+        }
+    }
+
+    // When an empty zone file is loaded, the origin doesn't even have
+    // an SOA RR. This condition should be avoided, and hence load()
+    // should throw when an empty zone is loaded.
+    if (RdataSet::find(rdataset, RRType::SOA()) == NULL) {
+        isc_throw(EmptyZone,
+                  "Won't create an empty zone for: " << zone_name);
+    }
+
+    return (holder.release());
+}
+
+// A wrapper for dns::masterLoad used by load() below.  Essentially it
+// converts the two callback types.  Note the mostly redundant wrapper of
+// boost::bind.  It converts function<void(ConstRRsetPtr)> to
+// function<void(RRsetPtr)> (masterLoad() expects the latter).  SunStudio
+// doesn't seem to do this conversion if we just pass 'callback'.
+void
+masterLoadWrapper(const char* const filename, const Name& origin,
+                  const RRClass& zone_class,
+                  LoadCallback callback)
+{
+    masterLoad(filename, origin, zone_class, boost::bind(callback, _1));
+}
+
+// The installer called from load() for the iterator version of load().
+void
+generateRRsetFromIterator(ZoneIterator* iterator,
+                          LoadCallback callback)
+{
+    ConstRRsetPtr rrset;
+    while ((rrset = iterator->getNextRRset()) != NULL) {
+        callback(rrset);
+    }
+}
+
+} // end of unnamed namespace
+
+ZoneData*
+loadZoneData(util::MemorySegment& mem_sgmt,
+             const isc::dns::RRClass rrclass,
+             const isc::dns::Name& zone_name,
+             const std::string& zone_file)
+{
+     return (loadZoneDataInternal(mem_sgmt, rrclass, zone_name,
+                                 boost::bind(masterLoadWrapper,
+                                             zone_file.c_str(),
+                                             zone_name, rrclass,
+                                             _1)));
+}
+
+ZoneData*
+loadZoneData(util::MemorySegment& mem_sgmt,
+             const isc::dns::RRClass rrclass,
+             const isc::dns::Name& zone_name,
+             ZoneIterator& iterator)
+{
+    return (loadZoneDataInternal(mem_sgmt, rrclass, zone_name,
+                                 boost::bind(generateRRsetFromIterator,
+                                             &iterator, _1)));
+}
+
 } // namespace memory
 } // namespace datasrc
 } // namespace isc
diff --git a/src/lib/datasrc/memory/zone_data_loader.h b/src/lib/datasrc/memory/zone_data_loader.h
index 2d1bdbb..08f590d 100644
--- a/src/lib/datasrc/memory/zone_data_loader.h
+++ b/src/lib/datasrc/memory/zone_data_loader.h
@@ -15,64 +15,35 @@
 #ifndef DATASRC_ZONE_DATA_LOADER_H
 #define DATASRC_ZONE_DATA_LOADER_H 1
 
-#include <datasrc/memory/zone_data_updater.h>
-
 #include <datasrc/memory/zone_data.h>
+#include <datasrc/iterator.h>
 #include <dns/name.h>
 #include <dns/rrclass.h>
-#include <dns/rrset.h>
 #include <util/memory_segment.h>
 
-#include <boost/noncopyable.hpp>
-#include <map>
-
 namespace isc {
 namespace datasrc {
 namespace memory {
 
-// A helper internal class for load().  make it non-copyable to avoid
-// accidental copy.
-//
-// The current internal implementation expects that both a normal
-// (non RRSIG) RRset and (when signed) its RRSIG are added at once.
-// Also in the current implementation, the input sequence of RRsets
-// are grouped with their owner name (so once a new owner name is encountered,
-// no subsequent RRset has the previous owner name), but the ordering
-// in the same group is not fixed.  So we hold all RRsets of the same
-// owner name in node_rrsets_ and node_rrsigsets_, and add the matching
-// pairs of RRsets to the zone when we see a new owner name.
-//
-// The caller is responsible for adding the RRsets of the last group
-// in the input sequence by explicitly calling flushNodeRRsets() at the
-// end.  It's cleaner and more robust if we let the destructor of this class
-// do it, but since we cannot guarantee the adding operation is exception free,
-// we don't choose that option to maintain the common expectation for
-// destructors.
-class ZoneDataLoader : boost::noncopyable {
-public:
-    ZoneDataLoader(util::MemorySegment& mem_sgmt,
-                   const isc::dns::RRClass rrclass,
-                   const isc::dns::Name& zone_name, ZoneData& zone_data) :
-        updater_(mem_sgmt, rrclass, zone_name, zone_data)
+/// \brief Zone is empty exception.
+///
+/// This is thrown if we have an empty zone created during
+/// \c loadZoneData().
+struct EmptyZone : public InvalidParameter {
+    EmptyZone(const char* file, size_t line, const char* what) :
+        InvalidParameter(file, line, what)
     {}
+};
 
-    void addFromLoad(const isc::dns::ConstRRsetPtr& rrset);
-    void flushNodeRRsets();
-
-private:
-    typedef std::map<isc::dns::RRType, isc::dns::ConstRRsetPtr> NodeRRsets;
-    typedef NodeRRsets::value_type NodeRRsetsVal;
-
-    // A helper to identify the covered type of an RRSIG.
-    static isc::dns::RRType getCoveredType
-        (const isc::dns::ConstRRsetPtr& sig_rrset);
-    const isc::dns::Name& getCurrentName() const;
+ZoneData* loadZoneData(util::MemorySegment& mem_sgmt,
+		       const isc::dns::RRClass rrclass,
+		       const isc::dns::Name& zone_name,
+		       const std::string& zone_file);
 
-private:
-    NodeRRsets node_rrsets_;
-    NodeRRsets node_rrsigsets_;
-    ZoneDataUpdater updater_;
-};
+ZoneData* loadZoneData(util::MemorySegment& mem_sgmt,
+		       const isc::dns::RRClass rrclass,
+		       const isc::dns::Name& zone_name,
+		       ZoneIterator& iterator);
 
 } // namespace memory
 } // namespace datasrc
diff --git a/src/lib/datasrc/tests/memory/memory_client_unittest.cc b/src/lib/datasrc/tests/memory/memory_client_unittest.cc
index 74d7aa8..4b4341a 100644
--- a/src/lib/datasrc/tests/memory/memory_client_unittest.cc
+++ b/src/lib/datasrc/tests/memory/memory_client_unittest.cc
@@ -30,6 +30,7 @@
 #include <datasrc/memory/zone_data.h>
 #include <datasrc/memory/zone_table.h>
 #include <datasrc/memory/zone_data_updater.h>
+#include <datasrc/memory/zone_data_loader.h>
 #include <datasrc/memory/memory_client.h>
 
 #include <testutils/dnsmessage_test.h>
@@ -298,7 +299,7 @@ TEST_F(MemoryClientTest, loadEmptyZoneFileThrows) {
 
     EXPECT_THROW(client_->load(Name("."),
                                TEST_DATA_DIR "/empty.zone"),
-                 InMemoryClient::EmptyZone);
+                 EmptyZone);
 
     EXPECT_EQ(0, client_->getZoneCount());
 



More information about the bind10-changes mailing list