2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-05 08:25:16 +00:00

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
This commit is contained in:
Evan Hunt
2010-03-08 00:03:04 +00:00
parent 298967b31a
commit cc1498e0cf
10 changed files with 53 additions and 23 deletions

View File

@@ -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);
}
}

View File

@@ -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.

View File

@@ -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;
}

View File

@@ -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,

View File

@@ -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());
}

View File

@@ -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) {

View File

@@ -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,

View File

@@ -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());
}

View File

@@ -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) {

View File

@@ -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,