libfoedus-core
FOEDUS Core Library
foedus::snapshot::SnapshotMetadata Struct Referencefinal

Represents the data in one snapshot metadata file. More...

Detailed Description

Represents the data in one snapshot metadata file.

One snapshot metadata file is written for each snapshotting as an xml file. It contains metadata of all storages and a few other global things.

We write it out as part of snapshotting. We read it at restart.

Definition at line 44 of file snapshot_metadata.hpp.

#include <snapshot_metadata.hpp>

Inheritance diagram for foedus::snapshot::SnapshotMetadata:
Collaboration diagram for foedus::snapshot::SnapshotMetadata:

Public Member Functions

void clear ()
 
storage::Metadataget_metadata (storage::StorageId id)
 
ErrorStack load (tinyxml2::XMLElement *element) override
 Reads the content of this object from the given XML element. More...
 
ErrorStack save (tinyxml2::XMLElement *element) const override
 Writes the content of this object to the given XML element. More...
 
const char * get_tag_name () const override
 Returns an XML tag name for this object as a root element. More...
 
void assign (const foedus::externalize::Externalizable *other) override
 Polymorphic assign operator. More...
 
- Public Member Functions inherited from foedus::externalize::Externalizable
ErrorStack load_from_string (const std::string &xml)
 Load the content of this object from the given XML string. More...
 
void save_to_stream (std::ostream *ptr) const
 Invokes save() and directs the resulting XML text to the given stream. More...
 
ErrorStack load_from_file (const fs::Path &path)
 Load the content of this object from the specified XML file. More...
 
ErrorStack save_to_file (const fs::Path &path) const
 Atomically and durably writes out this object to the specified XML file. More...
 

Public Attributes

SnapshotId id_
 Equivalent to Snapshot::id_. More...
 
Epoch::EpochInteger base_epoch_
 Equivalent to Snapshot::base_epoch_. More...
 
Epoch::EpochInteger valid_until_epoch_
 Equivalent to Snapshot::valid_until_epoch_. More...
 
storage::StorageId largest_storage_id_
 The largest StorageId we so far observed. More...
 
storage::StorageControlBlockstorage_control_blocks_
 control block of all storages. More...
 
memory::AlignedMemory storage_control_blocks_memory_
 Memory backing storage_control_blocks_. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from foedus::externalize::Externalizable
static ErrorStack insert_comment (tinyxml2::XMLElement *element, const std::string &comment)
 
static ErrorStack append_comment (tinyxml2::XMLElement *parent, const std::string &comment)
 
static ErrorStack create_element (tinyxml2::XMLElement *parent, const std::string &name, tinyxml2::XMLElement **out)
 
template<typename T >
static ErrorStack add_element (tinyxml2::XMLElement *parent, const std::string &tag, const std::string &comment, T value)
 Only declaration in header. More...
 
template<uint MAXLEN, typename CHAR >
static ErrorStack add_element (tinyxml2::XMLElement *parent, const std::string &tag, const std::string &comment, const assorted::FixedString< MAXLEN, CHAR > &value)
 
template<typename T >
static ErrorStack add_element (tinyxml2::XMLElement *parent, const std::string &tag, const std::string &comment, const std::vector< T > &value)
 vector version More...
 
template<typename ENUM >
static ErrorStack add_enum_element (tinyxml2::XMLElement *parent, const std::string &tag, const std::string &comment, ENUM value)
 enum version More...
 
static ErrorStack add_child_element (tinyxml2::XMLElement *parent, const std::string &tag, const std::string &comment, const Externalizable &child)
 child Externalizable version More...
 
template<typename T >
static ErrorStack get_element (tinyxml2::XMLElement *parent, const std::string &tag, T *out, bool optional=false, T value=0)
 Only declaration in header. More...
 
static ErrorStack get_element (tinyxml2::XMLElement *parent, const std::string &tag, std::string *out, bool optional=false, const char *value="")
 string type is bit special. More...
 
template<uint MAXLEN, typename CHAR >
static ErrorStack get_element (tinyxml2::XMLElement *parent, const std::string &tag, assorted::FixedString< MAXLEN, CHAR > *out, bool optional=false, const assorted::FixedString< MAXLEN, CHAR > &value=assorted::FixedString< MAXLEN, CHAR >())
 
template<typename ENUM >
static ErrorStack get_enum_element (tinyxml2::XMLElement *parent, const std::string &tag, ENUM *out, bool optional=false, ENUM default_value=static_cast< ENUM >(0))
 enum version More...
 
template<typename T >
static ErrorStack get_element (tinyxml2::XMLElement *parent, const std::string &tag, std::vector< T > *out, bool optional=false)
 vector version. More...
 
static ErrorStack get_child_element (tinyxml2::XMLElement *parent, const std::string &tag, Externalizable *child, bool optional=false)
 child Externalizable version More...
 

Member Function Documentation

void foedus::snapshot::SnapshotMetadata::assign ( const foedus::externalize::Externalizable other)
overridevirtual

Polymorphic assign operator.

This should invoke operator= of the derived class.

Parameters
[in]otherassigned value. It must be dynamic-castable to the assignee class.

Implements foedus::externalize::Externalizable.

Definition at line 100 of file snapshot_metadata.cpp.

References ASSERT_ND.

100  {
101  ASSERT_ND(false); // should not be called
102 }
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72
void foedus::snapshot::SnapshotMetadata::clear ( )

Definition at line 33 of file snapshot_metadata.cpp.

References base_epoch_, id_, foedus::Epoch::kEpochInvalid, foedus::snapshot::kNullSnapshotId, largest_storage_id_, foedus::memory::AlignedMemory::release_block(), storage_control_blocks_, storage_control_blocks_memory_, and valid_until_epoch_.

Referenced by load().

33  {
38  storage_control_blocks_ = nullptr;
40 }
storage::StorageControlBlock * storage_control_blocks_
control block of all storages.
Epoch::EpochInteger valid_until_epoch_
Equivalent to Snapshot::valid_until_epoch_.
void release_block()
Releases the memory block.
Zero is always reserved for invalid epoch.
Definition: epoch.hpp:68
memory::AlignedMemory storage_control_blocks_memory_
Memory backing storage_control_blocks_.
SnapshotId id_
Equivalent to Snapshot::id_.
const SnapshotId kNullSnapshotId
Definition: snapshot_id.hpp:45
Epoch::EpochInteger base_epoch_
Equivalent to Snapshot::base_epoch_.
storage::StorageId largest_storage_id_
The largest StorageId we so far observed.

Here is the call graph for this function:

Here is the caller graph for this function:

storage::Metadata* foedus::snapshot::SnapshotMetadata::get_metadata ( storage::StorageId  id)
inline

Definition at line 46 of file snapshot_metadata.hpp.

References foedus::storage::StorageControlBlock::meta_, and storage_control_blocks_.

Referenced by foedus::snapshot::SnapshotManagerPimpl::snapshot_metadata().

46  {
47  return &storage_control_blocks_[id].meta_;
48  }
storage::StorageControlBlock * storage_control_blocks_
control block of all storages.
Metadata meta_
common part of the metadata.
Definition: storage.hpp:84

Here is the caller graph for this function:

const char* foedus::snapshot::SnapshotMetadata::get_tag_name ( ) const
inlineoverridevirtual

Returns an XML tag name for this object as a root element.

We might want to give a different name for same externalizable objects, so this is used only when it is the root element of xml.

Implements foedus::externalize::Externalizable.

Definition at line 52 of file snapshot_metadata.hpp.

52 { return "SnapshotMetadata"; }
ErrorStack foedus::snapshot::SnapshotMetadata::load ( tinyxml2::XMLElement *  element)
overridevirtual

Reads the content of this object from the given XML element.

Parameters
[in]elementthe XML element that represents this object

Expect errors due to missing-elements, out-of-range values, etc.

Implements foedus::externalize::Externalizable.

Definition at line 42 of file snapshot_metadata.cpp.

References foedus::memory::AlignedMemory::alloc(), base_epoch_, CHECK_ERROR, clear(), EXTERNALIZE_LOAD_ELEMENT, foedus::memory::AlignedMemory::get_block(), foedus::memory::AlignedMemory::get_size(), id_, foedus::memory::AlignedMemory::kNumaAllocOnnode, foedus::kRetOk, foedus::soc::GlobalMemoryAnchors::kStorageMemorySize, largest_storage_id_, foedus::storage::MetadataSerializer::load_all_storages_from_xml(), storage_control_blocks_, storage_control_blocks_memory_, and valid_until_epoch_.

42  {
43  clear();
44  EXTERNALIZE_LOAD_ELEMENT(element, id_);
48 
49  uint64_t memory_size
52  memory_size,
53  1 << 12,
55  0);
56  storage_control_blocks_ = reinterpret_cast<storage::StorageControlBlock*>(
59 
60  // <storages>
61  tinyxml2::XMLElement* storages = element->FirstChildElement(kStoragesTagName);
62  if (!storages) {
63  // <storages> tag is missing. treat it as no storages. but weird!
64  LOG(ERROR) << "WAIT, the snapshot metadata file doesn't have " << kStoragesTagName
65  << " element? that's weird. It'll be treated as empty, but this shouldn't happen!";
66  } else {
69  storages,
71  }
72  // </storages>
73  return kRetOk;
74 }
#define EXTERNALIZE_LOAD_ELEMENT(element, attribute)
Reads a child xml element to load a member variable of this object.
storage::StorageControlBlock * storage_control_blocks_
control block of all storages.
numa_alloc_onnode() and numa_free().
Epoch::EpochInteger valid_until_epoch_
Equivalent to Snapshot::valid_until_epoch_.
void alloc(uint64_t size, uint64_t alignment, AllocType alloc_type, int numa_node) noexcept
Allocate a memory, releasing the current memory if exists.
const char * kStoragesTagName
memory::AlignedMemory storage_control_blocks_memory_
Memory backing storage_control_blocks_.
SnapshotId id_
Equivalent to Snapshot::id_.
void * get_block() const
Returns the memory block.
uint64_t get_size() const
Returns the byte size of the memory block.
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
const ErrorStack kRetOk
Normal return value for no-error case.
Epoch::EpochInteger base_epoch_
Equivalent to Snapshot::base_epoch_.
storage::StorageId largest_storage_id_
The largest StorageId we so far observed.
static ErrorStack load_all_storages_from_xml(storage::StorageId largest_storage_id, tinyxml2::XMLElement *element, StorageControlBlock *blocks)
Definition: metadata.cpp:125

Here is the call graph for this function:

ErrorStack foedus::snapshot::SnapshotMetadata::save ( tinyxml2::XMLElement *  element) const
overridevirtual

Writes the content of this object to the given XML element.

Parameters
[in]elementthe XML element that represents this object

Expect only out-of-memory error. We receive the XML element this object will represent, so this method does not determine the XML element name of itself. The parent object determines children's tag names because one parent object might have multiple child objects of the same type with different XML element name.

Implements foedus::externalize::Externalizable.

Definition at line 76 of file snapshot_metadata.cpp.

References base_epoch_, CHECK_ERROR, CHECK_OUTOFMEMORY, EXTERNALIZE_SAVE_ELEMENT, id_, foedus::externalize::Externalizable::insert_comment(), foedus::kRetOk, largest_storage_id_, foedus::storage::MetadataSerializer::save_all_storages_to_xml(), storage_control_blocks_, and valid_until_epoch_.

76  {
77  CHECK_ERROR(insert_comment(element, "Metadata of a snapshot"));
78 
79  EXTERNALIZE_SAVE_ELEMENT(element, id_, "Unique ID of this snapshot");
81  "This snapshot was taken based on another snapshot that is valid_until this epoch."
82  " If this is the first snapshot, this value is 0.");
84  "This snapshot contains all the logs until this epoch.");
86  "The largest StorageId we so far observed.");
87 
88  // <storages>
89  tinyxml2::XMLElement* storages = element->GetDocument()->NewElement(kStoragesTagName);
90  CHECK_OUTOFMEMORY(storages);
91  element->InsertEndChild(storages);
92  CHECK_ERROR(insert_comment(storages, "Metadata of all storages"));
95  storages,
97  // </storages>
98  return kRetOk;
99 }
storage::StorageControlBlock * storage_control_blocks_
control block of all storages.
Epoch::EpochInteger valid_until_epoch_
Equivalent to Snapshot::valid_until_epoch_.
static ErrorStack insert_comment(tinyxml2::XMLElement *element, const std::string &comment)
#define CHECK_OUTOFMEMORY(ptr)
This macro checks if ptr is nullptr, and if so exists with kErrorCodeOutofmemory error stack...
const char * kStoragesTagName
SnapshotId id_
Equivalent to Snapshot::id_.
static ErrorStack save_all_storages_to_xml(storage::StorageId largest_storage_id, tinyxml2::XMLElement *element, StorageControlBlock *blocks)
Definition: metadata.cpp:166
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
const ErrorStack kRetOk
Normal return value for no-error case.
Epoch::EpochInteger base_epoch_
Equivalent to Snapshot::base_epoch_.
#define EXTERNALIZE_SAVE_ELEMENT(element, attribute, comment)
Adds an xml element to represent a member variable of this object.
storage::StorageId largest_storage_id_
The largest StorageId we so far observed.

Here is the call graph for this function:

Member Data Documentation

Epoch::EpochInteger foedus::snapshot::SnapshotMetadata::base_epoch_
storage::StorageControlBlock* foedus::snapshot::SnapshotMetadata::storage_control_blocks_
memory::AlignedMemory foedus::snapshot::SnapshotMetadata::storage_control_blocks_memory_

Memory backing storage_control_blocks_.

Definition at line 75 of file snapshot_metadata.hpp.

Referenced by clear(), foedus::storage::StorageManagerPimpl::clone_all_storage_metadata(), and load().

Epoch::EpochInteger foedus::snapshot::SnapshotMetadata::valid_until_epoch_

The documentation for this struct was generated from the following files: