[svn] commit: r4116 - in /branches/trac467/src: bin/auth/ bin/auth/tests/ lib/datasrc/ lib/datasrc/tests/ lib/testutils/testdata/

BIND 10 source code commits bind10-changes at lists.isc.org
Sat Jan 1 03:58:26 UTC 2011


Author: jinmei
Date: Sat Jan  1 03:58:04 2011
New Revision: 4116

Log:
initial implementaiton for trac #456: reloding in memory zone

Added:
    branches/trac467/src/bin/auth/command.cc
    branches/trac467/src/bin/auth/command.h
    branches/trac467/src/bin/auth/tests/command_unittest.cc
Modified:
    branches/trac467/src/bin/auth/Makefile.am
    branches/trac467/src/bin/auth/auth.spec.pre.in
    branches/trac467/src/bin/auth/auth_srv.cc
    branches/trac467/src/bin/auth/auth_srv.h
    branches/trac467/src/bin/auth/main.cc
    branches/trac467/src/bin/auth/tests/Makefile.am
    branches/trac467/src/bin/auth/tests/auth_srv_unittest.cc
    branches/trac467/src/lib/datasrc/memory_datasrc.cc
    branches/trac467/src/lib/datasrc/memory_datasrc.h
    branches/trac467/src/lib/datasrc/tests/memory_datasrc_unittest.cc
    branches/trac467/src/lib/datasrc/zonetable.cc
    branches/trac467/src/lib/datasrc/zonetable.h
    branches/trac467/src/lib/testutils/testdata/Makefile.am

Modified: branches/trac467/src/bin/auth/Makefile.am
==============================================================================
--- branches/trac467/src/bin/auth/Makefile.am (original)
+++ branches/trac467/src/bin/auth/Makefile.am Sat Jan  1 03:58:04 2011
@@ -40,6 +40,7 @@
 b10_auth_SOURCES += auth_srv.cc auth_srv.h
 b10_auth_SOURCES += change_user.cc change_user.h
 b10_auth_SOURCES += config.cc config.h
+b10_auth_SOURCES += command.cc command.h
 b10_auth_SOURCES += common.h
 b10_auth_SOURCES += statistics.cc statistics.h
 b10_auth_SOURCES += main.cc

Modified: branches/trac467/src/bin/auth/auth.spec.pre.in
==============================================================================
--- branches/trac467/src/bin/auth/auth.spec.pre.in (original)
+++ branches/trac467/src/bin/auth/auth.spec.pre.in Sat Jan  1 03:58:04 2011
@@ -64,6 +64,24 @@
         "command_name": "sendstats",
         "command_description": "Send data to a statistics module at once",
         "command_args": []
+      },
+      {
+        "command_name": "loadzone",
+        "command_description": "TBD",
+        "command_args": [
+          {
+            "item_name": "class", "item_type": "string",
+            "item_optional": true, "item_default": "IN"
+          },
+	  {
+            "item_name": "origin", "item_type": "string",
+            "item_optional": false, "item_default": ""
+          },
+	  {
+            "item_name": "datasrc", "item_type": "string",
+            "item_optional": true, "item_default": "memory"
+          }
+        ]
       }
     ]
   }

Modified: branches/trac467/src/bin/auth/auth_srv.cc
==============================================================================
--- branches/trac467/src/bin/auth/auth_srv.cc (original)
+++ branches/trac467/src/bin/auth/auth_srv.cc Sat Jan  1 03:58:04 2011
@@ -195,10 +195,19 @@
 
 AuthSrv::AuthSrv(const bool use_cache, AbstractXfroutClient& xfrout_client) :
     impl_(new AuthSrvImpl(use_cache, xfrout_client)),
+    io_service_(NULL),
     checkin_(new ConfigChecker(this)),
     dns_lookup_(new MessageLookup(this)),
     dns_answer_(new MessageAnswer(this))
 {}
+
+void
+AuthSrv::stop() {
+    if (io_service_ == NULL) {
+        throw FatalError("Assumption failure; server is stopped before start");
+    }
+    io_service_->stop();
+}
 
 AuthSrv::~AuthSrv() {
     delete impl_;
@@ -299,8 +308,8 @@
     return (impl_->config_session_);
 }
 
-AuthSrv::ConstMemoryDataSrcPtr
-AuthSrv::getMemoryDataSrc(const RRClass& rrclass) const {
+AuthSrv::MemoryDataSrcPtr
+AuthSrv::getMemoryDataSrc(const RRClass& rrclass) {
     // XXX: for simplicity, we only support the IN class right now.
     if (rrclass != impl_->memory_datasrc_class_) {
         isc_throw(InvalidParameter,

Modified: branches/trac467/src/bin/auth/auth_srv.h
==============================================================================
--- branches/trac467/src/bin/auth/auth_srv.h (original)
+++ branches/trac467/src/bin/auth/auth_srv.h Sat Jan  1 03:58:04 2011
@@ -87,6 +87,15 @@
     ~AuthSrv();
     //@}
 
+    /// Stop the server.
+    ///
+    /// It stops the internal event loop of the server and subsequently
+    /// returns the control to the top level context.
+    /// The server must have been associated with an \c IOService object;
+    /// otherwise an exception of \c FatalError will be thrown.
+    /// This method never throws an exception otherwise.
+    void stop();
+
     /// \brief Process an incoming DNS message, then signal 'server' to resume 
     ///
     /// A DNS query (or other message) has been received by a \c DNSServer
@@ -265,8 +274,7 @@
     /// \param rrclass The RR class of the requested in-memory data source.
     /// \return A pointer to the in-memory data source, if configured;
     /// otherwise NULL.
-    ConstMemoryDataSrcPtr
-    getMemoryDataSrc(const isc::dns::RRClass& rrclass) const;
+    MemoryDataSrcPtr getMemoryDataSrc(const isc::dns::RRClass& rrclass);
 
     /// Sets or replaces the in-memory data source of the specified RR class.
     ///

Modified: branches/trac467/src/bin/auth/main.cc
==============================================================================
--- branches/trac467/src/bin/auth/main.cc (original)
+++ branches/trac467/src/bin/auth/main.cc Sat Jan  1 03:58:04 2011
@@ -42,6 +42,7 @@
 #include <auth/spec_config.h>
 #include <auth/common.h>
 #include <auth/config.h>
+#include <auth/command.h>
 #include <auth/change_user.h>
 #include <auth/auth_srv.h>
 #include <asiolink/asiolink.h>
@@ -80,23 +81,8 @@
 
 ConstElementPtr
 my_command_handler(const string& command, ConstElementPtr args) {
-    ConstElementPtr answer = createAnswer();
-
-    if (command == "print_message") {
-        cout << args << endl;
-        /* let's add that message to our answer as well */
-        answer = createAnswer(0, args);
-    } else if (command == "shutdown") {
-        io_service.stop();
-    } else if (command == "sendstats") {
-        if (verbose_mode) {
-            cerr << "[b10-auth] command 'sendstats' received" << endl;
-        }
-        assert(auth_server != NULL);
-        auth_server->submitStatistics();
-    }
-
-    return (answer);
+    assert(auth_server != NULL);
+    return (execAuthServerCommand(*auth_server, command, args));
 }
 
 void

Modified: branches/trac467/src/bin/auth/tests/Makefile.am
==============================================================================
--- branches/trac467/src/bin/auth/tests/Makefile.am (original)
+++ branches/trac467/src/bin/auth/tests/Makefile.am Sat Jan  1 03:58:04 2011
@@ -2,8 +2,9 @@
 AM_CPPFLAGS += -I$(top_builddir)/src/lib/dns -I$(top_srcdir)/src/bin
 AM_CPPFLAGS += -I$(top_builddir)/src/lib/cc
 AM_CPPFLAGS += $(BOOST_INCLUDES)
-AM_CPPFLAGS += -DTEST_DATA_DIR=\"$(top_srcdir)/src/lib/testutils/testdata\"
+AM_CPPFLAGS += -DTEST_DATA_DIR=\"$(abs_top_srcdir)/src/lib/testutils/testdata\"
 AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/lib/testutils/testdata\"
+AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\"
 
 AM_CXXFLAGS = $(B10_CXXFLAGS)
 
@@ -22,9 +23,11 @@
 run_unittests_SOURCES += ../query.h ../query.cc
 run_unittests_SOURCES += ../change_user.h ../change_user.cc
 run_unittests_SOURCES += ../config.h ../config.cc
+run_unittests_SOURCES += ../command.h ../command.cc
 run_unittests_SOURCES += ../statistics.h ../statistics.cc
 run_unittests_SOURCES += auth_srv_unittest.cc
 run_unittests_SOURCES += config_unittest.cc
+run_unittests_SOURCES += command_unittest.cc
 run_unittests_SOURCES += query_unittest.cc
 run_unittests_SOURCES += change_user_unittest.cc
 run_unittests_SOURCES += statistics_unittest.cc

Modified: branches/trac467/src/bin/auth/tests/auth_srv_unittest.cc
==============================================================================
--- branches/trac467/src/bin/auth/tests/auth_srv_unittest.cc (original)
+++ branches/trac467/src/bin/auth/tests/auth_srv_unittest.cc Sat Jan  1 03:58:04 2011
@@ -30,8 +30,10 @@
 
 #include <datasrc/memory_datasrc.h>
 #include <auth/auth_srv.h>
+#include <auth/common.h>
+#include <auth/statistics.h>
+
 #include <testutils/srv_unittest.h>
-#include <auth/statistics.h>
 
 using namespace isc::cc;
 using namespace isc::dns;
@@ -628,4 +630,13 @@
                                        response_obuffer, &dnsserv),
                  isc::Unexpected);
 }
-}
+
+TEST_F(AuthSrvTest, stop) {
+    // normal case is covered in command_unittest.cc.  we should primarily
+    // test it here, but the current design of the stop test takes time,
+    // so we consolidate the cases in the command tests.
+
+    // stop before start is prohibited.
+    EXPECT_THROW(server.stop(), FatalError);
+}
+}

Modified: branches/trac467/src/lib/datasrc/memory_datasrc.cc
==============================================================================
--- branches/trac467/src/lib/datasrc/memory_datasrc.cc (original)
+++ branches/trac467/src/lib/datasrc/memory_datasrc.cc Sat Jan  1 03:58:04 2011
@@ -40,6 +40,7 @@
     // Information about the zone
     RRClass zone_class_;
     Name origin_;
+    string file_name_;
 
     // Some type aliases
     /*
@@ -275,8 +276,19 @@
     masterLoad(filename.c_str(), getOrigin(), getClass(),
         boost::bind(&MemoryZoneImpl::addFromLoad, impl_, _1, &tmp));
     // If it went well, put it inside
+    impl_->file_name_ = filename;
     tmp.swap(impl_->domains_);
     // And let the old data die with tmp
+}
+
+void
+MemoryZone::swap(MemoryZone& zone) {
+    std::swap(impl_, zone.impl_);
+}
+
+const string
+MemoryZone::getFileName() const {
+    return (impl_->file_name_);
 }
 
 /// Implementation details for \c MemoryDataSrc hidden from the public

Modified: branches/trac467/src/lib/datasrc/memory_datasrc.h
==============================================================================
--- branches/trac467/src/lib/datasrc/memory_datasrc.h (original)
+++ branches/trac467/src/lib/datasrc/memory_datasrc.h Sat Jan  1 03:58:04 2011
@@ -15,6 +15,8 @@
 #ifndef __MEMORY_DATA_SOURCE_H
 #define __MEMORY_DATA_SOURCE_H 1
 
+#include <string>
+
 #include <datasrc/zonetable.h>
 
 namespace isc {
@@ -98,6 +100,20 @@
         { }
     };
 
+    /// Return the master file name of the zone
+    ///
+    /// This method returns the name of the zone's master file to be loaded.
+    /// The returned string will be an empty unless the zone has successfully
+    /// loaded a zone.
+    ///
+    /// This method should normally not throw an exception.  But the creation
+    /// of the return string may involve a resource allocation, and if it
+    /// fails, the corresponding standard exception will be thrown.
+    ///
+    /// \return The name of the zone file loaded in the zone, or an empty
+    /// string if the zone hasn't loaded any file.
+    const std::string getFileName() const;
+
     /// \brief Load zone from masterfile.
     ///
     /// This loads data from masterfile specified by filename. It replaces
@@ -122,6 +138,15 @@
     ///     This will probably be needed when a better implementation of
     ///     configuration reloading is written.
     void load(const std::string& filename);
+
+    /// Exchanges the content of \c this zone with that of the given \c zone.
+    ///
+    /// This method never throws an exception.
+    ///
+    /// \param zone Another \c MemoryZone object which is to be swapped with
+    /// \c this zone.
+    void swap(MemoryZone& zone);
+
 private:
     /// \name Hidden private data
     //@{
@@ -158,10 +183,6 @@
 /// The findZone() method takes a domain name and returns the best matching \c
 /// MemoryZone in the form of (Boost) shared pointer, so that it can provide
 /// the general interface for all data sources.
-///
-/// Currently, \c FindResult::zone is immutable for safety.
-/// In future versions we may want to make it changeable.  For example,
-/// we may want to allow configuration update on an existing zone.
 class MemoryDataSrc {
 public:
     /// \brief A helper structure to represent the search result of
@@ -180,11 +201,11 @@
     /// See the description of \c find() for the semantics of the member
     /// variables.
     struct FindResult {
-        FindResult(result::Result param_code, const ConstZonePtr param_zone) :
+        FindResult(result::Result param_code, const ZonePtr param_zone) :
             code(param_code), zone(param_zone)
         {}
         const result::Result code;
-        const ConstZonePtr zone;
+        const ZonePtr zone;
     };
 
     ///

Modified: branches/trac467/src/lib/datasrc/tests/memory_datasrc_unittest.cc
==============================================================================
--- branches/trac467/src/lib/datasrc/tests/memory_datasrc_unittest.cc (original)
+++ branches/trac467/src/lib/datasrc/tests/memory_datasrc_unittest.cc Sat Jan  1 03:58:04 2011
@@ -405,4 +405,58 @@
         MasterLoadError);
 }
 
-}
+TEST_F(MemoryZoneTest, swap) {
+    // build one zone with some data
+    MemoryZone zone1(class_, origin_);
+    EXPECT_EQ(result::SUCCESS, zone1.add(rr_ns_));
+    EXPECT_EQ(result::SUCCESS, zone1.add(rr_ns_aaaa_));
+
+    // build another zone of a different RR class with some other data
+    const Name other_origin("version.bind");
+    ASSERT_NE(origin_, other_origin); // make sure these two are different
+    MemoryZone zone2(RRClass::CH(), other_origin);
+    EXPECT_EQ(result::SUCCESS,
+              zone2.add(RRsetPtr(new RRset(Name("version.bind"),
+                                           RRClass::CH(), RRType::TXT(),
+                                           RRTTL(0)))));
+
+    zone1.swap(zone2);
+    EXPECT_EQ(other_origin, zone1.getOrigin());
+    EXPECT_EQ(origin_, zone2.getOrigin());
+    EXPECT_EQ(RRClass::CH(), zone1.getClass());
+    EXPECT_EQ(RRClass::IN(), zone2.getClass());
+    // make sure the zone data is swapped, too
+    findTest(origin_, RRType::NS(), Zone::NXDOMAIN, false, ConstRRsetPtr(),
+             &zone1);
+    findTest(other_origin, RRType::TXT(), Zone::SUCCESS, false,
+             ConstRRsetPtr(), &zone1);
+    findTest(origin_, RRType::NS(), Zone::SUCCESS, false, ConstRRsetPtr(),
+             &zone2);
+    findTest(other_origin, RRType::TXT(), Zone::NXDOMAIN, false,
+             ConstRRsetPtr(), &zone2);
+}
+
+TEST_F(MemoryZoneTest, getFileName) {
+    // for an empty zone the file name should also be empty.
+    EXPECT_TRUE(zone_.getFileName().empty());
+
+    // if loading a zone fails the file name shouldn't be set.
+    EXPECT_THROW(zone_.load(TEST_DATA_DIR "/root.zone"), MasterLoadError);
+    EXPECT_TRUE(zone_.getFileName().empty());
+
+    // after a successful load, the specified file name should be set
+    MemoryZone rootzone(class_, Name("."));
+    EXPECT_NO_THROW(rootzone.load(TEST_DATA_DIR "/root.zone"));
+    EXPECT_EQ(TEST_DATA_DIR "/root.zone", rootzone.getFileName());
+    // overriding load, which will fail
+    EXPECT_THROW(rootzone.load(TEST_DATA_DIR "/duplicate_rrset.zone"),
+                 MasterLoadError);
+    // the file name should be intact.
+    EXPECT_EQ(TEST_DATA_DIR "/root.zone", rootzone.getFileName());
+
+    // After swap, file names should also be swapped.
+    zone_.swap(rootzone);
+    EXPECT_EQ(TEST_DATA_DIR "/root.zone", zone_.getFileName());
+    EXPECT_TRUE(rootzone.getFileName().empty());
+}
+}

Modified: branches/trac467/src/lib/datasrc/zonetable.cc
==============================================================================
--- branches/trac467/src/lib/datasrc/zonetable.cc (original)
+++ branches/trac467/src/lib/datasrc/zonetable.cc Sat Jan  1 03:58:04 2011
@@ -85,12 +85,12 @@
                 break;
             // We have no data there, so translate the pointer to NULL as well
             case ZoneTree::NOTFOUND:
-                return (FindResult(result::NOTFOUND, ConstZonePtr()));
+                return (FindResult(result::NOTFOUND, ZonePtr()));
             // Can Not Happen
             default:
                 assert(0);
                 // Because of warning
-                return (FindResult(result::NOTFOUND, ConstZonePtr()));
+                return (FindResult(result::NOTFOUND, ZonePtr()));
         }
 
         // Can Not Happen (remember, NOTFOUND is handled)

Modified: branches/trac467/src/lib/datasrc/zonetable.h
==============================================================================
--- branches/trac467/src/lib/datasrc/zonetable.h (original)
+++ branches/trac467/src/lib/datasrc/zonetable.h Sat Jan  1 03:58:04 2011
@@ -41,11 +41,11 @@
 class ZoneTable {
 public:
     struct FindResult {
-        FindResult(result::Result param_code, const ConstZonePtr param_zone) :
+        FindResult(result::Result param_code, const ZonePtr param_zone) :
             code(param_code), zone(param_zone)
         {}
         const result::Result code;
-        const ConstZonePtr zone;
+        const ZonePtr zone;
     };
     ///
     /// \name Constructors and Destructor.

Modified: branches/trac467/src/lib/testutils/testdata/Makefile.am
==============================================================================
--- branches/trac467/src/lib/testutils/testdata/Makefile.am (original)
+++ branches/trac467/src/lib/testutils/testdata/Makefile.am Sat Jan  1 03:58:04 2011
@@ -1,4 +1,4 @@
-CLEANFILES = *.wire
+CLEANFILES = *.wire *.copied
 
 BUILT_SOURCES = badExampleQuery_fromWire.wire examplequery_fromWire.wire
 BUILT_SOURCES += iqueryresponse_fromWire.wire multiquestion_fromWire.wire
@@ -25,5 +25,11 @@
 EXTRA_DIST += example.com
 EXTRA_DIST += example.sqlite3
 
+EXTRA_DIST += test1.zone.in
+EXTRA_DIST += test1-new.zone.in
+EXTRA_DIST += test1-broken.zone.in
+EXTRA_DIST += test2.zone.in
+EXTRA_DIST += test2-new.zone.in
+
 .spec.wire:
 	$(abs_top_builddir)/src/lib/dns/tests/testdata/gen-wiredata.py -o $@ $<




More information about the bind10-changes mailing list