BIND 10 master, updated. 8fa723bfd4e41dca1c398dfc1350b419d50facea Merge branch 'master' into trac2106

BIND 10 source code commits bind10-changes at lists.isc.org
Sun Jul 29 20:30:38 UTC 2012


The branch, master has been updated
       via  8fa723bfd4e41dca1c398dfc1350b419d50facea (commit)
       via  72f8c0cf002334f1cb9a63be785c018a310750ef (commit)
       via  866fcdbc687f8d1350397d8f8c7f10f524054d81 (commit)
       via  a539dcc9f4f0f6d334fbcf0f0f36b3182547aca5 (commit)
       via  e50cd96f5079816c9e951cebaf4844317dedcbe3 (commit)
       via  97873bf89cc93362dde0dd68e3201723a80e1c4c (commit)
      from  0ae269325e8667b8f91555b655d001b3a5b217ae (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 8fa723bfd4e41dca1c398dfc1350b419d50facea
Merge: 72f8c0c 0ae2693
Author: Mukund Sivaraman <muks at isc.org>
Date:   Mon Jul 30 01:39:15 2012 +0530

    Merge branch 'master' into trac2106

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

Summary of changes:
 src/lib/datasrc/memory_datasrc.cc        |    3 +-
 src/lib/datasrc/rbtree.h                 |   67 ++++++++++++++++++++++--------
 src/lib/datasrc/tests/rbtree_unittest.cc |   43 +++++++++++++++----
 3 files changed, 86 insertions(+), 27 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/memory_datasrc.cc b/src/lib/datasrc/memory_datasrc.cc
index 372141a..90b5917 100644
--- a/src/lib/datasrc/memory_datasrc.cc
+++ b/src/lib/datasrc/memory_datasrc.cc
@@ -452,7 +452,8 @@ ZoneData::findNode(const Name& name, RBTreeNodeChain<Domain>& node_path,
     FindState state((options & ZoneFinder::FIND_GLUE_OK) != 0);
 
     const DomainTree::Result result =
-        domains_.find(name, &node, node_path, cutCallback, &state);
+        domains_.find(LabelSequence(name), &node, node_path,
+                      cutCallback, &state);
     const unsigned int zonecut_flag =
         (state.zonecut_node_ != NULL) ? FindNodeResult::FIND_ZONECUT : 0;
     if (result == DomainTree::EXACTMATCH) {
diff --git a/src/lib/datasrc/rbtree.h b/src/lib/datasrc/rbtree.h
index 771f23e..38086db 100644
--- a/src/lib/datasrc/rbtree.h
+++ b/src/lib/datasrc/rbtree.h
@@ -948,7 +948,8 @@ public:
     /// Acts as described in the \ref find section.
     Result find(const isc::dns::Name& name, RBNode<T>** node) const {
         RBTreeNodeChain<T> node_path;
-        return (find<void*>(name, node, node_path, NULL, NULL));
+        const isc::dns::LabelSequence ls(name);
+        return (find<void*>(ls, node, node_path, NULL, NULL));
     }
 
     /// \brief Simple find returning immutable node.
@@ -958,7 +959,8 @@ public:
     Result find(const isc::dns::Name& name, const RBNode<T>** node) const {
         RBTreeNodeChain<T> node_path;
         RBNode<T> *target_node = NULL;
-        Result ret = (find<void*>(name, &target_node, node_path, NULL, NULL));
+        const isc::dns::LabelSequence ls(name);
+        Result ret = (find<void*>(ls, &target_node, node_path, NULL, NULL));
         if (ret != NOTFOUND) {
             *node = target_node;
         }
@@ -971,7 +973,8 @@ public:
     Result find(const isc::dns::Name& name, RBNode<T>** node,
                 RBTreeNodeChain<T>& node_path) const
     {
-        return (find<void*>(name, node, node_path, NULL, NULL));
+        const isc::dns::LabelSequence ls(name);
+        return (find<void*>(ls, node, node_path, NULL, NULL));
     }
 
     /// \brief Simple find returning immutable node, with node_path tracking
@@ -982,14 +985,36 @@ public:
                 RBTreeNodeChain<T>& node_path) const
     {
         RBNode<T> *target_node = NULL;
-        Result ret = (find<void*>(name, &target_node, node_path, NULL, NULL));
+        const isc::dns::LabelSequence ls(name);
+        Result ret = (find<void*>(ls, &target_node, node_path, NULL, NULL));
         if (ret != NOTFOUND) {
             *node = target_node;
         }
         return (ret);
     }
 
-    /// \brief Find with callback and node chain.
+    /// \brief Simple find returning immutable node.
+    ///
+    /// Acts as described in the \ref find section, but returns immutable
+    /// node pointer.
+    template <typename CBARG>
+    Result find(const isc::dns::Name& name,
+                const RBNode<T>** node,
+                RBTreeNodeChain<T>& node_path,
+                bool (*callback)(const RBNode<T>&, CBARG),
+                CBARG callback_arg) const
+    {
+        RBNode<T>* target_node = NULL;
+        const isc::dns::LabelSequence ls(name);
+        Result ret = find(ls, &target_node, node_path, callback,
+                          callback_arg);
+        if (ret != NOTFOUND) {
+            *node = target_node;
+        }
+        return (ret);
+    }
+
+    /// \brief Find with callback and node chain
     /// \anchor callback
     ///
     /// This version of \c find() is specifically designed for the backend
@@ -1001,6 +1026,17 @@ public:
     /// the way from root down the tree) a marked node on the way down through
     /// the domain namespace (see \c RBNode::FLAG_CALLBACK).
     ///
+    /// Also, this version takes a \c LabelSequence object, not a \c Name
+    /// object to be as efficient as possible; operations on the former
+    /// needed for the search are generally much more efficient than those
+    /// for the latter.  Since \c Name objects are more commonly used
+    /// in other parts of the implementation, other versions take a \c Name
+    /// and convert it to \c LabelSequence.  This conversion is cheap,
+    /// while the other direction isn't, and since there would be cases
+    /// where an implementation primarily handles \c LabelSequence objects
+    /// as an efficient representation of names, it would make most sense
+    /// to provide the interface that takes \c LabelSequence.
+    ///
     /// If you return true from the callback, the search is stopped and a
     /// PARTIALMATCH is returned with the given node. Note that this node
     /// doesn't really need to be the one with longest possible match.
@@ -1031,17 +1067,14 @@ public:
     ///
     /// This feature can be used to get the absolute name for a node;
     /// to do so, we need to travel upside from the node toward the root,
-    /// concatenating all ancestor names.  With the current implementation
-    /// it's not possible without a node chain, because there is a no pointer
-    /// from the root of a subtree to the parent subtree (this may change
-    /// in a future version).  A node chain can also be used to find the
-    /// next and previous nodes of a given node in the entire RBTree;
+    /// concatenating all ancestor labels.  A node chain can also be used to
+    /// find the next and previous nodes of a given node in the entire RBTree;
     /// the \c nextNode() and \c previousNode() methods take a node
     /// chain as a parameter.
     ///
     /// \exception isc::BadValue node_path is not empty.
     ///
-    /// \param name Target to be found
+    /// \param target_labels_orig Target to be found
     /// \param node On success (either \c EXACTMATCH or \c PARTIALMATCH)
     ///     it will store a pointer to the matching node
     /// \param node_path Other search details will be stored (see the
@@ -1054,7 +1087,7 @@ public:
     /// \return As in the description, but in case of callback returning
     ///     \c true, it returns immediately with the current node.
     template <typename CBARG>
-    Result find(const isc::dns::Name& name,
+    Result find(const isc::dns::LabelSequence& target_labels_orig,
                 RBNode<T>** node,
                 RBTreeNodeChain<T>& node_path,
                 bool (*callback)(const RBNode<T>&, CBARG),
@@ -1065,15 +1098,15 @@ public:
     /// Acts as described in the \ref find section, but returns immutable
     /// node pointer.
     template <typename CBARG>
-    Result find(const isc::dns::Name& name,
+    Result find(const isc::dns::LabelSequence& target_labels,
                 const RBNode<T>** node,
                 RBTreeNodeChain<T>& node_path,
                 bool (*callback)(const RBNode<T>&, CBARG),
                 CBARG callback_arg) const
     {
         RBNode<T>* target_node = NULL;
-        Result ret = find(name, &target_node, node_path, callback,
-                          callback_arg);
+        Result ret = find(target_labels, &target_node, node_path,
+                          callback, callback_arg);
         if (ret != NOTFOUND) {
             *node = target_node;
         }
@@ -1310,7 +1343,7 @@ RBTree<T>::deleteHelper(util::MemorySegment& mem_sgmt, RBNode<T>* root) {
 template <typename T>
 template <typename CBARG>
 typename RBTree<T>::Result
-RBTree<T>::find(const isc::dns::Name& target_name,
+RBTree<T>::find(const isc::dns::LabelSequence& target_labels_orig,
                 RBNode<T>** target,
                 RBTreeNodeChain<T>& node_path,
                 bool (*callback)(const RBNode<T>&, CBARG),
@@ -1322,7 +1355,7 @@ RBTree<T>::find(const isc::dns::Name& target_name,
 
     RBNode<T>* node = root_.get();
     Result ret = NOTFOUND;
-    dns::LabelSequence target_labels(target_name);
+    dns::LabelSequence target_labels(target_labels_orig);
 
     while (node != NULL) {
         node_path.last_compared_ = node;
diff --git a/src/lib/datasrc/tests/rbtree_unittest.cc b/src/lib/datasrc/tests/rbtree_unittest.cc
index a9d4bf8..1d08fed 100644
--- a/src/lib/datasrc/tests/rbtree_unittest.cc
+++ b/src/lib/datasrc/tests/rbtree_unittest.cc
@@ -318,14 +318,23 @@ TEST_F(RBTreeTest, flags) {
 }
 
 bool
-testCallback(const RBNode<int>&, bool* callack_checker) {
-    *callack_checker = true;
+testCallback(const RBNode<int>&, bool* callback_checker) {
+    *callback_checker = true;
     return (false);
 }
 
-TEST_F(RBTreeTest, callback) {
+template <typename T>
+void
+performCallbackTest(RBTree<int>& rbtree,
+                    util::MemorySegmentLocal& mem_sgmt,
+                    const T& name_called,
+                    const T& name_not_called)
+{
+    RBNode<int>* rbtnode;
+    const RBNode<int>* crbtnode;
+
     // by default callback isn't enabled
-    EXPECT_EQ(RBTree<int>::SUCCESS, rbtree.insert(mem_sgmt_,
+    EXPECT_EQ(RBTree<int>::SUCCESS, rbtree.insert(mem_sgmt,
                                                   Name("callback.example"),
                                                   &rbtnode));
     rbtnode->setData(RBNode<int>::NodeDataPtr(new int(1)));
@@ -341,15 +350,15 @@ TEST_F(RBTreeTest, callback) {
     rbtnode->setFlag(RBNode<int>::FLAG_CALLBACK);
     // add more levels below and above the callback node for partial match.
     RBNode<int>* subrbtnode;
-    EXPECT_EQ(RBTree<int>::SUCCESS, rbtree.insert(mem_sgmt_,
+    EXPECT_EQ(RBTree<int>::SUCCESS, rbtree.insert(mem_sgmt,
                                                   Name("sub.callback.example"),
                                                   &subrbtnode));
     subrbtnode->setData(RBNode<int>::NodeDataPtr(new int(2)));
     RBNode<int>* parentrbtnode;
-    EXPECT_EQ(RBTree<int>::ALREADYEXISTS, rbtree.insert(mem_sgmt_,
+    EXPECT_EQ(RBTree<int>::ALREADYEXISTS, rbtree.insert(mem_sgmt,
                                                         Name("example"),
                                                         &parentrbtnode));
-    //  the chilld/parent nodes shouldn't "inherit" the callback flag.
+    // the child/parent nodes shouldn't "inherit" the callback flag.
     // "rbtnode" may be invalid due to the insertion, so we need to re-find
     // it.
     EXPECT_EQ(RBTree<int>::EXACTMATCH, rbtree.find(Name("callback.example"),
@@ -362,7 +371,7 @@ TEST_F(RBTreeTest, callback) {
     RBTreeNodeChain<int> node_path1;
     bool callback_called = false;
     EXPECT_EQ(RBTree<int>::EXACTMATCH,
-              rbtree.find(Name("sub.callback.example"), &crbtnode, node_path1,
+              rbtree.find(name_called, &crbtnode, node_path1,
                           testCallback, &callback_called));
     EXPECT_TRUE(callback_called);
 
@@ -372,11 +381,27 @@ TEST_F(RBTreeTest, callback) {
     parentrbtnode->setFlag(RBNode<int>::FLAG_CALLBACK);
     callback_called = false;
     EXPECT_EQ(RBTree<int>::EXACTMATCH,
-              rbtree.find(Name("callback.example"), &crbtnode, node_path2,
+              rbtree.find(name_not_called, &crbtnode, node_path2,
                           testCallback, &callback_called));
     EXPECT_FALSE(callback_called);
 }
 
+TEST_F(RBTreeTest, callbackName) {
+    const Name n1("sub.callback.example");
+    const Name n2("callback.example");
+
+    performCallbackTest(rbtree, mem_sgmt_, n1, n2);
+}
+
+TEST_F(RBTreeTest, callbackLabelSequence) {
+    const Name n1("sub.callback.example");
+    const Name n2("callback.example");
+    const LabelSequence ls1(n1);
+    const LabelSequence ls2(n2);
+
+    performCallbackTest(rbtree, mem_sgmt_, ls1, ls2);
+}
+
 TEST_F(RBTreeTest, chainLevel) {
     RBTreeNodeChain<int> chain;
 



More information about the bind10-changes mailing list