libfoedus-core
FOEDUS Core Library
composer.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 <ostream>
21 
22 #include "foedus/assert_nd.hpp"
23 #include "foedus/engine.hpp"
36 
37 namespace foedus {
38 namespace storage {
39 std::ostream& operator<<(std::ostream& o, const Composer& v) {
40  o << "<Composer>"
41  << "<storage_id_>" << v.get_storage_id() << "</storage_id_>"
42  << "<storage_type>" << to_storage_type_name(v.get_storage_type()) << "</storage_type>"
43  << "</Composer>";
44  return o;
45 }
46 std::ostream& operator<<(std::ostream& o, const Composer::DropResult& v) {
47  o << "<DropResult>"
48  << "<max_observed_>" << v.max_observed_ << "</max_observed_>"
49  << "<dropped_all_>" << v.dropped_all_ << "</dropped_all_>"
50  << "</DropResult>";
51  return o;
52 }
53 
54 
55 Composer::Composer(Engine *engine, StorageId storage_id)
56  : engine_(engine),
57  storage_id_(storage_id),
58  storage_type_(engine_->get_storage_manager()->get_storage(storage_id_)->meta_.type_) {}
59 
60 
62  switch (storage_type_) {
63  case kArrayStorage: return array::ArrayComposer(this).compose(args);
64  case kHashStorage: return hash::HashComposer(this).compose(args);
66  case kMasstreeStorage: return masstree::MasstreeComposer(this).compose(args);
67  default:
68  return kRetOk;
69  }
70 }
71 
73  switch (storage_type_) {
74  case kArrayStorage: return array::ArrayComposer(this).construct_root(args);
75  case kHashStorage: return hash::HashComposer(this).construct_root(args);
78  default:
79  return kRetOk;
80  }
81 }
82 
84  switch (storage_type_) {
85  case kArrayStorage: return array::ArrayComposer(this).drop_volatiles(args);
86  case kHashStorage: return hash::HashComposer(this).drop_volatiles(args);
89  default:
90  return DropResult(args);
91  }
92 }
93 
95  switch (storage_type_) {
96  case kArrayStorage:
98  return;
99  case kHashStorage:
101  return;
102  case kSequentialStorage:
103  // Sequential storage already dropped it. Nothing to do.
104  return;
105  case kMasstreeStorage:
107  return;
108  default:
109  return;
110  }
111 }
112 
113 
115  Engine* engine,
116  VolatilePagePointer pointer) const {
117  uint16_t node = pointer.get_numa_node();
118  ASSERT_ND(node < engine->get_soc_count());
119  ASSERT_ND(!pointer.is_null());
120 #ifndef NDEBUG
121  // let's fill the page with garbage to help debugging
122  std::memset(
124  0xDA,
125  sizeof(Page));
126 #endif // NDEBUG
127 
129  if (chunk->full()) {
130  memory::PagePool* pool
132  pool->release(chunk->size(), chunk);
133  ASSERT_ND(chunk->empty());
134  }
135  ASSERT_ND(!chunk->full());
136  chunk->push_back(pointer.get_offset());
137  ++(*dropped_count_);
138 }
139 
140 } // namespace storage
141 } // namespace foedus
void drop_root_volatile(const Composer::DropVolatilesArguments &args)
ErrorStack construct_root(const Composer::ConstructRootArguments &args)
storage::Page * resolve_offset(uint8_t numa_node, PagePoolOffset offset) const __attribute__((always_inline))
Resolves offset plus NUMA node ID to storage::Page*.
void drop_root_volatile(const Composer::DropVolatilesArguments &args)
memory::PagePoolOffsetChunk * dropped_chunks_
Caches dropped pages to avoid returning every single page.
Definition: composer.hpp:161
Epoch max_observed_
the largest Epoch it observed recursively.
Definition: composer.hpp:200
ErrorStack construct_root(const ConstructRootArguments &args)
Construct root page(s) for one storage based on the ouputs of compose().
Definition: composer.cpp:72
Page pool for volatile read/write store (VolatilePage) and the read-only bufferpool (SnapshotPage)...
Definition: page_pool.hpp:173
DropResult drop_volatiles(const DropVolatilesArguments &args)
Drops volatile pages that have not been modified since the snapshotted epoch.
Definition: composer.cpp:83
Represents a logic to compose a new version of data pages for one storage.
Definition: composer.hpp:86
uint32_t StorageId
Unique ID for storage.
Definition: storage_id.hpp:55
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
const GlobalVolatilePageResolver & get_global_volatile_page_resolver() const
Returns the page resolver to convert volatile page ID to page pointer.
void drop_root_volatile(const Composer::DropVolatilesArguments &args)
Composer::DropResult drop_volatiles(const Composer::DropVolatilesArguments &args)
Represents a pointer to a volatile page with modification count for preventing ABA.
Definition: storage_id.hpp:194
ErrorStack compose(const Composer::ComposeArguments &args)
Composer::DropResult drop_volatiles(const Composer::DropVolatilesArguments &args)
drop_volatiles and related methods
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
StorageId get_storage_id() const
Definition: composer.hpp:91
Composer(Engine *engine, StorageId storage_id)
Definition: composer.cpp:55
ErrorStack construct_root(const Composer::ConstructRootArguments &args)
Composer::DropResult drop_volatiles(const Composer::DropVolatilesArguments &args)
drop_volatiles and related methods
ErrorStack construct_root(const Composer::ConstructRootArguments &args)
memory::PagePoolOffset get_offset() const
Definition: storage_id.hpp:202
Composer for an array storage.
Composer::DropResult drop_volatiles(const Composer::DropVolatilesArguments &args)
drop_volatiles and related methods
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
NumaNodeMemoryRef * get_node_memory(foedus::thread::ThreadGroupId group) const
ErrorStack compose(const Composer::ComposeArguments &args)
ErrorStack compose(const ComposeArguments &args)
Construct snapshot pages from sorted run files of one storage.
Definition: composer.cpp:61
Just a marker to denote that the memory region represents a data page.
Definition: page.hpp:334
Retrun value of drop_volatiles()
Definition: composer.hpp:171
const char * to_storage_type_name(StorageType type)
Gives a string representation of StorageType.
Definition: storage_id.hpp:139
bool dropped_all_
Whether all volatile pages under the page was dropped.
Definition: composer.hpp:202
void release(uint32_t desired_release_count, PagePoolOffsetChunk *chunk)
Returns the specified number of free pages from the chunk.
Definition: page_pool.cpp:134
ErrorStack compose(const Composer::ComposeArguments &args)
ErrorStack construct_root(const Composer::ConstructRootArguments &args)
void push_back(PagePoolOffset pointer)
Definition: page_pool.hpp:68
ErrorStack compose(const Composer::ComposeArguments &args)
To reduce the overhead of grabbing/releasing pages from pool, we pack this many pointers for each gra...
Definition: page_pool.hpp:47
const ErrorStack kRetOk
Normal return value for no-error case.
Composer for a hash storage.
std::ostream & operator<<(std::ostream &o, const Composer &v)
Definition: composer.cpp:39
void drop_root_volatile(const DropVolatilesArguments &args)
This is additionally called when no partitions observed any new modifications.
Definition: composer.cpp:94
StorageType get_storage_type() const
Definition: composer.hpp:92
#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 drop(Engine *engine, VolatilePagePointer pointer) const
Returns (might cache) the given pointer to volatile pool.
Definition: composer.cpp:114
memory::EngineMemory * get_memory_manager() const
See Memory Manager.
Definition: engine.cpp:50