Browse Source

[2834] use CacheConfig::getLoadAction for ConfigurableClientList::configure.

we now don't distinguish MasterFiles and other data sources, so we unified
two error logs.
JINMEI Tatuya 12 years ago
parent
commit
854d608fd2
2 changed files with 40 additions and 62 deletions
  1. 34 53
      src/lib/datasrc/client_list.cc
  2. 6 9
      src/lib/datasrc/datasrc_messages.mes

+ 34 - 53
src/lib/datasrc/client_list.cc

@@ -31,6 +31,7 @@
 #include <set>
 #include <set>
 #include <boost/foreach.hpp>
 #include <boost/foreach.hpp>
 #include <boost/bind.hpp>
 #include <boost/bind.hpp>
+#include <boost/scoped_ptr.hpp>
 
 
 using namespace isc::data;
 using namespace isc::data;
 using namespace isc::dns;
 using namespace isc::dns;
@@ -119,6 +120,9 @@ ConfigurableClientList::configure(const ConstElementPtr& config,
                 continue;
                 continue;
             }
             }
 
 
+            // Build in-memory cache configuration, and create a set of
+            // related objects including the in-memory zone table for the
+            // cache.
             boost::shared_ptr<internal::CacheConfig> cache_conf(
             boost::shared_ptr<internal::CacheConfig> cache_conf(
                 new internal::CacheConfig(type, dsrc_pair.first, *dconf,
                 new internal::CacheConfig(type, dsrc_pair.first, *dconf,
                                           allow_cache));
                                           allow_cache));
@@ -127,60 +131,37 @@ ConfigurableClientList::configure(const ConstElementPtr& config,
                                                       cache_conf, rrclass_,
                                                       cache_conf, rrclass_,
                                                       name));
                                                       name));
 
 
-            if (cache_conf->isEnabled()) {
+            // If cache is disabled we are done for this data source.
-                // List the zones we are loading
+            // Otherwise load zones into the in-memory cache.
-                vector<string> zones_origins;
+            if (!cache_conf->isEnabled()) {
-                if (type == "MasterFiles") {
+                continue;
-                    const map<string, ConstElementPtr>
+            }
-                        zones_files(paramConf->mapValue());
+            internal::CacheConfig::ConstZoneIterator end_of_zones =
-                    for (map<string, ConstElementPtr>::const_iterator
+                cache_conf->end();
-                         it(zones_files.begin()); it != zones_files.end();
+            for (internal::CacheConfig::ConstZoneIterator zone_it =
-                         ++it) {
+                     cache_conf->begin();
-                        zones_origins.push_back(it->first);
+                 zone_it != end_of_zones;
-                    }
+                 ++zone_it)
-                } else {
+            {
-                    const ConstElementPtr zones(dconf->get("cache-zones"));
+                const Name& zname = zone_it->first;
-                    for (size_t i(0); i < zones->size(); ++i) {
+                memory::LoadAction load_action;
-                        zones_origins.push_back(zones->get(i)->stringValue());
+                try {
-                    }
+                    load_action = cache_conf->getLoadAction(rrclass_, zname);
+                } catch (const DataSourceError&) {
+                    isc_throw(ConfigurationError, "Unable to cache "
+                              "non-existent zone " << zname);
                 }
                 }
-
+                assert(load_action); // in this loop this should be always true
-                const shared_ptr<InMemoryClient>
+                boost::scoped_ptr<memory::ZoneWriter> writer;
-                    cache(new_data_sources.back().cache_);
+                try {
-                const DataSourceClient* const
+                    writer.reset(new_data_sources.back().ztable_segment_->
-                    client(new_data_sources.back().data_src_client_);
+                                 getZoneWriter(load_action, zname, rrclass_));
-
+                    writer->load();
-                for (vector<string>::const_iterator it(zones_origins.begin());
+                    writer->install();
-                     it != zones_origins.end(); ++it) {
+                    writer->cleanup();
-                    const Name origin(*it);
+                } catch (const ZoneLoaderException& e) {
-                    if (type == "MasterFiles") {
+                    LOG_ERROR(logger, DATASRC_LOAD_ZONE_ERROR)
-                        try {
+                        .arg(zname).arg(rrclass_).arg(name).arg(e.what());
-                            cache->load(origin,
-                                        paramConf->get(*it)->stringValue());
-                        } catch (const ZoneLoaderException& e) {
-                            LOG_ERROR(logger, DATASRC_LOAD_FROM_FILE_ERROR)
-                                .arg(origin).arg(e.what());
-                        }
-                    } else {
-                        ZoneIteratorPtr iterator;
-                        try {
-                            iterator = client->getIterator(origin);
-                        } catch (const DataSourceError&) {
-                            isc_throw(ConfigurationError, "Unable to "
-                                      "cache non-existent zone "
-                                      << origin);
-                        }
-                        if (!iterator) {
-                            isc_throw(isc::Unexpected, "Got NULL iterator "
-                                      "for zone " << origin);
-                        }
-                        try {
-                            cache->load(origin, *iterator);
-                        } catch (const ZoneLoaderException& e) {
-                            LOG_ERROR(logger, DATASRC_LOAD_FROM_ITERATOR_ERROR)
-                                .arg(origin).arg(e.what());
-                        }
-                    }
                 }
                 }
             }
             }
         }
         }

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

@@ -328,15 +328,12 @@ Therefore, the entire data source will not be available for this process. If
 this is a problem, you should configure the zones of that data source to some
 this is a problem, you should configure the zones of that data source to some
 database backend (sqlite3, for example) and use it from there.
 database backend (sqlite3, for example) and use it from there.
 
 
-% DATASRC_LOAD_FROM_FILE_ERROR Error loading zone %1: %2
+% DATASRC_LOAD_ZONE_ERROR Error loading zone %1/%2 on data source %3: %4
-An error was found in the zone data when it was being loaded from a
+During data source configuration, an error was found in the zone data
-file. The zone was not loaded. The specific error is shown in the
+when it was being loaded in to memory on the shown data source.  This
-message, and should be addressed.
+particular zone was not loaded, but data source configuration
-
+continues, possibly loading other zones into memory. The specific
-% DATASRC_LOAD_FROM_ITERATOR_ERROR Error loading zone %1: %2
+error is shown in the message, and should be addressed.
-An error was found in the zone data when it was being loaded from
-another data source. The zone was not loaded. The specific error is
-shown in the message, and should be addressed.
 
 
 % DATASRC_MASTER_LOAD_ERROR %1:%2: Zone '%3/%4' contains error: %5
 % DATASRC_MASTER_LOAD_ERROR %1:%2: Zone '%3/%4' contains error: %5
 There's an error in the given master file. The zone won't be loaded for
 There's an error in the given master file. The zone won't be loaded for