Commit a92defd1 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[2209] Hack the ZoneTableSegment into MemoryClient

This branch needs the MemoryClient to have its Zonetablesegment. But it
doesn't have one now and it is not the task of this branch to put it in
there. So I added it inside in somewhat ad-hoc manner.

This is hairy and adds bunch of temporary methods. If there's a better
approach, let's use it. But taking this for now to be cleaned up in some
follow-up ticket.
parent a09e57e2
......@@ -22,6 +22,7 @@
#include <datasrc/memory/treenode_rrset.h>
#include <datasrc/memory/zone_finder.h>
#include <datasrc/memory/zone_data_loader.h>
#include <datasrc/memory/zone_table_segment.h>
#include <util/memory_segment_local.h>
......@@ -66,7 +67,14 @@ public:
InMemoryClient::InMemoryClient(util::MemorySegment& mem_sgmt,
RRClass rrclass) :
mem_sgmt_(mem_sgmt),
// FIXME: We currently use the temporary and "unsupported"
// constructor of the zone table segment. Once we clarify
// how the config thing, we want to change it.
zone_table_segment_(ZoneTableSegment::create(mem_sgmt)),
// Use the memory segment from the zone table segment. Currently,
// it is the same one as the one in parameter, but that will
// probably change.
mem_sgmt_(zone_table_segment_->getMemorySegment()),
rrclass_(rrclass),
zone_count_(0)
{
......@@ -76,13 +84,19 @@ InMemoryClient::InMemoryClient(util::MemorySegment& mem_sgmt,
file_name_tree_ = FileNameTree::create(mem_sgmt_, false);
zone_table_ = holder.release();
// TODO: Once the table is created inside the zone table segment, use that
// one.
zone_table_segment_->getHeader().setTable(zone_table_);
}
InMemoryClient::~InMemoryClient() {
FileNameDeleter deleter;
FileNameTree::destroy(mem_sgmt_, file_name_tree_, deleter);
// TODO: Once the table is created inside the zone table segment, do not
// destroy it here.
ZoneTable::destroy(mem_sgmt_, zone_table_, rrclass_);
ZoneTableSegment::destroy(zone_table_segment_);
}
result::Result
......
......@@ -34,6 +34,8 @@ class RRsetList;
namespace datasrc {
namespace memory {
class ZoneTableSegment;
/// \brief A data source client that holds all necessary data in memory.
///
/// The \c InMemoryClient class provides an access to a conceptual data
......@@ -175,6 +177,18 @@ public:
getJournalReader(const isc::dns::Name& zone, uint32_t begin_serial,
uint32_t end_serial) const;
/// \brief Get the zone table segment used
///
/// This is a low-level function, used to some internal handling when,
/// for example, reloading the data inside the in-memory data source.
/// It should not be generally used.
///
/// \todo Consider making this private and add a friend declaration
/// for the ClientList.
ZoneTableSegment& getZoneTableSegment() {
return (*zone_table_segment_);
}
private:
// Some type aliases
typedef DomainTree<std::string> FileNameTree;
......@@ -186,6 +200,7 @@ private:
const std::string& filename,
ZoneData* zone_data);
ZoneTableSegment* zone_table_segment_;
util::MemorySegment& mem_sgmt_;
const isc::dns::RRClass rrclass_;
unsigned int zone_count_;
......
......@@ -28,6 +28,11 @@ ZoneTableSegment::create(const isc::data::Element&) {
return (new ZoneTableSegmentLocal);
}
ZoneTableSegment*
ZoneTableSegment::create(isc::util::MemorySegment& segment) {
return (new ZoneTableSegmentLocal(segment));
}
void
ZoneTableSegment::destroy(ZoneTableSegment *segment) {
delete segment;
......
......@@ -121,6 +121,18 @@ public:
/// \return Returns a ZoneTableSegment object
static ZoneTableSegment* create(const isc::data::Element& config);
/// \brief Temporary/Testing version of create.
///
/// This exists as a temporary solution during the migration phase
/// towards using the ZoneTableSegment. It doesn't take a config,
/// but a memory segment instead. If you can, you should use the
/// other version, this one will be gone soon.
///
/// \param segment The memory segment to use.
/// \return Returns a new ZoneTableSegment object.
/// \todo Remove this method.
static ZoneTableSegment* create(isc::util::MemorySegment& segment);
/// \brief Destroy a ZoneTableSegment
///
/// This method destroys the passed ZoneTableSegment. It must be
......
......@@ -37,7 +37,13 @@ protected:
/// Instances are expected to be created by the factory method
/// (\c ZoneTableSegment::create()), so this constructor is
/// protected.
ZoneTableSegmentLocal()
ZoneTableSegmentLocal() :
mem_sgmt_(mem_sgmt_local_)
{}
// TODO: A temporary constructor, for tests for now. Needs to
// be removed.
ZoneTableSegmentLocal(isc::util::MemorySegment& segment) :
mem_sgmt_(segment)
{}
public:
/// \brief Destructor
......@@ -60,7 +66,8 @@ public:
const dns::RRClass& rrclass);
private:
ZoneTableHeader header_;
isc::util::MemorySegmentLocal mem_sgmt_;
isc::util::MemorySegmentLocal mem_sgmt_local_;
isc::util::MemorySegment& mem_sgmt_;
};
} // namespace memory
......
......@@ -765,4 +765,12 @@ TEST_F(MemoryClientTest, getJournalReaderNotImplemented) {
isc::NotImplemented);
}
TEST_F(MemoryClientTest, getZoneTableSegment) {
// It's hard to test this method. It returns a reference, so we can't even
// check for non-NULL. Checking it doesn't throw/crash is good enough for
// now, the method will be used in other functions, so checked it works
// implicitly.
EXPECT_NO_THROW(client_->getZoneTableSegment());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment