libfoedus-core
FOEDUS Core Library
snapshot_metadata.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
19 
20 #include <tinyxml2.h>
21 #include <glog/logging.h>
22 
23 #include <memory>
24 
28 
29 namespace foedus {
30 namespace snapshot {
31 
32 const char* kStoragesTagName = "storages";
38  storage_control_blocks_ = nullptr;
40 }
41 
42 ErrorStack SnapshotMetadata::load(tinyxml2::XMLElement* element) {
43  clear();
44  EXTERNALIZE_LOAD_ELEMENT(element, id_);
48 
49  uint64_t memory_size
52  memory_size,
53  1 << 12,
55  0);
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 }
75 
76 ErrorStack SnapshotMetadata::save(tinyxml2::XMLElement* element) const {
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 }
101  ASSERT_ND(false); // should not be called
102 }
103 
104 } // namespace snapshot
105 } // namespace foedus
#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.
ErrorStack save(tinyxml2::XMLElement *element) const override
Writes the content of this object to the given XML element.
numa_alloc_onnode() and numa_free().
Represents an object that can be written to and read from files/bytes in XML format.
Epoch::EpochInteger valid_until_epoch_
Equivalent to Snapshot::valid_until_epoch_.
void release_block()
Releases the memory block.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
void alloc(uint64_t size, uint64_t alignment, AllocType alloc_type, int numa_node) noexcept
Allocate a memory, releasing the current memory if exists.
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...
ErrorStack load(tinyxml2::XMLElement *element) override
Reads the content of this object from the given XML element.
const char * kStoragesTagName
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_.
void * get_block() const
Returns the memory block.
const SnapshotId kNullSnapshotId
Definition: snapshot_id.hpp:45
uint64_t get_size() const
Returns the byte size of the memory block.
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_.
void assign(const foedus::externalize::Externalizable *other) override
Polymorphic assign operator.
#define EXTERNALIZE_SAVE_ELEMENT(element, attribute, comment)
Adds an xml element to represent a member variable of this object.
#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
A base layout of shared data for all storage types.
Definition: storage.hpp:53
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