From: JINMEI Tatuya Date: Wed, 3 Apr 2013 04:02:52 +0000 (-0700) Subject: [2834] updated getCachedZoneWriter so it uses CacheConfig::getLoadAction. X-Git-Tag: bind10-1.1.0beta2-release~8^2~23^2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bb5f0f9677e89c5fa45a6e54c2176a2496cfa6a8;p=thirdparty%2Fkea.git [2834] updated getCachedZoneWriter so it uses CacheConfig::getLoadAction. --- diff --git a/src/lib/datasrc/client_list.cc b/src/lib/datasrc/client_list.cc index d366ac3bc2..67408d5fc6 100644 --- a/src/lib/datasrc/client_list.cc +++ b/src/lib/datasrc/client_list.cc @@ -344,46 +344,6 @@ ConfigurableClientList::reload(const Name& name) { return (ZONE_SUCCESS); } -namespace { - -// We would like to use boost::bind for this. However, the loadZoneData takes -// a reference, while we have a shared pointer to the iterator -- and we need -// to keep it alive as long as the ZoneWriter is alive. Therefore we can't -// really just dereference it and pass it, since it would get destroyed once -// the getCachedZoneWriter would end. This class holds the shared pointer -// alive, otherwise is mostly simple. -// -// It might be doable with nested boost::bind, but it would probably look -// more awkward and complicated than this. -class IteratorLoader { -public: - IteratorLoader(const RRClass& rrclass, const Name& name, - const ZoneIteratorPtr& iterator) : - rrclass_(rrclass), - name_(name), - iterator_(iterator) - {} - memory::ZoneData* operator()(util::MemorySegment& segment) { - return (memory::loadZoneData(segment, rrclass_, name_, *iterator_)); - } -private: - const RRClass rrclass_; - const Name name_; - ZoneIteratorPtr iterator_; -}; - -// We can't use the loadZoneData function directly in boost::bind, since -// it is overloaded and the compiler can't choose the correct version -// reliably and fails. So we simply wrap it into an unique name. -memory::ZoneData* -loadZoneDataFromFile(util::MemorySegment& segment, const RRClass& rrclass, - const Name& name, const string& filename) -{ - return (memory::loadZoneData(segment, rrclass, name, filename)); -} - -} - ConfigurableClientList::ZoneWriterPair ConfigurableClientList::getCachedZoneWriter(const Name& name) { if (!allow_cache_) { @@ -395,35 +355,14 @@ ConfigurableClientList::getCachedZoneWriter(const Name& name) { if (!result.finder) { return (ZoneWriterPair(ZONE_NOT_FOUND, ZoneWriterPtr())); } - // Try to get the in-memory cache for the zone. If there's none, - // we can't provide the result. - if (!result.info->cache_) { - return (ZoneWriterPair(ZONE_NOT_CACHED, ZoneWriterPtr())); - } - memory::LoadAction load_action; - DataSourceClient* client(result.info->data_src_client_); - if (client != NULL) { - // Now finally provide the writer. - // If it does not exist in client, - // DataSourceError is thrown, which is exactly the result what we - // want, so no need to handle it. - ZoneIteratorPtr iterator(client->getIterator(name)); - if (!iterator) { - isc_throw(isc::Unexpected, "Null iterator from " << name); - } - // And wrap the iterator into the correct functor (which - // keeps it alive as long as it is needed). - load_action = IteratorLoader(rrclass_, name, iterator); - } else { - // The MasterFiles special case - const string filename(result.info->cache_->getFileName(name)); - if (filename.empty()) { - isc_throw(isc::Unexpected, "Confused about missing both filename " - "and data source"); - } - // boost::bind is enough here. - load_action = boost::bind(loadZoneDataFromFile, _1, rrclass_, name, - filename); + + // Then get the appropriate load action and create a zone writer. + // Note that getCacheConfig() must return non NULL in this module (only + // tests could set it to a bogus value). + const memory::LoadAction load_action = + result.info->getCacheConfig()->getLoadAction(rrclass_, name); + if (!load_action) { + ZoneWriterPair(ZONE_NOT_CACHED, ZoneWriterPtr()); } return (ZoneWriterPair(ZONE_SUCCESS, ZoneWriterPtr(