libfoedus-core
FOEDUS Core Library
foedus::storage::MetadataSerializer Struct Reference

Detailed Description

Definition at line 117 of file metadata.hpp.

#include <metadata.hpp>

Inheritance diagram for foedus::storage::MetadataSerializer:
Collaboration diagram for foedus::storage::MetadataSerializer:

Public Member Functions

 MetadataSerializer ()
 
 MetadataSerializer (Metadata *data)
 
virtual ~MetadataSerializer ()
 
ErrorStack load_base (tinyxml2::XMLElement *element)
 common routine for the implementation of load() More...
 
ErrorStack save_base (tinyxml2::XMLElement *element) const
 common routine for the implementation of save() More...
 
- Public Member Functions inherited from foedus::externalize::Externalizable
virtual ErrorStack load (tinyxml2::XMLElement *element)=0
 Reads the content of this object from the given XML element. More...
 
virtual ErrorStack save (tinyxml2::XMLElement *element) const =0
 Writes the content of this object to the given XML element. More...
 
virtual const char * get_tag_name () const =0
 Returns an XML tag name for this object as a root element. More...
 
virtual void assign (const foedus::externalize::Externalizable *other)=0
 Polymorphic assign operator. More...
 
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...
 

Static Public Member Functions

static ErrorStack load_all_storages_from_xml (storage::StorageId largest_storage_id, tinyxml2::XMLElement *element, StorageControlBlock *blocks)
 
static ErrorStack save_all_storages_to_xml (storage::StorageId largest_storage_id, tinyxml2::XMLElement *element, StorageControlBlock *blocks)
 
- 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...
 

Public Attributes

Metadatadata_
 

Constructor & Destructor Documentation

foedus::storage::MetadataSerializer::MetadataSerializer ( )
inline

Definition at line 118 of file metadata.hpp.

118 : data_(CXX11_NULLPTR) {}
#define CXX11_NULLPTR
Used in public headers in place of "nullptr" of C++11.
Definition: cxx11.hpp:132
foedus::storage::MetadataSerializer::MetadataSerializer ( Metadata data)
inlineexplicit

Definition at line 119 of file metadata.hpp.

119 : data_(data) {}
virtual foedus::storage::MetadataSerializer::~MetadataSerializer ( )
inlinevirtual

Definition at line 120 of file metadata.hpp.

120 {}

Member Function Documentation

ErrorStack foedus::storage::MetadataSerializer::load_all_storages_from_xml ( storage::StorageId  largest_storage_id,
tinyxml2::XMLElement *  element,
StorageControlBlock blocks 
)
static

Definition at line 125 of file metadata.cpp.

References ASSERT_ND, CHECK_ERROR, ERROR_STACK, foedus::externalize::Externalizable::get_element(), foedus::externalize::Externalizable::get_enum_element(), foedus::storage::kArrayStorage, foedus::kErrorCodeStrUnsupportedMetadata, foedus::storage::kExists, foedus::storage::kHashStorage, foedus::storage::kInvalidStorage, foedus::storage::kMasstreeStorage, foedus::storage::kNotExists, foedus::kRetOk, foedus::storage::kSequentialStorage, foedus::storage::load_from_xml_array(), foedus::storage::load_from_xml_hash(), foedus::storage::load_from_xml_masstree(), foedus::storage::load_from_xml_sequential(), foedus::storage::StorageControlBlock::meta_, and foedus::storage::StorageControlBlock::status_.

Referenced by foedus::snapshot::SnapshotMetadata::load().

128  {
129  uint32_t loaded_count = 0;
130  for (tinyxml2::XMLElement* element = parent->FirstChildElement(kChildTagName);
131  element;
132  element = element->NextSiblingElement(kChildTagName)) {
133  StorageId id;
134  CHECK_ERROR(get_element(element, "id_", &id))
135  ASSERT_ND(id > 0);
136  ASSERT_ND(id <= largest_storage_id);
138  CHECK_ERROR(get_enum_element(element, "type_", &type));
139 
140  VLOG(0) << "Loading metadata of storage-" << id << " from xml";
141  ASSERT_ND(blocks[id].status_ == kNotExists);
142  Metadata* data = &blocks[id].meta_;
143  blocks[id].status_ = kExists;
144  switch (type) {
145  case kArrayStorage:
146  CHECK_ERROR(load_from_xml_array(element, data));
147  break;
148  case kHashStorage:
149  CHECK_ERROR(load_from_xml_hash(element, data));
150  break;
151  case kMasstreeStorage:
152  CHECK_ERROR(load_from_xml_masstree(element, data));
153  break;
154  case kSequentialStorage:
155  CHECK_ERROR(load_from_xml_sequential(element, data));
156  break;
157  default:
159  }
160  ++loaded_count;
161  }
162  LOG(INFO) << "Loaded metadata of " << loaded_count << " storages";
163  return kRetOk;
164 }
#define ERROR_STACK(e)
Instantiates ErrorStack with the given foedus::error_code, creating an error stack with the current f...
uint32_t StorageId
Unique ID for storage.
Definition: storage_id.hpp:55
The storage has been created and ready for use.
Definition: storage_id.hpp:158
0 indicates invalid type.
Definition: storage_id.hpp:124
ErrorStack load_from_xml_sequential(tinyxml2::XMLElement *element, Metadata *data)
Definition: metadata.cpp:98
ErrorStack load_from_xml_hash(tinyxml2::XMLElement *element, Metadata *data)
Definition: metadata.cpp:89
StorageType
Type of the storage, such as hash.
Definition: storage_id.hpp:122
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
const char * kChildTagName
Definition: metadata.cpp:104
const ErrorStack kRetOk
Normal return value for no-error case.
static ErrorStack get_element(tinyxml2::XMLElement *parent, const std::string &tag, T *out, bool optional=false, T value=0)
Only declaration in header.
Initial state, which means the storage has not been created yet.
Definition: storage_id.hpp:156
0x0807 : "STORAGE: This metadata type is not yet supported" .
Definition: error_code.hpp:173
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
#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
ErrorStack load_from_xml_masstree(tinyxml2::XMLElement *element, Metadata *data)
Definition: metadata.cpp:93
ErrorStack load_from_xml_array(tinyxml2::XMLElement *element, Metadata *data)
Definition: metadata.cpp:85

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::storage::MetadataSerializer::load_base ( tinyxml2::XMLElement *  element)

common routine for the implementation of load()

Definition at line 50 of file metadata.cpp.

References CHECK_ERROR, data_, foedus::externalize::Externalizable::get_element(), foedus::externalize::Externalizable::get_enum_element(), foedus::storage::Metadata::id_, foedus::kRetOk, foedus::storage::Metadata::name_, foedus::storage::Metadata::root_snapshot_page_id_, foedus::storage::Metadata::SnapshotThresholds::snapshot_keep_threshold_, foedus::storage::Metadata::snapshot_thresholds_, foedus::storage::Metadata::SnapshotThresholds::snapshot_trigger_threshold_, and foedus::storage::Metadata::type_.

Referenced by foedus::storage::sequential::SequentialMetadataSerializer::load(), foedus::storage::hash::HashMetadataSerializer::load(), foedus::storage::array::ArrayMetadataSerializer::load(), and foedus::storage::masstree::MasstreeMetadataSerializer::load().

50  {
51  CHECK_ERROR(get_element(element, "id_", &data_->id_))
52  CHECK_ERROR(get_enum_element(element, "type_", &data_->type_))
53  CHECK_ERROR(get_element(element, "name_", &data_->name_))
54  CHECK_ERROR(get_element(element, "root_snapshot_page_id_", &data_->root_snapshot_page_id_))
56  element,
57  "snapshot_trigger_threshold_",
58  &data_->snapshot_thresholds_.snapshot_trigger_threshold_));
60  element,
61  "snapshot_keep_threshold_",
62  &data_->snapshot_thresholds_.snapshot_keep_threshold_));
63  return kRetOk;
64 }
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
const ErrorStack kRetOk
Normal return value for no-error case.
static ErrorStack get_element(tinyxml2::XMLElement *parent, const std::string &tag, T *out, bool optional=false, T value=0)
Only declaration in header.
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
StorageId id_
the unique ID of this storage.
Definition: metadata.hpp:103

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::storage::MetadataSerializer::save_all_storages_to_xml ( storage::StorageId  largest_storage_id,
tinyxml2::XMLElement *  element,
StorageControlBlock blocks 
)
static

Definition at line 166 of file metadata.cpp.

References ASSERT_ND, CHECK_ERROR, ERROR_STACK, foedus::fs::exists(), foedus::storage::kArrayStorage, foedus::kErrorCodeStrUnsupportedMetadata, foedus::storage::kHashStorage, foedus::storage::kMasstreeStorage, foedus::kRetOk, foedus::storage::kSequentialStorage, foedus::storage::StorageControlBlock::meta_, foedus::storage::save_to_xml_array(), foedus::storage::save_to_xml_hash(), foedus::storage::save_to_xml_masstree(), foedus::storage::save_to_xml_sequential(), and foedus::storage::Metadata::type_.

Referenced by foedus::snapshot::SnapshotMetadata::save().

169  {
170  uint32_t saved_count = 0;
171  for (storage::StorageId id = 1; id <= largest_storage_id; ++id) {
172  ASSERT_ND(blocks[id].is_valid_status());
173  if (!blocks[id].exists()) {
174  continue;
175  }
176  StorageType type = blocks[id].meta_.type_;
177  Metadata* data = &blocks[id].meta_;
178  switch (type) {
179  case kArrayStorage:
180  CHECK_ERROR(save_to_xml_array(parent, data));
181  break;
182  case kHashStorage:
183  CHECK_ERROR(save_to_xml_hash(parent, data));
184  break;
185  case kMasstreeStorage:
186  CHECK_ERROR(save_to_xml_masstree(parent, data));
187  break;
188  case kSequentialStorage:
189  CHECK_ERROR(save_to_xml_sequential(parent, data));
190  break;
191  default:
193  }
194  ++saved_count;
195  }
196  LOG(INFO) << "Written metadata of " << saved_count << " storages";
197  return kRetOk;
198 }
ErrorStack save_to_xml_hash(tinyxml2::XMLElement *parent, Metadata *data)
Definition: metadata.cpp:110
#define ERROR_STACK(e)
Instantiates ErrorStack with the given foedus::error_code, creating an error stack with the current f...
uint32_t StorageId
Unique ID for storage.
Definition: storage_id.hpp:55
ErrorStack save_to_xml_masstree(tinyxml2::XMLElement *parent, Metadata *data)
Definition: metadata.cpp:114
ErrorStack save_to_xml_sequential(tinyxml2::XMLElement *parent, Metadata *data)
Definition: metadata.cpp:119
bool exists(const Path &p)
Returns if the file exists.
Definition: filesystem.hpp:128
ErrorStack save_to_xml_array(tinyxml2::XMLElement *parent, Metadata *data)
Definition: metadata.cpp:106
StorageType
Type of the storage, such as hash.
Definition: storage_id.hpp:122
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
const ErrorStack kRetOk
Normal return value for no-error case.
0x0807 : "STORAGE: This metadata type is not yet supported" .
Definition: error_code.hpp:173
#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

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::storage::MetadataSerializer::save_base ( tinyxml2::XMLElement *  element) const

common routine for the implementation of save()

Definition at line 66 of file metadata.cpp.

References foedus::externalize::Externalizable::add_element(), foedus::externalize::Externalizable::add_enum_element(), CHECK_ERROR, data_, foedus::storage::Metadata::id_, foedus::kRetOk, foedus::storage::Metadata::name_, foedus::storage::Metadata::root_snapshot_page_id_, foedus::storage::Metadata::SnapshotThresholds::snapshot_keep_threshold_, foedus::storage::Metadata::snapshot_thresholds_, foedus::storage::Metadata::SnapshotThresholds::snapshot_trigger_threshold_, and foedus::storage::Metadata::type_.

Referenced by foedus::storage::sequential::SequentialMetadataSerializer::save(), foedus::storage::hash::HashMetadataSerializer::save(), foedus::storage::array::ArrayMetadataSerializer::save(), and foedus::storage::masstree::MasstreeMetadataSerializer::save().

66  {
67  CHECK_ERROR(add_element(element, "id_", "", data_->id_));
68  CHECK_ERROR(add_enum_element(element, "type_", "", data_->type_));
69  CHECK_ERROR(add_element(element, "name_", "", data_->name_));
70  CHECK_ERROR(add_element(element, "root_snapshot_page_id_", "", data_->root_snapshot_page_id_));
72  element,
73  "snapshot_trigger_threshold_",
74  "",
77  element,
78  "snapshot_keep_threshold_",
79  "",
81  return kRetOk;
82 }
static ErrorStack add_enum_element(tinyxml2::XMLElement *parent, const std::string &tag, const std::string &comment, ENUM value)
enum version
uint32_t snapshot_keep_threshold_
[Only partially implemented] When a log gleaner created new snapshot pages for this storage...
Definition: metadata.hpp:76
StorageName name_
the unique name of this storage.
Definition: metadata.hpp:107
SnapshotThresholds snapshot_thresholds_
Definition: metadata.hpp:114
StorageType type_
type of the storage.
Definition: metadata.hpp:105
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
const ErrorStack kRetOk
Normal return value for no-error case.
uint32_t snapshot_trigger_threshold_
[Not implemented yet] If this storage has more than this number of volatile pages, log gleaner will soon start to drop some of the volatile pages.
Definition: metadata.hpp:67
StorageId id_
the unique ID of this storage.
Definition: metadata.hpp:103
static ErrorStack add_element(tinyxml2::XMLElement *parent, const std::string &tag, const std::string &comment, T value)
Only declaration in header.
SnapshotPagePointer root_snapshot_page_id_
Pointer to a snapshotted page this storage is rooted at.
Definition: metadata.hpp:112

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

Metadata* foedus::storage::MetadataSerializer::data_

Definition at line 136 of file metadata.hpp.

Referenced by load_base(), and save_base().


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