libfoedus-core
FOEDUS Core Library
hash_composed_bins_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_COMPOSED_BINS_IMPL_HPP_
19 #define FOEDUS_STORAGE_HASH_HASH_COMPOSED_BINS_IMPL_HPP_
20 
21 #include <stdint.h>
22 
23 #include <memory>
24 
25 #include "foedus/compiler.hpp"
26 #include "foedus/error_stack.hpp"
27 #include "foedus/cache/fwd.hpp"
28 #include "foedus/snapshot/fwd.hpp"
34 
35 namespace foedus {
36 namespace storage {
37 namespace hash {
38 
80 
85 struct ComposedBin final {
88 };
89 
90 const uint16_t kHashComposedBinsPageMaxBins = (kPageSize - 80) / sizeof(ComposedBin);
91 
101 struct HashComposedBinsPage final {
102  PageHeader header_; // +40 -> 40
103  HashBinRange bin_range_; // +16 -> 56
105  uint32_t bin_count_; // +4 -> 68
106  uint32_t dummy_; // +4 -> 72
107  uint64_t padding_; // +8 -> 80
109 };
110 
118 struct ComposedBinsBuffer final {
119  enum Constants {
120  kMinBufferSize = 1 << 6,
121  };
127  uint32_t total_pages_;
129  uint32_t buffer_size_;
134  uint32_t buffer_pos_;
136  uint32_t buffer_count_;
137 
142  uint32_t cursor_buffer_;
143 
148  uint16_t cursor_bin_;
151 
154 
155  void init(
156  cache::SnapshotFileSet* fileset,
157  SnapshotPagePointer head_page_id,
158  uint32_t total_pages,
159  uint32_t buffer_size,
160  HashComposedBinsPage* buffer);
161 
167  static void assure_read_buffer_size(memory::AlignedMemory* read_buffer, uint32_t inputs);
168 
184  return buffer_[cursor_buffer_];
185  }
191  ASSERT_ND(has_more());
192  ASSERT_ND(cursor_bin_count_ == get_cur_page().bin_count_);
193  ASSERT_ND(cursor_bin_ < cursor_bin_count_);
194  return get_cur_page().bins_[cursor_bin_];
195  }
196  bool has_more() const { return buffer_pos_ < total_pages_; }
197 };
198 
207 
209  std::unique_ptr< ComposedBinsBuffer[] > inputs_memory_;
210 
213  uint32_t input_count_;
215  uint8_t levels_;
216  uint8_t padding_;
217 
220 
222  const HashRootInfoPage* const* inputs,
223  uint32_t input_count,
224  PagePtr root_page,
225  uint16_t root_child_index,
226  memory::AlignedMemory* read_buffer,
227  cache::SnapshotFileSet* fileset,
228  snapshot::SnapshotWriter* writer,
229  uint32_t* writer_buffer_pos,
230  uint32_t* writer_higher_buffer_pos,
231  bool* had_any_change);
232 
239  ErrorCode process_a_bin(uint32_t* installed_count, HashBin* next_lowest_bin);
240 
246  HashBin lowest_bin,
247  cache::SnapshotFileSet* fileset,
248  snapshot::SnapshotWriter* writer,
249  uint32_t* writer_buffer_pos,
250  uint32_t* writer_higher_buffer_pos);
251 
254  HashBin bin,
255  uint8_t fixed_upto_level,
256  cache::SnapshotFileSet* fileset,
257  snapshot::SnapshotWriter* writer,
258  uint32_t* writer_buffer_pos,
259  uint32_t* writer_higher_buffer_pos);
260 
263  snapshot::SnapshotWriter* writer,
264  uint32_t* writer_buffer_pos,
265  uint32_t writer_higher_buffer_pos);
266 };
267 
269  if (LIKELY(cursor_bin_ + 1U < cursor_bin_count_)) {
270  ++cursor_bin_;
271  return kErrorCodeOk;
272  } else if (LIKELY(cursor_buffer_ + 1U < buffer_count_)) {
273  ++cursor_buffer_;
274  cursor_bin_ = 0;
276  return kErrorCodeOk;
277  } else {
278  return next_pages();
279  }
280 }
281 
282 static_assert(sizeof(HashRootInfoPage) == kPageSize, "incorrect sizeof(RootInfoPage)");
283 static_assert(sizeof(HashComposedBinsPage) == kPageSize, "incorrect sizeof(HashComposedBinsPage)");
284 
285 } // namespace hash
286 } // namespace storage
287 } // namespace foedus
288 #endif // FOEDUS_STORAGE_HASH_HASH_COMPOSED_BINS_IMPL_HPP_
Represents an output of composer on one bin.
SnapshotPagePointer head_page_id_
Page ID of the head of HashComposedBinsPage for this sub-tree.
ErrorCode assure_writer_buffer(snapshot::SnapshotWriter *writer, uint32_t *writer_buffer_pos, uint32_t writer_higher_buffer_pos)
Subroutine to flush the writer if needed to make sure it has enough room.
uint16_t cursor_bin_count_
Number of active bins in the current page.
Definitions of IDs in this package and a few related constant values.
ComposedBin bins_[kHashComposedBinsPageMaxBins]
Typedefs of ID types used in snapshot package.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
const uint16_t kHashComposedBinsPageMaxBins
uint32_t total_pages_
Number of HashComposedBinsPage from head_page_id_ contiguously emit by a composer.
uint32_t input_count_
total number of buffers in inputs_
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
Abstracts how we batch-read several HashComposedBinsPage emit from individual composers.
Forward declarations of classes in snapshot manager package.
Holds a set of read-only file objects for snapshot files.
PagePtr cur_path_[kHashMaxLevels]
The pages we are now composing.
#define LIKELY(x)
Hints that x is highly likely true.
Definition: compiler.hpp:103
Forward declarations of classes in cache package.
uint32_t buffer_size_
How many pages buffer_ can hold.
const uint8_t kHashMaxLevels
Max level of intermediate pages.
Definition: hash_id.hpp:104
0 means no-error.
Definition: error_code.hpp:87
void init(cache::SnapshotFileSet *fileset, SnapshotPagePointer head_page_id, uint32_t total_pages, uint32_t buffer_size, HashComposedBinsPage *buffer)
ErrorCode process_a_bin(uint32_t *installed_count, HashBin *next_lowest_bin)
Consumes inputs for the cur_path_[0] page and install snapshot pointers there.
uint64_t SnapshotPagePointer
Page ID of a snapshot page.
Definition: storage_id.hpp:79
ErrorCode next_pages()
Read pages to buffer_.
Just a marker to denote that a memory region represents a data page.
Definition: page.hpp:184
Represents a range of hash bins in a hash storage, such as what an intermediate page is responsible f...
Definition: hash_id.hpp:172
uint32_t buffer_pos_
index (0=head, total_pages_ - 1=tail, ) of the first page in the buffer_.
std::unique_ptr< ComposedBinsBuffer[] > inputs_memory_
just for auto release
uint16_t SnapshotId
Unique ID of Snapshot.
Definition: snapshot_id.hpp:43
uint32_t buffer_count_
number of pages so far read in the buffer_.
ErrorCode next_bin() __attribute__((always_inline))
Moves on to next bin.
Represents an intermediate page in Hashtable Storage.
HashIntermediatePage HashRootInfoPage
Output of one compose() call, which are then combined in construct_root().
HashComposedBinsPage * buffer_
The buffer to read contiguous pages in one shot.
uint64_t HashBin
Represents a bin of a hash value.
Definition: hash_id.hpp:142
uint16_t cursor_bin_
Cursor position for bin in the current page.
const HashComposedBinsPage & get_cur_page() const __attribute__((always_inline))
ErrorCode open_path(HashBin bin, uint8_t fixed_upto_level, cache::SnapshotFileSet *fileset, snapshot::SnapshotWriter *writer, uint32_t *writer_buffer_pos, uint32_t *writer_higher_buffer_pos)
Recursively opens pages down from fixed_upto_level.
Represents one memory block aligned to actual OS/hardware pages.
cache::SnapshotFileSet * fileset_
file handles
ErrorCode switch_path(HashBin lowest_bin, cache::SnapshotFileSet *fileset, snapshot::SnapshotWriter *writer, uint32_t *writer_buffer_pos, uint32_t *writer_higher_buffer_pos)
Moves cur_path_ to a page that cotains the specified bin.
#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.
static void assure_read_buffer_size(memory::AlignedMemory *read_buffer, uint32_t inputs)
If needed, expand the given read buffer to be used with the inputs.
#define ALWAYS_INLINE
A function suffix to hint that the function should always be inlined.
Definition: compiler.hpp:106
ErrorStack init(const HashRootInfoPage *const *inputs, uint32_t input_count, PagePtr root_page, uint16_t root_child_index, memory::AlignedMemory *read_buffer, cache::SnapshotFileSet *fileset, snapshot::SnapshotWriter *writer, uint32_t *writer_buffer_pos, uint32_t *writer_higher_buffer_pos, bool *had_any_change)
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
uint32_t cursor_buffer_
Cursor position for page in the buffer.
Forward declarations of classes in hash storage package.
const ComposedBin & get_cur_bin() const __attribute__((always_inline))
Packages all ComposedBinsBuffer to easily extract bins of current interest.
A page to pack many ComposedBin as an output of composer.
Writes out one snapshot file for all data pages in one reducer.