Browse Source

specify query class when calling findClosestEnclosure(), so that we can
skip data sources that definitely won't match. (I'm not sure about the
design here and may revisit it, but there should be a marginal speedup
from not having to compare every single qname to "authors.bind" and
"version.bind".)


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1191 e5f2f494-b856-4b98-b285-d166d9295462

Evan Hunt 15 years ago
parent
commit
cc1498e0cf

+ 12 - 5
src/lib/auth/data_source.cc

@@ -495,7 +495,7 @@ DataSrc::doQuery(Query& q)
         NameMatch match(task->qtype == RRType::DS() ?
                         task->qname.split(1, task->qname.getLabelCount() - 1) :
                         task->qname);
-        findClosestEnclosure(match);
+        findClosestEnclosure(match, task->qclass);
         const DataSrc* datasource = match.bestDataSrc();
         const Name* zonename = match.closestName();
 
@@ -782,15 +782,22 @@ MetaDataSrc::addDataSrc(ConstDataSrcPtr data_src)
 }
 
 void
-MetaDataSrc::findClosestEnclosure(NameMatch& match) const
+MetaDataSrc::findClosestEnclosure(NameMatch& match, const RRClass& qclass) const
 {
+    if (qclass == RRClass::ANY()) {
+        isc_throw(Unexpected, "invalid query class");
+    }
+
+    if (getClass() != RRClass::ANY() && getClass() != qclass) {
+        return;
+    }
+
     BOOST_FOREACH (ConstDataSrcPtr data_src, data_sources) {
-        if (getClass() != RRClass::ANY() &&
-            data_src->getClass() != getClass()) {
+        if (data_src->getClass() != qclass) {
             continue;
         }
 
-        data_src->findClosestEnclosure(match);
+        data_src->findClosestEnclosure(match, qclass);
     }
 }
 

+ 8 - 3
src/lib/auth/data_source.h

@@ -95,7 +95,9 @@ public:
 
     // 'Medium-level' methods.  This will be implemented by the general
     // DataSrc class but MAY be overwritten by subclasses.
-    virtual void findClosestEnclosure(NameMatch& match) const = 0;
+    virtual void findClosestEnclosure(NameMatch& match,
+                                      const isc::dns::RRClass& qclasss)
+                                      const = 0;
 
     // Optional 'low-level' methods.  These will have stub implementations
     // in the general DataSrc class but MAY be overwritten by subclasses
@@ -170,7 +172,9 @@ public:
 
     virtual void doQuery(Query& q);
 
-    virtual void findClosestEnclosure(NameMatch& match) const = 0;
+    virtual void findClosestEnclosure(NameMatch& match,
+                                      const isc::dns::RRClass& qclass)
+                                      const = 0;
 
     const isc::dns::RRClass& getClass() const { return rrclass; }
     void setClass(isc::dns::RRClass& c) { rrclass = c; }
@@ -241,7 +245,8 @@ public:
     //@}
 
     void addDataSrc(ConstDataSrcPtr data_src);
-    void findClosestEnclosure(NameMatch& match) const;
+    void findClosestEnclosure(NameMatch& match,
+                              const isc::dns::RRClass& qclass) const;
 
     // Actual queries for data should not be sent to a MetaDataSrc object,
     // so we return NOT_IMPLEMENTED if we receive any.

+ 6 - 1
src/lib/auth/data_source_sqlite3.cc

@@ -500,9 +500,14 @@ Sqlite3DataSrc::init() {
 }
 
 void
-Sqlite3DataSrc::findClosestEnclosure(NameMatch& match) const {
+Sqlite3DataSrc::findClosestEnclosure(NameMatch& match,
+                                     const RRClass& qclass) const {
     const char* position = NULL;
     
+    if (qclass != getClass()) {
+        return;
+    }
+
     if (findClosest(match.qname().toText().c_str(), &position) == -1) {
         return;
     }

+ 2 - 1
src/lib/auth/data_source_sqlite3.h

@@ -59,7 +59,8 @@ public:
     ~Sqlite3DataSrc();
     //@}
 
-    void findClosestEnclosure(NameMatch& match) const;
+    void findClosestEnclosure(NameMatch& match,
+                              const isc::dns::RRClass& qclass) const;
 
     Result findRRset(const Query& q,
                      const isc::dns::Name& qname,

+ 4 - 4
src/lib/auth/data_source_sqlite3_unittest.cc

@@ -353,7 +353,7 @@ TEST_F(Sqlite3DataSourceTest, reOpen) {
     EXPECT_EQ(DataSrc::SUCCESS, data_source.init(SQLITE_DBFILE_EXAMPLE2));
 
     NameMatch name_match(www_name);
-    data_source.findClosestEnclosure(name_match);
+    data_source.findClosestEnclosure(name_match, RRClass::IN());
     EXPECT_EQ(NULL, name_match.closestName());
     EXPECT_EQ(NULL, name_match.bestDataSrc());
 }
@@ -365,7 +365,7 @@ TEST_F(Sqlite3DataSourceTest, openFail) {
 
 TEST_F(Sqlite3DataSourceTest, findClosestEnclosure) {
     NameMatch name_match(www_name);
-    data_source.findClosestEnclosure(name_match);
+    data_source.findClosestEnclosure(name_match, RRClass::IN());
     EXPECT_EQ(zone_name, *name_match.closestName());
     EXPECT_EQ(&data_source, name_match.bestDataSrc());
 }
@@ -374,14 +374,14 @@ TEST_F(Sqlite3DataSourceTest, findClosestEnclosureAtDelegation) {
     // The search name exists both in the parent and child zones, but
     // child has a better match.
     NameMatch name_match(child_name);
-    data_source.findClosestEnclosure(name_match);
+    data_source.findClosestEnclosure(name_match, RRClass::IN());
     EXPECT_EQ(child_name, *name_match.closestName());
     EXPECT_EQ(&data_source, name_match.bestDataSrc());
 }
 
 TEST_F(Sqlite3DataSourceTest, findClosestEnclosureNoMatch) {
     NameMatch name_match(nomatch_name);
-    data_source.findClosestEnclosure(name_match);
+    data_source.findClosestEnclosure(name_match, RRClass::IN());
     EXPECT_EQ(NULL, name_match.closestName());
     EXPECT_EQ(NULL, name_match.bestDataSrc());
 }

+ 6 - 1
src/lib/auth/data_source_static.cc

@@ -101,10 +101,15 @@ StaticDataSrc::~StaticDataSrc()
 }
 
 void
-StaticDataSrc::findClosestEnclosure(NameMatch& match) const {
+StaticDataSrc::findClosestEnclosure(NameMatch& match,
+                                    const RRClass& qclass) const {
     const Name& qname = match.qname();
     NameComparisonResult::NameRelation cmp;
 
+    if (qclass != getClass()) {
+        return;
+    }
+
     cmp = qname.compare(impl_->version_name).getRelation();
     if (cmp == NameComparisonResult::EQUAL ||
         cmp == NameComparisonResult::SUBDOMAIN) {

+ 2 - 1
src/lib/auth/data_source_static.h

@@ -58,7 +58,8 @@ public:
     ~StaticDataSrc();
     //@}
 
-    void findClosestEnclosure(NameMatch& match) const;
+    void findClosestEnclosure(NameMatch& match,
+                              const isc::dns::RRClass& qclass) const;
 
     Result findRRset(const Query& q,
                      const isc::dns::Name& qname,

+ 5 - 5
src/lib/auth/data_source_static_unittest.cc

@@ -132,35 +132,35 @@ TEST_F(StaticDataSourceTest, close) {
 
 TEST_F(StaticDataSourceTest, findClosestEnclosureForVersion) {
     NameMatch name_match(version_name);
-    data_source.findClosestEnclosure(name_match);
+    data_source.findClosestEnclosure(name_match, RRClass::IN());
     EXPECT_EQ(version_name, *name_match.closestName());
     EXPECT_EQ(&data_source, name_match.bestDataSrc());
 }
 
 TEST_F(StaticDataSourceTest, findClosestEnclosureForVersionPartial) {
     NameMatch name_match(Name("foo").concatenate(version_name));
-    data_source.findClosestEnclosure(name_match);
+    data_source.findClosestEnclosure(name_match, RRClass::IN());
     EXPECT_EQ(version_name, *name_match.closestName());
     EXPECT_EQ(&data_source, name_match.bestDataSrc());
 }
 
 TEST_F(StaticDataSourceTest, findClosestEnclosureForAuthors) {
     NameMatch name_match(authors_name);
-    data_source.findClosestEnclosure(name_match);
+    data_source.findClosestEnclosure(name_match, RRClass::IN());
     EXPECT_EQ(authors_name, *name_match.closestName());
     EXPECT_EQ(&data_source, name_match.bestDataSrc());
 }
 
 TEST_F(StaticDataSourceTest, findClosestEnclosureForAuthorsPartial) {
     NameMatch name_match(Name("foo").concatenate(authors_name));
-    data_source.findClosestEnclosure(name_match);
+    data_source.findClosestEnclosure(name_match, RRClass::IN());
     EXPECT_EQ(authors_name, *name_match.closestName());
     EXPECT_EQ(&data_source, name_match.bestDataSrc());
 }
 
 TEST_F(StaticDataSourceTest, findClosestEnclosureNoMatch) {
     NameMatch name_match(nomatch_name);
-    data_source.findClosestEnclosure(name_match);
+    data_source.findClosestEnclosure(name_match, RRClass::IN());
     EXPECT_EQ(NULL, name_match.closestName());
     EXPECT_EQ(NULL, name_match.bestDataSrc());
 }

+ 6 - 1
src/lib/auth/unittest_ds.cc

@@ -414,10 +414,15 @@ TestDataSrc::init() {
 }
 
 void
-TestDataSrc::findClosestEnclosure(NameMatch& match) const {
+TestDataSrc::findClosestEnclosure(NameMatch& match,
+                                  const RRClass& qclass) const {
     const Name& qname = match.qname();
     NameComparisonResult::NameRelation cmp;
 
+    if (qclass != getClass()) {
+        return;
+    }
+
     cmp = qname.compare(sql1).getRelation();
     if (cmp == NameComparisonResult::EQUAL ||
           cmp == NameComparisonResult::SUBDOMAIN) {

+ 2 - 1
src/lib/auth/unittest_ds.h

@@ -48,7 +48,8 @@ public:
     ~TestDataSrc() {}
     //@}
 
-    void findClosestEnclosure(NameMatch& match) const;
+    void findClosestEnclosure(NameMatch& match,
+                              const isc::dns::RRClass& qclass) const;
 
     Result findRRset(const Query& q,
                      const isc::dns::Name& qname,