BIND 10 trac2850_2, updated. 1815740f4154dea79aa15ec64cffe2f5d010769d [2850] Move reset() method to the base ZoneTableSegment class
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu May 2 14:25:23 UTC 2013
The branch, trac2850_2 has been updated
via 1815740f4154dea79aa15ec64cffe2f5d010769d (commit)
via 0b7af64f6b3a567371a38ceb83001008dcc8f4b2 (commit)
from a1d81937904fd5f646f40c655975855aea5985d4 (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 1815740f4154dea79aa15ec64cffe2f5d010769d
Author: Mukund Sivaraman <muks at isc.org>
Date: Thu May 2 19:44:21 2013 +0530
[2850] Move reset() method to the base ZoneTableSegment class
Also update ZoneTableSegmentMapped testcases to test the created segment
as a base ZoneTableSegment.
commit 0b7af64f6b3a567371a38ceb83001008dcc8f4b2
Author: Mukund Sivaraman <muks at isc.org>
Date: Thu May 2 19:30:50 2013 +0530
[2850] Update comment about not verifying checksum for a read-only segment
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/memory/zone_table_segment.h | 45 ++++++++++++++++++++
src/lib/datasrc/memory/zone_table_segment_local.cc | 7 +++
src/lib/datasrc/memory/zone_table_segment_local.h | 6 +++
.../datasrc/memory/zone_table_segment_mapped.cc | 8 ++--
src/lib/datasrc/memory/zone_table_segment_mapped.h | 30 +++----------
.../memory/zone_table_segment_mapped_unittest.cc | 31 ++++++++------
.../datasrc/tests/memory/zone_table_segment_test.h | 4 ++
.../tests/memory/zone_table_segment_unittest.cc | 7 +++
8 files changed, 95 insertions(+), 43 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/memory/zone_table_segment.h b/src/lib/datasrc/memory/zone_table_segment.h
index d62426f..f2be970 100644
--- a/src/lib/datasrc/memory/zone_table_segment.h
+++ b/src/lib/datasrc/memory/zone_table_segment.h
@@ -140,6 +140,51 @@ public:
///
/// \param segment The segment to destroy.
static void destroy(ZoneTableSegment* segment);
+
+ /// \brief The mode using which to open a ZoneTableSegment.
+ ///
+ /// - CREATE: If the backing memory store doesn't exist, create
+ /// it. If it exists, overwrite it with a newly created
+ /// memory store. In both cases, open the newly created
+ /// memory store in read+write mode.
+ ///
+ /// - READ_WRITE: If the backing memory store doesn't exist, create
+ /// it. If it exists, use the existing memory store
+ /// as-is. In both cases, open the memory store in
+ /// read+write mode.
+ ///
+ /// - READ_ONLY: If the backing memory store doesn't exist, throw an
+ /// exception. If it exists, open the existing memory
+ /// store in read-only mode.
+ enum MemorySegmentOpenMode {
+ CREATE,
+ READ_WRITE,
+ READ_ONLY
+ };
+
+ /// \brief Unload the current memory store (if loaded) and load the
+ /// specified one.
+ ///
+ /// See the \c MemorySegmentOpenMode documentation above for the
+ /// various modes in which a ZoneTableSegment can be created.
+ ///
+ /// \c params should contain an implementation-defined
+ /// configuration. See the specific \c ZoneTableSegment
+ /// implementation class for details of what to pass in this
+ /// argument.
+ ///
+ /// \throws isc::InvalidParameter if the configuration in \c params
+ /// has incorrect syntax.
+ /// \throws isc::Unexpected for a variety of cases where an
+ /// unexpected condition occurs. These should not occur normally in
+ /// correctly written code.
+ ///
+ /// \param mode The open mode (see the MemorySegmentOpenMode
+ /// documentation).
+ /// \param params An element containing implementation-specific
+ /// config (see the description).
+ virtual void reset(MemorySegmentOpenMode mode,
+ isc::data::ConstElementPtr params) = 0;
};
} // namespace memory
diff --git a/src/lib/datasrc/memory/zone_table_segment_local.cc b/src/lib/datasrc/memory/zone_table_segment_local.cc
index de69d4a..dbcb54f 100644
--- a/src/lib/datasrc/memory/zone_table_segment_local.cc
+++ b/src/lib/datasrc/memory/zone_table_segment_local.cc
@@ -37,6 +37,13 @@ ZoneTableSegmentLocal::~ZoneTableSegmentLocal() {
assert(mem_sgmt_.allMemoryDeallocated());
}
+void
+ZoneTableSegmentLocal::reset(MemorySegmentOpenMode,
+ isc::data::ConstElementPtr)
+{
+ // This method doesn't do anything in this implementation.
+}
+
// After more methods' definitions are added here, it would be a good
// idea to move getHeader() and getMemorySegment() definitions to the
// header file.
diff --git a/src/lib/datasrc/memory/zone_table_segment_local.h b/src/lib/datasrc/memory/zone_table_segment_local.h
index 7728c1a..6430d2a 100644
--- a/src/lib/datasrc/memory/zone_table_segment_local.h
+++ b/src/lib/datasrc/memory/zone_table_segment_local.h
@@ -61,6 +61,12 @@ public:
return (true);
}
+ /// \brief This method currently doesn't do anything.
+ ///
+ /// \c mode and \c params args are currently ignored.
+ virtual void reset(MemorySegmentOpenMode mode,
+ isc::data::ConstElementPtr params);
+
private:
isc::util::MemorySegmentLocal mem_sgmt_;
ZoneTableHeader header_;
diff --git a/src/lib/datasrc/memory/zone_table_segment_mapped.cc b/src/lib/datasrc/memory/zone_table_segment_mapped.cc
index f28d1ee..51ce9e9 100644
--- a/src/lib/datasrc/memory/zone_table_segment_mapped.cc
+++ b/src/lib/datasrc/memory/zone_table_segment_mapped.cc
@@ -167,10 +167,10 @@ ZoneTableSegmentMapped::reset(MemorySegmentOpenMode mode,
"There is no previously saved checksum in a "
"mapped segment opened in read-only mode.");
}
- // The segment was already shrunk when it was last closed. Check
- // that its checksum is consistent.
- // FIXME: We can't really do this as we can't set the checksum
- // to 0 for checksum calculation in a read-only segment.
+
+ // We can't verify the checksum here as we can't set the
+ // checksum to 0 for checksum calculation in a read-only
+ // segment. So we continue without verifying the checksum.
// There must be a previously saved ZoneTableHeader.
result = segment->getNamedAddress("zone_table_header");
diff --git a/src/lib/datasrc/memory/zone_table_segment_mapped.h b/src/lib/datasrc/memory/zone_table_segment_mapped.h
index d73528b..5e37a81 100644
--- a/src/lib/datasrc/memory/zone_table_segment_mapped.h
+++ b/src/lib/datasrc/memory/zone_table_segment_mapped.h
@@ -71,32 +71,12 @@ public:
/// writable.
virtual bool isWritable() const;
- /// \brief The mode using which to open a ZoneTableSegment around a
- /// mapped file.
- ///
- /// - CREATE: If the mapped file doesn't exist, create it. If it
- /// exists, overwrite it with a newly created mapped
- /// file. In both cases, open the newly created mapped
- /// file in read+write mode.
- ///
- /// - READ_WRITE: If the mapped file doesn't exist, create it. If it
- /// exists, use the existing mapped file. In both
- /// cases, open the mapped file in read+write mode.
- ///
- /// - READ_ONLY: If the mapped file doesn't exist, throw an
- /// exception. If it exists, open the existing mapped
- /// file in read-only mode.
- enum MemorySegmentOpenMode {
- CREATE,
- READ_WRITE,
- READ_ONLY
- };
-
/// \brief Unmap the current file (if mapped) and map the specified
/// one.
///
- /// See the \c MemorySegmentOpenMode documentation above for the
- /// various modes in which a ZoneTableSegment can be created.
+ /// See the \c MemorySegmentOpenMode documentation (in
+ /// \c ZoneTableSegment class) for the various modes in which a
+ /// \c ZoneTableSegmentMapped can be created.
///
/// \c params should be a map containing a "mapped-file" key that
/// points to a string value containing the filename of a mapped
@@ -110,8 +90,8 @@ public:
/// unexpected condition occurs. These should not occur normally in
/// correctly written code.
///
- /// \param mode The open mode (see the MemorySegmentOpenMode
- /// documentation).
+ /// \param mode The open mode (see the \c MemorySegmentOpenMode
+ /// documentation in \c ZoneTableSegment class).
/// \param params An element containing config for the mapped file
/// (see the description).
virtual void reset(MemorySegmentOpenMode mode,
diff --git a/src/lib/datasrc/tests/memory/zone_table_segment_mapped_unittest.cc b/src/lib/datasrc/tests/memory/zone_table_segment_mapped_unittest.cc
index c26b421..6a32538 100644
--- a/src/lib/datasrc/tests/memory/zone_table_segment_mapped_unittest.cc
+++ b/src/lib/datasrc/tests/memory/zone_table_segment_mapped_unittest.cc
@@ -33,13 +33,16 @@ const std::string mapped_file = TEST_DATA_BUILDDIR "/test.mapped";
class ZoneTableSegmentMappedTest : public ::testing::Test {
protected:
ZoneTableSegmentMappedTest() :
- ztable_segment_(dynamic_cast<ZoneTableSegmentMapped*>(
- ZoneTableSegment::create(RRClass::IN(), "mapped"))),
+ ztable_segment_(
+ ZoneTableSegment::create(RRClass::IN(), "mapped")),
config_params_(
Element::fromJSON("{\"mapped-file\": \"" + mapped_file + "\"}"))
{
- // Verify that a ZoneTableSegmentMapped is created.
EXPECT_NE(static_cast<void*>(NULL), ztable_segment_);
+ // Verify that a ZoneTableSegmentMapped is created.
+ ZoneTableSegmentMapped* mapped_segment =
+ dynamic_cast<ZoneTableSegmentMapped*>(ztable_segment_);
+ EXPECT_NE(static_cast<void*>(NULL), mapped_segment);
}
~ZoneTableSegmentMappedTest() {
@@ -51,7 +54,7 @@ protected:
ztable_segment_ = NULL;
}
- ZoneTableSegmentMapped* ztable_segment_;
+ ZoneTableSegment* ztable_segment_;
const ConstElementPtr config_params_;
};
@@ -80,25 +83,25 @@ loadAction(MemorySegment&) {
TEST_F(ZoneTableSegmentMappedTest, resetBadConfig) {
// Not a map
EXPECT_THROW({
- ztable_segment_->reset(ZoneTableSegmentMapped::CREATE,
+ ztable_segment_->reset(ZoneTableSegment::CREATE,
Element::fromJSON("42"));
}, isc::InvalidParameter);
// Empty map
EXPECT_THROW({
- ztable_segment_->reset(ZoneTableSegmentMapped::CREATE,
+ ztable_segment_->reset(ZoneTableSegment::CREATE,
Element::fromJSON("{}"));
}, isc::InvalidParameter);
// No "mapped-file" key
EXPECT_THROW({
- ztable_segment_->reset(ZoneTableSegmentMapped::CREATE,
+ ztable_segment_->reset(ZoneTableSegment::CREATE,
Element::fromJSON("{\"foo\": \"bar\"}"));
}, isc::InvalidParameter);
// Value of "mapped-file" key is not a string
EXPECT_THROW({
- ztable_segment_->reset(ZoneTableSegmentMapped::CREATE,
+ ztable_segment_->reset(ZoneTableSegment::CREATE,
Element::fromJSON("{\"mapped-file\": 42}"));
}, isc::InvalidParameter);
@@ -115,7 +118,7 @@ TEST_F(ZoneTableSegmentMappedTest, reset) {
// By default, the mapped file doesn't exist, so we cannot open it
// in READ_ONLY mode (which does not create the file).
EXPECT_THROW({
- ztable_segment_->reset(ZoneTableSegmentMapped::READ_ONLY,
+ ztable_segment_->reset(ZoneTableSegment::READ_ONLY,
config_params_);
}, MemorySegmentOpenError);
@@ -129,7 +132,7 @@ TEST_F(ZoneTableSegmentMappedTest, reset) {
// READ_WRITE mode must create the mapped file if it doesn't exist
// (and must not result in an exception).
- ztable_segment_->reset(ZoneTableSegmentMapped::READ_WRITE,
+ ztable_segment_->reset(ZoneTableSegment::READ_WRITE,
config_params_);
// This must not throw now.
EXPECT_TRUE(ztable_segment_->isWritable());
@@ -140,21 +143,21 @@ TEST_F(ZoneTableSegmentMappedTest, reset) {
// Let's try to re-open the mapped file in READ_ONLY mode. It should
// not fail now.
- ztable_segment_->reset(ZoneTableSegmentMapped::READ_ONLY,
+ ztable_segment_->reset(ZoneTableSegment::READ_ONLY,
config_params_);
EXPECT_FALSE(ztable_segment_->isWritable());
// Re-creating the mapped file should erase old data and should not
// trigger any exceptions inside reset() due to old data (such as
// named addresses).
- ztable_segment_->reset(ZoneTableSegmentMapped::CREATE,
+ ztable_segment_->reset(ZoneTableSegment::CREATE,
config_params_);
EXPECT_TRUE(ztable_segment_->isWritable());
// When we reset() and it fails, then the segment should be
// unusable.
EXPECT_THROW({
- ztable_segment_->reset(ZoneTableSegmentMapped::CREATE,
+ ztable_segment_->reset(ZoneTableSegment::CREATE,
Element::fromJSON("{}"));
}, isc::InvalidParameter);
// The following should throw now.
@@ -166,7 +169,7 @@ TEST_F(ZoneTableSegmentMappedTest, reset) {
// READ_WRITE with an existing map file ought to work too. This
// would use existing named addresses.
- ztable_segment_->reset(ZoneTableSegmentMapped::READ_WRITE,
+ ztable_segment_->reset(ZoneTableSegment::READ_WRITE,
config_params_);
EXPECT_TRUE(ztable_segment_->isWritable());
}
diff --git a/src/lib/datasrc/tests/memory/zone_table_segment_test.h b/src/lib/datasrc/tests/memory/zone_table_segment_test.h
index f1cfbee..e76a971 100644
--- a/src/lib/datasrc/tests/memory/zone_table_segment_test.h
+++ b/src/lib/datasrc/tests/memory/zone_table_segment_test.h
@@ -41,6 +41,10 @@ public:
ZoneTable::destroy(mem_sgmt_, header_.getTable());
}
+ virtual void reset(MemorySegmentOpenMode, isc::data::ConstElementPtr) {
+ // This method doesn't do anything.
+ }
+
virtual ZoneTableHeader& getHeader() {
return (header_);
}
diff --git a/src/lib/datasrc/tests/memory/zone_table_segment_unittest.cc b/src/lib/datasrc/tests/memory/zone_table_segment_unittest.cc
index 1ef997c..1a57133 100644
--- a/src/lib/datasrc/tests/memory/zone_table_segment_unittest.cc
+++ b/src/lib/datasrc/tests/memory/zone_table_segment_unittest.cc
@@ -51,6 +51,13 @@ TEST_F(ZoneTableSegmentTest, create) {
UnknownSegmentType);
}
+TEST_F(ZoneTableSegmentTest, reset) {
+ // reset() currently doesn't do anything in a local segment. But
+ // test the API.
+ ztable_segment_->reset(ZoneTableSegment::CREATE,
+ Element::fromJSON("{}"));
+}
+
// Helper function to check const and non-const methods.
template <typename TS, typename TH, typename TT>
void
More information about the bind10-changes
mailing list