BIND 10 trac2378, updated. 6f90157ffab047e614c9574529018cc8ca230d1b [2378] Implement the master file loading
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Nov 29 14:27:01 UTC 2012
The branch, trac2378 has been updated
discards 74b99376d071dc61dd205566f8a78fc8289471ff (commit)
discards 5c1c51b9de5564fdc833d56b9f08a927e753d6ef (commit)
discards 163b1e34060b0ffc73a3551ae45c8d59c0caa103 (commit)
discards c73cec5320b45a6b14eaa7362dffb817e8e21266 (commit)
via 6f90157ffab047e614c9574529018cc8ca230d1b (commit)
via 3c212ec16d0b74d9532510c12f4f8f8611667111 (commit)
via 6f58803e1bd507586a10ba00c86cfb179124cfd7 (commit)
via fb1789ccdcb4740550af52b388dc46b0fed81319 (commit)
via 0c89bc5d564a9961538d4efa47a3194f239cf681 (commit)
via abd1274d3bc04463752ff163bf156f8d21cf376e (commit)
via 33faa4833595ec772f8b5cfd0db01059bac078f1 (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (74b99376d071dc61dd205566f8a78fc8289471ff)
\
N -- N -- N (6f90157ffab047e614c9574529018cc8ca230d1b)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
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 6f90157ffab047e614c9574529018cc8ca230d1b
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Nov 29 15:26:42 2012 +0100
[2378] Implement the master file loading
commit 3c212ec16d0b74d9532510c12f4f8f8611667111
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Nov 29 15:25:49 2012 +0100
[2378] It would throw at load(), not constructor
There's no way to know the master file would be broken in the
constructor. So update the documentation to say it'd throw from the
load() and loadIncremental().
commit 6f58803e1bd507586a10ba00c86cfb179124cfd7
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Nov 29 15:21:40 2012 +0100
[2378] Detect class mismatch with copy mode
commit fb1789ccdcb4740550af52b388dc46b0fed81319
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Nov 29 15:10:12 2012 +0100
[2378] Add missing callback to MasterLoader
The tentative interface of the MasterLoader was missing a callback to
add RRsets.
Also, include some small changes to the interface - pass RRClass as
reference and have DEFAULT options value for no special options.
commit 0c89bc5d564a9961538d4efa47a3194f239cf681
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Nov 27 14:36:47 2012 +0100
[2378] Tests for the loading from file
They are similar to the ones for copy mode. Should they be unified in
some way?
commit abd1274d3bc04463752ff163bf156f8d21cf376e
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Nov 27 14:14:10 2012 +0100
[2378] Consider masterfile errors in ZoneLoader docs
commit 33faa4833595ec772f8b5cfd0db01059bac078f1
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Nov 27 14:03:44 2012 +0100
[2378] Test throwing when missing zone
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/tests/zone_loader_unittest.cc | 64 +++++++++++++++++++++----
src/lib/datasrc/zone_loader.cc | 45 +++++++++++++++--
src/lib/datasrc/zone_loader.h | 18 +++++--
src/lib/dns/master_loader.cc | 14 ++++--
src/lib/dns/master_loader.h | 10 ++--
src/lib/dns/tests/master_loader_unittest.cc | 8 +++-
6 files changed, 131 insertions(+), 28 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/tests/zone_loader_unittest.cc b/src/lib/datasrc/tests/zone_loader_unittest.cc
index 3910894..ccc5b9d 100644
--- a/src/lib/datasrc/tests/zone_loader_unittest.cc
+++ b/src/lib/datasrc/tests/zone_loader_unittest.cc
@@ -32,8 +32,11 @@
using isc::dns::RRClass;
using isc::dns::Name;
+using isc::dns::RRType;
+using isc::dns::ConstRRsetPtr;
using std::string;
using std::vector;
+using boost::shared_ptr;
using namespace isc::datasrc;
namespace {
@@ -42,7 +45,8 @@ class MockClient : public DataSourceClient {
public:
MockClient() :
commit_called_(false),
- missing_zone_(false)
+ missing_zone_(false),
+ rrclass_(RRClass::IN())
{}
virtual FindResult findZone(const Name&) const {
isc_throw(isc::NotImplemented, "Method not used in tests");
@@ -67,6 +71,8 @@ public:
bool commit_called_;
// If set to true, getUpdater returns NULL
bool missing_zone_;
+ // The pretended class of the client. Usualy IN, but can be overriden.
+ RRClass rrclass_;
};
// The updater isn't really correct according to the API. For example,
@@ -77,10 +83,11 @@ public:
class Updater : public ZoneUpdater {
public:
Updater(MockClient* client) :
- client_(client)
+ client_(client),
+ finder_(client_->rrclass_)
{}
virtual ZoneFinder& getFinder() {
- isc_throw(isc::NotImplemented, "Method not used in tests");
+ return (finder_);
}
virtual void addRRset(const isc::dns::AbstractRRset& rrset) {
if (client_->commit_called_) {
@@ -96,6 +103,34 @@ public:
}
private:
MockClient* client_;
+ class Finder : public ZoneFinder {
+ public:
+ Finder(const RRClass& rrclass) :
+ class_(rrclass)
+ {}
+ virtual RRClass getClass() const {
+ return (class_);
+ }
+ virtual Name getOrigin() const {
+ isc_throw(isc::NotImplemented, "Method not used in tests");
+ }
+ virtual shared_ptr<Context> find(const Name&, const RRType&,
+ const FindOptions)
+ {
+ isc_throw(isc::NotImplemented, "Method not used in tests");
+ }
+ virtual shared_ptr<Context> findAll(const Name&,
+ vector<ConstRRsetPtr>&,
+ const FindOptions)
+ {
+ isc_throw(isc::NotImplemented, "Method not used in tests");
+ }
+ virtual FindNSEC3Result findNSEC3(const Name&, bool) {
+ isc_throw(isc::NotImplemented, "Method not used in tests");
+ }
+ private:
+ const RRClass class_;
+ } finder_;
};
ZoneUpdaterPtr
@@ -136,7 +171,7 @@ private:
// FIXME: We should be destroying it by ZoneTableSegment::destroy.
// But the shared pointer won't let us, will it?
- boost::shared_ptr<memory::ZoneTableSegment> ztable_segment_;
+ shared_ptr<memory::ZoneTableSegment> ztable_segment_;
protected:
memory::InMemoryClient source_client_;
// This one is mocked. It will help us see what is happening inside.
@@ -242,6 +277,14 @@ TEST_F(ZoneLoaderTest, copyMissingSource) {
source_client_), DataSourceError);
}
+// The class of the source and destination are different
+TEST_F(ZoneLoaderTest, classMismatch) {
+ destination_client_.rrclass_ = RRClass::CH();
+ prepareSource(Name::ROOT_NAME(), "root.zone");
+ EXPECT_THROW(ZoneLoader(destination_client_, Name::ROOT_NAME(),
+ source_client_), isc::InvalidParameter);
+}
+
// Load an unsigned zone, all at once
TEST_F(ZoneLoaderTest, loadUnsigned) {
ZoneLoader loader(destination_client_, Name::ROOT_NAME(),
@@ -340,12 +383,13 @@ TEST_F(ZoneLoaderTest, loadNoSuchFile) {
// And it also throws when there's a syntax error in the master file
TEST_F(ZoneLoaderTest, loadSyntaxError) {
- EXPECT_THROW(ZoneLoader(destination_client_, Name::ROOT_NAME(),
- // This is not a master file for sure
- // (misusing a file that happens to be there
- // already).
- TEST_DATA_DIR "/example.org.sqlite3"),
- MasterFileError);
+ ZoneLoader loader(destination_client_, Name::ROOT_NAME(),
+ // This is not a master file for sure
+ // (misusing a file that happens to be there
+ // already).
+ TEST_DATA_DIR "/example.org.sqlite3");
+ EXPECT_THROW(loader.load(), MasterFileError);
+ EXPECT_FALSE(destination_client_.commit_called_);
}
}
diff --git a/src/lib/datasrc/zone_loader.cc b/src/lib/datasrc/zone_loader.cc
index 5fc03fa..b77f6b8 100644
--- a/src/lib/datasrc/zone_loader.cc
+++ b/src/lib/datasrc/zone_loader.cc
@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
#include <datasrc/zone_loader.h>
+#include <datasrc/master_loader_callbacks.h>
#include <datasrc/client.h>
#include <datasrc/data_source.h>
@@ -23,6 +24,7 @@
using isc::dns::Name;
using isc::dns::ConstRRsetPtr;
+using isc::dns::MasterLoader;
namespace isc {
namespace datasrc {
@@ -43,6 +45,32 @@ ZoneLoader::ZoneLoader(DataSourceClient& destination, const Name& zone_name,
isc_throw(DataSourceError, "Zone " << zone_name << " not found in "
"destination data source, can't fill it with data");
}
+ // The dereference of zone_finder is safe, if we can get iterator, we can
+ // get a finder.
+ //
+ // TODO: We probably need a getClass on the data source itself.
+ if (source.findZone(zone_name).zone_finder->getClass() !=
+ updater_->getFinder().getClass()) {
+ isc_throw(isc::InvalidParameter,
+ "Source and destination class mismatch");
+ }
+}
+
+ZoneLoader::ZoneLoader(DataSourceClient& destination, const Name& zone_name,
+ const char* filename) :
+ updater_(destination.getUpdater(zone_name, true, false)),
+ loader_(new MasterLoader(filename, zone_name,
+ // TODO: Maybe we should have getClass() on the
+ // data source?
+ updater_->getFinder().getClass(),
+ createMasterLoaderCallbacks(zone_name,
+ updater_->getFinder().getClass(),
+ &loaded_ok_),
+ createMasterLoaderAddCallback(*updater_))),
+ complete_(false),
+ loaded_ok_(true)
+{
+
}
namespace {
@@ -75,7 +103,20 @@ ZoneLoader::loadIncremental(size_t limit) {
"Loading has been completed previously");
}
- if (iterator_ != ZoneIteratorPtr()) {
+ if (iterator_ == ZoneIteratorPtr()) {
+ assert(loader_.get() != NULL);
+ if (loader_->loadIncremental(limit)) {
+ complete_ = true;
+ if (!loaded_ok_) {
+ isc_throw(MasterFileError, "Error while loading master file");
+ } else {
+ updater_->commit();
+ }
+ return (true);
+ } else {
+ return (false);
+ }
+ } else {
if (copyRRsets(updater_, iterator_, limit)) {
updater_->commit();
complete_ = true;
@@ -83,8 +124,6 @@ ZoneLoader::loadIncremental(size_t limit) {
} else {
return (false);
}
- } else {
- isc_throw(isc::NotImplemented, "The master file way is not ready yet");
}
}
diff --git a/src/lib/datasrc/zone_loader.h b/src/lib/datasrc/zone_loader.h
index 1bfaf29..65be733 100644
--- a/src/lib/datasrc/zone_loader.h
+++ b/src/lib/datasrc/zone_loader.h
@@ -17,8 +17,11 @@
#include <datasrc/data_source.h>
+#include <dns/master_loader.h>
+
#include <cstdlib> // For size_t
#include <boost/shared_ptr.hpp>
+#include <boost/scoped_ptr.hpp>
namespace isc {
namespace dns {
@@ -69,8 +72,6 @@ public:
/// beforehead.
/// \throw DataSourceError in case of other (possibly low-level) errors,
/// such as read-only data source or database error.
- /// \throw MasterFileError when the master_file is badly formatted or some
- /// similar problem is found when loading the master file.
ZoneLoader(DataSourceClient& destination, const isc::dns::Name& zone_name,
const char* master_file);
@@ -79,13 +80,12 @@ public:
/// This initializes the zone loader to read from another data source.
/// It'll effectively copy data from one data source to another.
///
- /// The RR class of both source and destination must be the same. But
- /// it is not checked.
- ///
/// \param destination The data source into which the loaded data should
/// go.
/// \param zone_name The origin of the zone.
/// \param source The data source from which the data would be read.
+ /// \throw InvalidParameter in case the class of destination and source
+ /// differs.
/// \throw DataSourceError in case the zone does not exist in destination.
/// This class does not support creating brand new zones, only loading
/// data into them. In case a new zone is needed, it must be created
@@ -105,6 +105,8 @@ public:
/// \throw InvalidOperation in case the loading was already completed
/// before this call.
/// \throw DataSourceError in case some error (possibly low-level) happens.
+ /// \throw MasterFileError when the master_file is badly formatted or some
+ /// similar problem is found when loading the master file.
void load() {
while (!loadIncremental(1000)) { // 1000 is arbitrary largish number
// Body intentionally left blank.
@@ -129,14 +131,20 @@ public:
/// before this call (by load() or by a loadIncremental that returned
/// true).
/// \throw DataSourceError in case some error (possibly low-level) happens.
+ /// \throw MasterFileError when the master_file is badly formatted or some
+ /// similar problem is found when loading the master file.
bool loadIncremental(size_t limit);
private:
/// \brief The iterator used as source of data in case of the copy mode.
const ZoneIteratorPtr iterator_;
/// \brief The destination zone updater
const ZoneUpdaterPtr updater_;
+ /// \brief The master loader (for the loader mode)
+ const boost::scoped_ptr<isc::dns::MasterLoader> loader_;
/// \brief Indicator if loading was completed
bool complete_;
+ /// \brief Was the loading successful?
+ bool loaded_ok_;
};
}
diff --git a/src/lib/dns/master_loader.cc b/src/lib/dns/master_loader.cc
index 5838238..9f3b7ea 100644
--- a/src/lib/dns/master_loader.cc
+++ b/src/lib/dns/master_loader.cc
@@ -21,13 +21,15 @@ class MasterLoader::MasterLoaderImpl {
public:
MasterLoaderImpl(const char* master_file,
const Name& zone_origin,
- const RRClass zone_class,
- MasterLoaderCallbacks callbacks,
+ const RRClass& zone_class,
+ const MasterLoaderCallbacks& callbacks,
+ const AddRRsetCallback& add_callback,
MasterLoader::Options options) :
lexer_(),
zone_origin_(zone_origin),
zone_class_(zone_class),
callbacks_(callbacks),
+ add_callback_(add_callback),
options_(options)
{
lexer_.pushSource(master_file);
@@ -48,18 +50,20 @@ private:
const Name& zone_origin_;
const RRClass zone_class_;
MasterLoaderCallbacks callbacks_;
+ AddRRsetCallback add_callback_;
MasterLoader::Options options_;
RRsetPtr current_rrset_;
};
MasterLoader::MasterLoader(const char* master_file,
const Name& zone_origin,
- const RRClass zone_class,
- MasterLoaderCallbacks callbacks,
+ const RRClass& zone_class,
+ const MasterLoaderCallbacks& callbacks,
+ const AddRRsetCallback& add_callback,
Options options)
{
impl_ = new MasterLoaderImpl(master_file, zone_origin,
- zone_class, callbacks, options);
+ zone_class, callbacks, add_callback, options);
}
MasterLoader::~MasterLoader() {
diff --git a/src/lib/dns/master_loader.h b/src/lib/dns/master_loader.h
index 86c4f58..a150087 100644
--- a/src/lib/dns/master_loader.h
+++ b/src/lib/dns/master_loader.h
@@ -25,13 +25,15 @@ namespace dns {
class MasterLoader {
public:
enum Options {
- MANY_ERRORS, ///< Lenient mode
+ DEFAULT = 0,
+ MANY_ERRORS ///< Lenient mode
};
MasterLoader(const char* master_file,
const Name& zone_origin,
- const RRClass zone_class,
- MasterLoaderCallbacks callbacks,
- Options options);
+ const RRClass& zone_class,
+ const MasterLoaderCallbacks& callbacks,
+ const AddRRsetCallback& add_callback,
+ Options options = DEFAULT);
~MasterLoader();
bool loadIncremental(size_t count_limit);
diff --git a/src/lib/dns/tests/master_loader_unittest.cc b/src/lib/dns/tests/master_loader_unittest.cc
index f9fe1f2..0465a01 100644
--- a/src/lib/dns/tests/master_loader_unittest.cc
+++ b/src/lib/dns/tests/master_loader_unittest.cc
@@ -46,11 +46,17 @@ public:
}
}
+ void addRRset(const RRsetPtr&) {
+ // TODO
+ }
+
void
setLoader(const char* file, const Name& origin, const RRClass rrclass,
const MasterLoader::Options options)
{
- loader.reset(new MasterLoader(file, origin, rrclass, callbacks_, options));
+ loader.reset(new MasterLoader(file, origin, rrclass, callbacks_,
+ boost::bind(&MasterLoaderTest::addRRset,
+ this, _1), options));
}
MasterLoaderCallbacks callbacks_;
More information about the bind10-changes
mailing list