libfoedus-core
FOEDUS Core Library
array_composer_impl.hpp
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  */
18 #ifndef FOEDUS_STORAGE_ARRAY_ARRAY_COMPOSER_IMPL_HPP_
19 #define FOEDUS_STORAGE_ARRAY_ARRAY_COMPOSER_IMPL_HPP_
20 
21 #include <stdint.h>
22 
23 #include <iosfwd>
24 #include <string>
25 
26 #include "foedus/compiler.hpp"
27 #include "foedus/fwd.hpp"
28 #include "foedus/memory/fwd.hpp"
29 #include "foedus/snapshot/fwd.hpp"
31 #include "foedus/storage/page.hpp"
36 #include "foedus/xct/xct_id.hpp"
37 
38 namespace foedus {
39 namespace storage {
40 namespace array {
51 class ArrayComposer final {
52  public:
53  explicit ArrayComposer(Composer *parent);
54 
55  std::string to_string() const;
56 
61 
62  private:
63  Engine* const engine_;
64  const StorageId storage_id_;
65  const ArrayStorage storage_;
66 
67  ArrayPage* resolve_volatile(VolatilePagePointer pointer);
68  Composer::DropResult drop_volatiles_recurse(
70  DualPagePointer* pointer);
72  Composer::DropResult drop_volatiles_intermediate(
74  DualPagePointer* pointer,
75  ArrayPage* volatile_page);
76  Composer::DropResult drop_volatiles_leaf(
78  DualPagePointer* pointer,
79  ArrayPage* volatile_page);
80  bool is_to_keep_volatile(uint16_t level);
82  void drop_all_recurse(
84  DualPagePointer* pointer);
85 };
86 
92 struct ArrayRootInfoPage final {
94 
97 
98  char filler_[
99  kPageSize
100  - sizeof(PageHeader)
102 };
103 
110  public:
112  Engine* engine,
113  snapshot::MergeSort* merge_sort,
114  snapshot::SnapshotWriter* snapshot_writer,
115  cache::SnapshotFileSet* previous_snapshot_files,
116  Page* root_info_page);
117 
119 
120  private:
121  ErrorStack initialize(ArrayOffset initial_offset);
122  ErrorStack init_root_page();
123 
129  void apply_batch(uint64_t cur, uint64_t next);
130 
135  ErrorStack execute_single_level_array();
136  ErrorStack finalize();
137 
138  ErrorCode update_cur_path(ArrayOffset next_offset);
139 
140  ErrorCode read_or_init_page(
141  SnapshotPagePointer old_page_id,
142  SnapshotPagePointer new_page_id,
143  uint8_t level,
144  ArrayRange range,
145  ArrayPage* page) ALWAYS_INLINE;
146 
151  ErrorCode create_empty_pages(ArrayOffset from, ArrayOffset to);
152  ErrorCode create_empty_pages_recurse(ArrayOffset from, ArrayOffset to, ArrayPage* page);
153  ErrorCode create_empty_intermediate_page(ArrayPage* parent, uint16_t index, ArrayRange range);
154  ErrorCode create_empty_leaf_page(ArrayPage* parent, uint16_t index, ArrayRange range);
155 
157  ErrorCode expand_intermediate_pool_if_needed() ALWAYS_INLINE;
158 
165  ErrorStack install_snapshot_pointers(
166  SnapshotPagePointer snapshot_base,
167  uint64_t* installed_count) const;
168  ErrorCode install_snapshot_pointers_recurse(
169  SnapshotPagePointer snapshot_base,
170  const memory::GlobalVolatilePageResolver& resolver,
171  const ArrayPage* snapshot_page,
172  ArrayPage* volatile_page,
173  uint64_t* installed_count) const;
174 
176  ErrorCode dump_leaf_pages();
178  bool verify_cur_path() const;
179  bool verify_snapshot_pointer(storage::SnapshotPagePointer pointer);
180 
182  ArrayRange to_leaf_range(ArrayOffset offset) const {
183  ArrayOffset begin = offset / offset_intervals_[0] * offset_intervals_[0];
184  return ArrayRange(begin, begin + offset_intervals_[0], storage_.get_array_size());
185  }
186  bool is_initial_snapshot() const { return previous_root_page_pointer_ == 0; }
187 
188  uint16_t get_root_children() const;
189 
190  // these properties are initialized in constructor and never changed afterwards
191  Engine* const engine_;
192  snapshot::MergeSort* const merge_sort_;
193  const Epoch system_initial_epoch_;
194  const StorageId storage_id_;
195  const snapshot::SnapshotId snapshot_id_;
196  const ArrayStorage storage_;
197  snapshot::SnapshotWriter* const snapshot_writer_;
198  cache::SnapshotFileSet* const previous_snapshot_files_;
200  ArrayRootInfoPage* const root_info_page_;
201 
202  const uint16_t payload_size_;
203  const uint8_t levels_;
204  const SnapshotPagePointer previous_root_page_pointer_;
205 
210  uint64_t offset_intervals_[kMaxLevels];
211 
217  ArrayPage* cur_path_[kMaxLevels];
218 
223  uint32_t allocated_pages_;
230  uint32_t allocated_intermediates_;
231  uint32_t max_pages_;
232  uint32_t max_intermediates_;
234  ArrayPage* page_base_;
236  ArrayPage* intermediate_base_;
237 
243  const ArrayPartitionerData* partitioning_data_;
244 };
245 
246 static_assert(sizeof(ArrayRootInfoPage) == kPageSize, "incorrect sizeof(RootInfoPage)");
247 } // namespace array
248 } // namespace storage
249 } // namespace foedus
250 #endif // FOEDUS_STORAGE_ARRAY_ARRAY_COMPOSER_IMPL_HPP_
char filler_[ kPageSize -sizeof(PageHeader) -kInteriorFanout *sizeof(SnapshotPagePointer)]
ArrayComposeContext(Engine *engine, snapshot::MergeSort *merge_sort, snapshot::SnapshotWriter *snapshot_writer, cache::SnapshotFileSet *previous_snapshot_files, Page *root_info_page)
ArrayComposeContext methods.
void drop_root_volatile(const Composer::DropVolatilesArguments &args)
Represents a pointer to another page (usually a child page).
Definition: storage_id.hpp:271
Represents a logic to compose a new version of data pages for one storage.
Definition: composer.hpp:86
ArrayComposer's compose() implementation separated from the class itself.
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
Represents a key-value store based on a dense and regular array.
uint64_t ArrayOffset
The only key type in array storage.
Definition: array_id.hpp:48
const uint8_t kMaxLevels
Code in array storage assumes this number as the maximum number of levels.
Definition: array_id.hpp:118
Represents a pointer to a volatile page with modification count for preventing ABA.
Definition: storage_id.hpp:194
ErrorStack compose(const Composer::ComposeArguments &args)
Forward declarations of classes in root package.
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
Represents one data page in Array Storage.
Forward declarations of classes in snapshot manager package.
Represents a time epoch.
Definition: epoch.hpp:61
Holds a set of read-only file objects for snapshot files.
Forward declarations of classes in array storage package.
Output of one compose() call, which are then combined in construct_root().
ArrayComposer(Composer *parent)
ArrayComposer methods.
ArrayOffset get_array_size() const
Returns the size of this array.
SnapshotPagePointer pointers_[kInteriorFanout]
Pointers to direct children of root.
ErrorStack construct_root(const Composer::ConstructRootArguments &args)
Definitions of IDs in this package and a few related constant values.
Composer for an array storage.
Receives an arbitrary number of sorted buffers and emits one fully sorted stream of logs...
Definition: merge_sort.hpp:77
Composer::DropResult drop_volatiles(const Composer::DropVolatilesArguments &args)
drop_volatiles and related methods
uint64_t SnapshotPagePointer
Page ID of a snapshot page.
Definition: storage_id.hpp:79
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
Just a marker to denote that a memory region represents a data page.
Definition: page.hpp:184
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
uint16_t SnapshotId
Unique ID of Snapshot.
Definition: snapshot_id.hpp:43
Forward declarations of classes in memory package.
Represents an offset range in an array storage.
Definition: array_id.hpp:62
Resolves an offset in a volatile page pool to an actual pointer and vice versa.
Definitions of IDs in this package and a few related constant values.
const uint16_t kInteriorFanout
Max number of entries in an interior page of array storage.
Definition: array_id.hpp:110
#define ALWAYS_INLINE
A function suffix to hint that the function should always be inlined.
Definition: compiler.hpp:106
const uint16_t kPageSize
A constant defining the page size (in bytes) of both snapshot pages and volatile pages.
Definition: storage_id.hpp:45
ErrorCode
Enum of error codes defined in error_code.xmacro.
Definition: error_code.hpp:85
Writes out one snapshot file for all data pages in one reducer.