Browse Source

[1198] proposed further refactor 7: recovered logs, with defining new
ones for each subcase of find().

JINMEI Tatuya 13 years ago
parent
commit
b447162191
3 changed files with 43 additions and 8 deletions
  1. 28 8
      src/lib/datasrc/database.cc
  2. 9 0
      src/lib/datasrc/database.h
  3. 6 0
      src/lib/datasrc/datasrc_messages.mes

+ 28 - 8
src/lib/datasrc/database.cc

@@ -613,6 +613,24 @@ DatabaseClient::Finder::findNoNameResult(const Name& name, const RRType& type,
 }
 }
 
 
 ZoneFinder::FindResult
 ZoneFinder::FindResult
+DatabaseClient::Finder::logAndCreateResult(const Name& name,
+                                           const RRType& type,
+                                           ZoneFinder::Result code,
+                                           ConstRRsetPtr rrset,
+                                           const isc::log::MessageID& log_id)
+{
+    if (rrset) {
+        LOG_DEBUG(logger, DBG_TRACE_DETAILED, log_id).
+            arg(accessor_->getDBName()).arg(name).arg(getClass()).
+            arg(type).arg(*rrset);
+    } else {
+        LOG_DEBUG(logger, DBG_TRACE_DETAILED, log_id).
+            arg(accessor_->getDBName()).arg(name).arg(type).arg(getClass());
+    }
+    return (ZoneFinder::FindResult(code, rrset));
+}
+
+ZoneFinder::FindResult
 DatabaseClient::Finder::find(const isc::dns::Name& name,
 DatabaseClient::Finder::find(const isc::dns::Name& name,
                              const isc::dns::RRType& type,
                              const isc::dns::RRType& type,
                              isc::dns::RRsetList*,
                              isc::dns::RRsetList*,
@@ -643,19 +661,19 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
 
 
     if (!is_origin && (options & FIND_GLUE_OK) == 0 &&
     if (!is_origin && (options & FIND_GLUE_OK) == 0 &&
         nsi != found.second.end()) { // delegation at the exact node
         nsi != found.second.end()) { // delegation at the exact node
-        LOG_DEBUG(logger, DBG_TRACE_DETAILED,
-                  DATASRC_DATABASE_FOUND_DELEGATION_EXACT).
-            arg(accessor_->getDBName()).arg(name);
-        return (FindResult(DELEGATION, nsi->second));
+        return (logAndCreateResult(name, type, DELEGATION, nsi->second,
+                                   DATASRC_DATABASE_FOUND_DELEGATION_EXACT));
     } else if (type != RRType::CNAME() && cni != found.second.end()) { // CNAME
     } else if (type != RRType::CNAME() && cni != found.second.end()) { // CNAME
         if (cni->second->getRdataCount() != 1) {
         if (cni->second->getRdataCount() != 1) {
             isc_throw(DataSourceError, "CNAME with " <<
             isc_throw(DataSourceError, "CNAME with " <<
                       cni->second->getRdataCount() <<
                       cni->second->getRdataCount() <<
                       " rdata at " << name << ", expected 1");
                       " rdata at " << name << ", expected 1");
         }
         }
-        return (FindResult(CNAME, cni->second));
+        return (logAndCreateResult(name, type, CNAME, cni->second,
+                                   DATASRC_DATABASE_FOUND_CNAME));
     } else if (wti != found.second.end()) { // normal answer
     } else if (wti != found.second.end()) { // normal answer
-        return (FindResult(SUCCESS, wti->second));
+        return (logAndCreateResult(name, type, SUCCESS, wti->second,
+                                   DATASRC_DATABASE_FOUND_RRSET));
     } else if (!found.first) { // NXDOMAIN, empty name, wildcard
     } else if (!found.first) { // NXDOMAIN, empty name, wildcard
         return (findNoNameResult(name, type, options, dresult));
         return (findNoNameResult(name, type, options, dresult));
     } else {
     } else {
@@ -664,10 +682,12 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
         if ((options & FIND_DNSSEC) != 0) {
         if ((options & FIND_DNSSEC) != 0) {
             const FoundIterator nci(found.second.find(RRType::NSEC()));
             const FoundIterator nci(found.second.find(RRType::NSEC()));
             if (nci != found.second.end()) {
             if (nci != found.second.end()) {
-                return (FindResult(NXRRSET, nci->second));
+                return (logAndCreateResult(name, type, NXRRSET, nci->second,
+                                           DATASRC_DATABASE_FOUND_NXRRSET_NSEC));
             }
             }
         }
         }
-        return (FindResult(NXRRSET, ConstRRsetPtr()));
+        return (logAndCreateResult(name, type, NXRRSET, ConstRRsetPtr(),
+                                   DATASRC_DATABASE_FOUND_NXRRSET));
     }
     }
 }
 }
 
 

+ 9 - 0
src/lib/datasrc/database.h

@@ -25,6 +25,7 @@
 #include <dns/rrtype.h>
 #include <dns/rrtype.h>
 
 
 #include <datasrc/client.h>
 #include <datasrc/client.h>
+#include <datasrc/logger.h>
 
 
 #include <dns/name.h>
 #include <dns/name.h>
 #include <exceptions/exceptions.h>
 #include <exceptions/exceptions.h>
@@ -981,6 +982,14 @@ public:
                                     const isc::dns::RRType& type,
                                     const isc::dns::RRType& type,
                                     FindOptions options,
                                     FindOptions options,
                                     const DelegationSearchResult& dresult);
                                     const DelegationSearchResult& dresult);
+
+        // To be documented.
+        FindResult logAndCreateResult(const isc::dns::Name& name,
+                                      const isc::dns::RRType& type,
+                                      ZoneFinder::Result code,
+                                      isc::dns::ConstRRsetPtr rrset,
+                                      const isc::log::MessageID& log_id);
+
         /**
         /**
          * \brief Checks if something lives below this domain.
          * \brief Checks if something lives below this domain.
          *
          *

+ 6 - 0
src/lib/datasrc/datasrc_messages.mes

@@ -110,6 +110,12 @@ The data returned by the database backend contained data for the given domain
 name, and it either matches the type or has a relevant type. The RRset that is
 name, and it either matches the type or has a relevant type. The RRset that is
 returned is printed.
 returned is printed.
 
 
+% DATASRC_DATABASE_FOUND_CNAME search in datasource %1 for %2/%3/%4 resulted in CNAME %5
+(TBD)
+
+% DATASRC_DATABASE_FOUND_NXRRSET_NSEC search in datasource %1 for %2/%3/%4 resulted in RRset %5
+(TBD)
+
 % DATASRC_DATABASE_ITERATE iterating zone %1
 % DATASRC_DATABASE_ITERATE iterating zone %1
 The program is reading the whole zone, eg. not searching for data, but going
 The program is reading the whole zone, eg. not searching for data, but going
 through each of the RRsets there.
 through each of the RRsets there.