Browse Source

[1062] logging in database.cc

Jelte Jansen 13 years ago
parent
commit
5951ef6faa

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

@@ -23,6 +23,7 @@
 #include <dns/rdataclass.h>
 
 #include <datasrc/data_source.h>
+#include <datasrc/logger.h>
 
 #include <boost/foreach.hpp>
 
@@ -95,12 +96,8 @@ void addOrCreate(isc::dns::RRsetPtr& rrset,
         if (ttl < rrset->getTTL()) {
             rrset->setTTL(ttl);
         }
-        // make sure the type is correct
-        // TODO Assert?
-        if (type != rrset->getType()) {
-            isc_throw(DataSourceError,
-                        "attempt to add multiple types to RRset in find()");
-        }
+        // This is a check to make sure find() is not messing things up
+        assert(type == rrset->getType());
     }
     try {
         rrset->addRdata(isc::dns::rdata::createRdata(type, cls, rdata_str));
@@ -167,6 +164,7 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
     isc::dns::RRsetPtr result_rrset;
     ZoneFinder::Result result_status = SUCCESS;
     RRsigStore sig_store;
+    logger.debug(DBG_TRACE_DETAILED, DATASRC_DATABASE_FIND_RECORDS).arg(name).arg(type);
 
     try {
         connection_->searchForRecords(zone_id_, name.toText());
@@ -193,13 +191,18 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
                 //cur_sigtype(columns[SIGTYPE_COLUMN]);
 
                 if (cur_type == type) {
+                    if (result_rrset &&
+                        result_rrset->getType() == isc::dns::RRType::CNAME()) {
+                        isc_throw(DataSourceError, "CNAME found but it is not "
+                                  "the only record for " + name.toText());
+                    }
                     addOrCreate(result_rrset, name, getClass(), cur_type,
                                 cur_ttl, columns[DatabaseConnection::RDATA_COLUMN]);
                 } else if (cur_type == isc::dns::RRType::CNAME()) {
                     // There should be no other data, so result_rrset should be empty.
                     if (result_rrset) {
                         isc_throw(DataSourceError, "CNAME found but it is not "
-                                "the only record for " + name.toText());
+                                  "the only record for " + name.toText());
                     }
                     addOrCreate(result_rrset, name, getClass(), cur_type, cur_ttl,
                                 columns[DatabaseConnection::RDATA_COLUMN]);
@@ -227,26 +230,35 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
             }
         }
     } catch (const DataSourceError& dse) {
+        logger.error(DATASRC_DATABASE_FIND_ERROR).arg(dse.what());
         // call cleanup and rethrow
         connection_->resetSearch();
         throw;
     } catch (const isc::Exception& isce) {
-//         // cleanup, change it to a DataSourceError and rethrow
+        logger.error(DATASRC_DATABASE_FIND_UNCAUGHT_ISC_ERROR).arg(isce.what());
+        // cleanup, change it to a DataSourceError and rethrow
         connection_->resetSearch();
         isc_throw(DataSourceError, isce.what());
     } catch (const std::exception& ex) {
+        logger.error(DATASRC_DATABASE_FIND_UNCAUGHT_ERROR).arg(ex.what());
         connection_->resetSearch();
         throw;
     }
 
     if (!result_rrset) {
         if (records_found) {
+            logger.debug(DBG_TRACE_DETAILED, DATASRC_DATABASE_FOUND_NXRRSET)
+                        .arg(name).arg(getClass()).arg(type);
             result_status = NXRRSET;
         } else {
+            logger.debug(DBG_TRACE_DETAILED, DATASRC_DATABASE_FOUND_NXDOMAIN)
+                        .arg(name).arg(getClass()).arg(type);
             result_status = NXDOMAIN;
         }
     } else {
         sig_store.appendSignatures(result_rrset);
+        logger.debug(DBG_TRACE_DETAILED,
+                    DATASRC_DATABASE_FOUND_RRSET).arg(*result_rrset);
     }
     return (FindResult(result_status, result_rrset));
 }

+ 5 - 3
src/lib/datasrc/database.h

@@ -96,7 +96,7 @@ public:
      * DatabaseConnection::RecordColumnCount elements, the elements of which
      * are defined in DatabaseConnection::RecordColumns, in their basic
      * string representation.
-     * 
+     *
      * If you are implementing a derived database connection class, you
      * should have this method check the column_count value, and fill the
      * array with strings conforming to their description in RecordColumn.
@@ -129,10 +129,12 @@ public:
     /**
      * Definitions of the fields as they are required to be filled in
      * by getNextRecord()
-     * 
+     *
      * When implementing getNextRecord(), the columns array should
      * be filled with the values as described in this enumeration,
-     * in this order.
+     * in this order, i.e. TYPE_COLUMN should be the first element
+     * (index 0) of the array, TTL_COLUMN should be the second element
+     * (index 1), etc.
      */
     enum RecordColumns {
         TYPE_COLUMN = 0,    ///< The RRType of the record (A/NS/TXT etc.)

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

@@ -63,6 +63,41 @@ The maximum allowed number of items of the hotspot cache is set to the given
 number. If there are too many, some of them will be dropped. The size of 0
 means no limit.
 
+% DATASRC_DATABASE_FIND_ERROR error retrieving data from database datasource: %1
+The was an internal error while reading data from a datasource. This can either
+mean the specific data source implementation is not behaving correctly, or the
+data it provides is invalid. The current search is aborted.
+The error message contains specific information about the error.
+
+% DATASRC_DATABASE_FIND_RECORDS looking for record %1/%2
+Debug information. The database data source is looking up records with the given
+name and type in the database.
+
+% DATASRC_DATABASE_FIND_UNCAUGHT_ERROR uncaught general error retrieving data from database datasource: %1
+There was an uncaught general exception while reading data from a datasource.
+This most likely points to a logic error in the code, and can be considered a
+bug. The current search is aborted. Specific information about the exception is
+printed in this error message.
+
+% DATASRC_DATABASE_FIND_UNCAUGHT_ISC_ERROR uncaught error retrieving data from database datasource: %1
+There was an uncaught ISC exception while reading data from a datasource. This
+most likely points to a logic error in the code, and can be considered a bug.
+The current search is aborted. Specific information about the exception is
+printed in this error message.
+
+% DATASRC_DATABASE_FOUND_NXDOMAIN search in database resulted in NXDOMAIN for %1/%2/%3
+The data returned by the database backend did not contain any data for the given
+domain name, class and type.
+
+% DATASRC_DATABASE_FOUND_NXRRSET search in database resulted in NXRRSET for %1/%2/%3
+The data returned by the database backend contained data for the given domain
+name and class, but not for the given type.
+
+% DATASRC_DATABASE_FOUND_RRSET search in database resulted in RRset %1
+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
+returned is printed.
+
 % DATASRC_DO_QUERY handling query for '%1/%2'
 A debug message indicating that a query for the given name and RR type is being
 processed.

+ 1 - 1
src/lib/datasrc/sqlite3_connection.h

@@ -130,7 +130,7 @@ public:
      *
      * This implements the resetSearch from DatabaseConnection.
      * See the documentation there for more information.
-     * 
+     *
      * This function never throws.
      */
     virtual void resetSearch();