BIND 10 trac2209, updated. ecabe80cbb2483d8057a83c84faeb84ce903b555 [2209] Make ConfigurableClientList::reload a wrapper
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Oct 25 18:59:46 UTC 2012
The branch, trac2209 has been updated
via ecabe80cbb2483d8057a83c84faeb84ce903b555 (commit)
via f609865c302b87caa3f5721557b0e5491c3eba3e (commit)
via 70473ce1f70543029936a6c5c6c055ea7a33581b (commit)
from 4a9e338f845772c9a0888a276c30449f89beea9c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit ecabe80cbb2483d8057a83c84faeb84ce903b555
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Oct 25 20:58:37 2012 +0200
[2209] Make ConfigurableClientList::reload a wrapper
Since the function is to reload and we provide an object that can
reload, we just get one and call it. It is just to avoid duplicate code.
commit f609865c302b87caa3f5721557b0e5491c3eba3e
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Oct 25 20:43:38 2012 +0200
[2209] Provide the callbacks to load data
So now the loading works correctly (at least as the tests say).
commit 70473ce1f70543029936a6c5c6c055ea7a33581b
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Oct 25 20:42:39 2012 +0200
[2209] Pass objects by const reference
Passing it as const RRClass (and making a copy) makes no real sense. It
looks more expected with the reference and might even be slightly
faster.
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/client_list.cc | 90 +++++++++++++++++-----------
src/lib/datasrc/memory/memory_client.cc | 2 +-
src/lib/datasrc/memory/zone_data_loader.cc | 6 +-
src/lib/datasrc/memory/zone_data_loader.h | 4 +-
4 files changed, 61 insertions(+), 41 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/client_list.cc b/src/lib/datasrc/client_list.cc
index 744776b..474f7a7 100644
--- a/src/lib/datasrc/client_list.cc
+++ b/src/lib/datasrc/client_list.cc
@@ -19,12 +19,14 @@
#include "memory/memory_client.h"
#include "memory/zone_table_segment.h"
#include "memory/zone_writer.h"
+#include "memory/zone_data_loader.h"
#include "logger.h"
#include <dns/masterload.h>
#include <util/memory_segment_local.h>
#include <memory>
#include <boost/foreach.hpp>
+#include <boost/bind.hpp>
using namespace isc::data;
using namespace isc::dns;
@@ -339,43 +341,57 @@ ConfigurableClientList::findInternal(MutableResult& candidate,
// and the need_updater parameter is true, get the zone there.
}
+// We still provide this method for backward compatibility. But to not have
+// duplicate code, it is a thin wrapper around getCachedZoneWriter only.
ConfigurableClientList::ReloadResult
ConfigurableClientList::reload(const Name& name) {
- if (!allow_cache_) {
- return (CACHE_DISABLED);
+ ZoneWriterPair result(getCachedZoneWriter(name));
+ if (result.second) {
+ result.second->load();
+ result.second->install();
+ result.second->cleanup();
}
- // Try to find the correct zone.
- MutableResult result;
- findInternal(result, name, true, true);
- if (!result.finder) {
- return (ZONE_NOT_FOUND);
- }
- // Try to convert the finder to in-memory one. If it is the cache,
- // it should work.
- // It is of a different type or there's no cache.
- if (!result.info->cache_) {
- return (ZONE_NOT_CACHED);
- }
- DataSourceClient* client(result.info->data_src_client_);
- if (client) {
- // Now do the final reload. 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);
- }
- result.info->cache_->load(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");
- }
- result.info->cache_->load(name, filename);
+ return (result.first);
+}
+
+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_));
}
- return (ZONE_RELOADED);
+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
@@ -405,7 +421,9 @@ ConfigurableClientList::getCachedZoneWriter(const Name& name) {
if (!iterator) {
isc_throw(isc::Unexpected, "Null iterator from " << name);
}
- // TODO
+ // 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));
@@ -413,7 +431,9 @@ ConfigurableClientList::getCachedZoneWriter(const Name& name) {
isc_throw(isc::Unexpected, "Confused about missing both filename "
"and data source");
}
- // TODO
+ // boost::bind is enough here.
+ load_action = boost::bind(loadZoneDataFromFile, _1, rrclass_, name,
+ filename);
}
return (ZoneWriterPair(ZONE_RELOADED,
ZoneWriterPtr(result.info->cache_->getZoneTableSegment().
diff --git a/src/lib/datasrc/memory/memory_client.cc b/src/lib/datasrc/memory/memory_client.cc
index 7a367e2..1eca593 100644
--- a/src/lib/datasrc/memory/memory_client.cc
+++ b/src/lib/datasrc/memory/memory_client.cc
@@ -221,7 +221,7 @@ private:
bool separate_rrs_;
bool ready_;
public:
- MemoryIterator(const RRClass rrclass,
+ MemoryIterator(const RRClass& rrclass,
const ZoneTree& tree, const Name& origin,
bool separate_rrs) :
rrclass_(rrclass),
diff --git a/src/lib/datasrc/memory/zone_data_loader.cc b/src/lib/datasrc/memory/zone_data_loader.cc
index 97c8092..d759901 100644
--- a/src/lib/datasrc/memory/zone_data_loader.cc
+++ b/src/lib/datasrc/memory/zone_data_loader.cc
@@ -165,7 +165,7 @@ ZoneDataLoader::getCurrentName() const {
ZoneData*
loadZoneDataInternal(util::MemorySegment& mem_sgmt,
- const isc::dns::RRClass rrclass,
+ const isc::dns::RRClass& rrclass,
const Name& zone_name,
boost::function<void(LoadCallback)> rrset_installer)
{
@@ -223,7 +223,7 @@ generateRRsetFromIterator(ZoneIterator* iterator, LoadCallback callback) {
ZoneData*
loadZoneData(util::MemorySegment& mem_sgmt,
- const isc::dns::RRClass rrclass,
+ const isc::dns::RRClass& rrclass,
const isc::dns::Name& zone_name,
const std::string& zone_file)
{
@@ -236,7 +236,7 @@ loadZoneData(util::MemorySegment& mem_sgmt,
ZoneData*
loadZoneData(util::MemorySegment& mem_sgmt,
- const isc::dns::RRClass rrclass,
+ const isc::dns::RRClass& rrclass,
const isc::dns::Name& zone_name,
ZoneIterator& iterator)
{
diff --git a/src/lib/datasrc/memory/zone_data_loader.h b/src/lib/datasrc/memory/zone_data_loader.h
index 298af46..6f02fcb 100644
--- a/src/lib/datasrc/memory/zone_data_loader.h
+++ b/src/lib/datasrc/memory/zone_data_loader.h
@@ -48,7 +48,7 @@ struct EmptyZone : public InvalidParameter {
/// \param zone_name The name of the zone that is being loaded.
/// \param zone_file Filename which contains the zone data for \c zone_name.
ZoneData* loadZoneData(util::MemorySegment& mem_sgmt,
- const isc::dns::RRClass rrclass,
+ const isc::dns::RRClass& rrclass,
const isc::dns::Name& zone_name,
const std::string& zone_file);
@@ -65,7 +65,7 @@ ZoneData* loadZoneData(util::MemorySegment& mem_sgmt,
/// \param zone_name The name of the zone that is being loaded.
/// \param iterator Iterator that returns RRsets to load into the zone.
ZoneData* loadZoneData(util::MemorySegment& mem_sgmt,
- const isc::dns::RRClass rrclass,
+ const isc::dns::RRClass& rrclass,
const isc::dns::Name& zone_name,
ZoneIterator& iterator);
More information about the bind10-changes
mailing list