libfoedus-core
FOEDUS Core Library
hash_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_HASH_HASH_COMPOSER_IMPL_HPP_
19 #define FOEDUS_STORAGE_HASH_HASH_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/cache/fwd.hpp"
29 #include "foedus/memory/fwd.hpp"
30 #include "foedus/snapshot/fwd.hpp"
32 #include "foedus/storage/page.hpp"
39 #include "foedus/xct/xct_id.hpp"
40 
41 namespace foedus {
42 namespace storage {
43 namespace hash {
62 class HashComposer final {
63  public:
64  explicit HashComposer(Composer *parent);
65 
66  std::string to_string() const;
67 
70 
71 
74 
77  HashComposer* pointer,
79  uint16_t numa_node,
80  HashIntermediatePage* root_page,
81  ErrorStack* out_error) {
82  *out_error = pointer->construct_root_multi_level(*args, numa_node, root_page);
83  }
84 
85  private:
86  Engine* const engine_;
87  const StorageId storage_id_;
88  const HashStorage storage_;
89 
91  const memory::GlobalVolatilePageResolver& volatile_resolver_;
92 
93  HashDataPage* resolve_data(VolatilePagePointer pointer) const ALWAYS_INLINE;
94  HashIntermediatePage* resolve_intermediate(VolatilePagePointer pointer) const ALWAYS_INLINE;
95 
97  ErrorStack construct_root_single_level(
99  HashIntermediatePage* root_page);
105  ErrorStack construct_root_multi_level(
107  uint16_t numa_node,
108  HashIntermediatePage* root_page);
109 
110  void drop_volatiles_child(
112  DualPagePointer* child_pointer,
113  uint8_t parent_level,
114  Composer::DropResult *result);
115  Composer::DropResult drop_volatiles_recurse(
117  DualPagePointer* pointer);
118 
123  bool can_drop_volatile_bin(VolatilePagePointer head, Epoch valid_until) const;
124 
126  void drop_volatile_entire_bin(
128  DualPagePointer* pointer_to_head) const;
129 
130  bool is_to_keep_volatile(uint16_t level);
132  void drop_all_recurse(
134  DualPagePointer* pointer);
135 };
136 
143  public:
145  Engine* engine,
146  snapshot::MergeSort* merge_sort,
147  snapshot::SnapshotWriter* snapshot_writer,
148  cache::SnapshotFileSet* previous_snapshot_files,
149  Page* root_info_page);
150 
152 
153  private:
158  ErrorCode apply_batch(uint64_t cur, uint64_t next);
159 
160  ErrorStack finalize();
161 
163  ErrorCode dump_data_pages();
164 
166  bool verify_new_pointer(storage::SnapshotPagePointer pointer) const;
168  bool verify_old_pointer(storage::SnapshotPagePointer pointer) const;
169 
170  HashDataPage* resolve_data(VolatilePagePointer pointer) const ALWAYS_INLINE;
171  HashIntermediatePage* resolve_intermediate(VolatilePagePointer pointer) const ALWAYS_INLINE;
172 
173  bool is_initial_snapshot() const { return previous_root_page_pointer_ == 0; }
174 
178 
179  HashIntermediatePage* get_cur_path_page(uint8_t level) const { return cur_path_ + level; }
181  HashIntermediatePage* get_cur_path_lowest() const {
182  return get_cur_path_page(cur_path_lowest_level_);
183  }
189  SnapshotPagePointer get_cur_path_bin_head(HashBin bin) const;
190 
192  ErrorStack init_cur_path();
197  ErrorCode update_cur_path(HashBin bin);
204  ErrorCode update_cur_path_if_needed(HashBin bin) ALWAYS_INLINE;
206  bool verify_cur_path() const;
207 
211 
215  ErrorStack close_cur_bin();
221  ErrorStack open_cur_bin(HashBin bin);
222 
226 
227  ErrorStack init_intermediates();
229  HashComposedBinsPage* get_intermediate_head(uint8_t root_index) const {
230  ASSERT_ND(root_index < storage_.get_root_children());
231  return intermediate_base_ + root_index;
232  }
234  HashComposedBinsPage* get_intermediate_tail(uint8_t root_index) const;
235 
241  void update_cur_intermediate_tail(HashBin bin);
243  void update_cur_intermediate_tail_if_needed(HashBin bin) ALWAYS_INLINE;
244 
251  ErrorCode append_to_intermediate(SnapshotPagePointer page_id, HashBin bin);
252 
254  ErrorCode expand_intermediate_pool_if_needed();
255 
262  ErrorStack install_snapshot_data_pages(uint64_t* installed_count) const;
264  ErrorStack install_snapshot_data_pages_root_child(
265  const HashComposedBinsPage* composed,
266  HashIntermediatePage* volatile_root_child,
267  uint64_t* installed_count) const;
268 
272  Engine* const engine_;
273  snapshot::MergeSort* const merge_sort_;
274  const Epoch system_initial_epoch_;
275  const StorageId storage_id_;
276  const snapshot::SnapshotId snapshot_id_;
277  const HashStorage storage_;
278  snapshot::SnapshotWriter* const snapshot_writer_;
279  cache::SnapshotFileSet* const previous_snapshot_files_;
281  HashRootInfoPage* const root_info_page_;
282 
283  const bool partitionable_;
284  const uint8_t levels_;
285  const uint8_t bin_bits_;
286  const uint8_t bin_shifts_;
287  const uint16_t root_children_;
288  const uint16_t numa_node_;
289  const HashBin total_bin_count_;
290  const SnapshotPagePointer previous_root_page_pointer_;
291 
293  const memory::GlobalVolatilePageResolver& volatile_resolver_;
294 
298 
303  HashIntermediatePage* cur_path_;
307  memory::AlignedMemory cur_path_memory_;
308 
314  uint8_t cur_path_lowest_level_;
315 
320  HashBinRange cur_path_valid_range_;
321 
328  HashBin cur_bin_;
329  const HashBin kCurBinNotOpened = (1ULL << kHashMaxBinBits);
330 
334  HashTmpBin cur_bin_table_;
335 
337  memory::AlignedMemory data_page_io_memory_;
338 
344  HashComposedBinsPage* cur_intermediate_tail_;
345 
350  uint32_t allocated_pages_;
356  uint32_t allocated_intermediates_;
357  uint32_t max_pages_;
358  uint32_t max_intermediates_;
360  HashDataPage* page_base_;
366  HashComposedBinsPage* intermediate_base_;
367 };
368 
369 
370 } // namespace hash
371 } // namespace storage
372 } // namespace foedus
373 #endif // FOEDUS_STORAGE_HASH_HASH_COMPOSER_IMPL_HPP_
void drop_root_volatile(const Composer::DropVolatilesArguments &args)
ErrorStack construct_root(const Composer::ConstructRootArguments &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
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
An in-memory single-threaded data structure to compose tuples in a hash bin.
Definition: hash_tmpbin.hpp:54
Represents a pointer to a volatile page with modification count for preventing ABA.
Definition: storage_id.hpp:194
Forward declarations of classes in root package.
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
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.
static void launch_construct_root_multi_level(HashComposer *pointer, const Composer::ConstructRootArguments *args, uint16_t numa_node, HashIntermediatePage *root_page, ErrorStack *out_error)
launched on its own thread.
Forward declarations of classes in cache package.
HashComposer(Composer *parent)
HashComposer methods.
Definitions of IDs in this package and a few related constant values.
Receives an arbitrary number of sorted buffers and emits one fully sorted stream of logs...
Definition: merge_sort.hpp:77
uint64_t SnapshotPagePointer
Page ID of a snapshot page.
Definition: storage_id.hpp:79
HashComposer's compose() implementation separated from the class itself.
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
Just a marker to denote that the memory region represents a data page.
Definition: page.hpp:334
Represents a range of hash bins in a hash storage, such as what an intermediate page is responsible f...
Definition: hash_id.hpp:172
Retrun value of drop_volatiles()
Definition: composer.hpp:171
uint16_t SnapshotId
Unique ID of Snapshot.
Definition: snapshot_id.hpp:43
Represents a key-value store based on a dense and regular hash.
ErrorStack compose(const Composer::ComposeArguments &args)
Forward declarations of classes in memory package.
Represents an intermediate page in Hashtable Storage.
uint64_t HashBin
Represents a bin of a hash value.
Definition: hash_id.hpp:142
Represents an individual data page in Hashtable Storage.
Represents one memory block aligned to actual OS/hardware pages.
Resolves an offset in a volatile page pool to an actual pointer and vice versa.
Composer for a hash storage.
HashComposeContext(Engine *engine, snapshot::MergeSort *merge_sort, snapshot::SnapshotWriter *snapshot_writer, cache::SnapshotFileSet *previous_snapshot_files, Page *root_info_page)
HashComposeContext methods.
const uint8_t kHashMaxBinBits
Maximum number allowed for bin-bits.
Definition: hash_id.hpp:159
#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
Definitions of IDs in this package and a few related constant values.
#define ALWAYS_INLINE
A function suffix to hint that the function should always be inlined.
Definition: compiler.hpp:106
ErrorCode
Enum of error codes defined in error_code.xmacro.
Definition: error_code.hpp:85
Forward declarations of classes in hash storage package.
A page to pack many ComposedBin as an output of composer.
Writes out one snapshot file for all data pages in one reducer.