#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>
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)
{
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
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
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;
const std::string& filename,
ZoneData* zone_data);
+ ZoneTableSegment* zone_table_segment_;
util::MemorySegment& mem_sgmt_;
const isc::dns::RRClass rrclass_;
unsigned int zone_count_;
return (new ZoneTableSegmentLocal);
}
+ZoneTableSegment*
+ZoneTableSegment::create(isc::util::MemorySegment& segment) {
+ return (new ZoneTableSegmentLocal(segment));
+}
+
void
ZoneTableSegment::destroy(ZoneTableSegment *segment) {
delete segment;
/// \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
/// 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
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
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());
+}
+
}