libfoedus-core
FOEDUS Core Library
hash_partitioner_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_PARTITIONER_IMPL_HPP_
19 #define FOEDUS_STORAGE_HASH_HASH_PARTITIONER_IMPL_HPP_
20 
21 #include <stdint.h>
22 
23 #include <cstring>
24 #include <iosfwd>
25 
26 #include "foedus/error_stack.hpp"
27 #include "foedus/fwd.hpp"
28 #include "foedus/memory/fwd.hpp"
32 
33 namespace foedus {
34 namespace storage {
35 namespace hash {
67 class HashPartitioner final {
68  public:
69  explicit HashPartitioner(Partitioner* parent);
70 
72  void design_partition_task(uint16_t task);
73 
74  bool is_partitionable() const;
76  void sort_batch(const Partitioner::SortBatchArguments& args) const;
77 
78  const PartitionId* get_bucket_owners() const;
79 
80  friend std::ostream& operator<<(std::ostream& o, const HashPartitioner& v);
81 
82  private:
83  void design_partition_task_recurse(
84  const memory::GlobalVolatilePageResolver& resolver,
85  const HashIntermediatePage* page);
86 
87  Engine* const engine_;
88  const StorageId id_;
89  PartitionerMetadata* const metadata_;
90  HashPartitionerData* data_;
91 };
92 
93 struct HashPartitionerData final {
94  // only for reinterpret_cast
95  HashPartitionerData() = delete;
96  ~HashPartitionerData() = delete;
97 
98  static uint64_t object_size(uint16_t node_count, HashBin total_bin_count) {
99  if (node_count <= 1U) {
100  return 16; // in this case we don't need bin_owners_
101  } else {
102  return total_bin_count + 16;
103  }
104  }
105  uint64_t object_size() const {
106  if (!partitionable_) {
107  return 16;
108  } else {
109  return total_bin_count_ + 16;
110  }
111  }
112 
114  bool partitionable_; // +1 -> 1
115  uint8_t levels_; // +1 -> 2
116  uint8_t bin_bits_; // +1 -> 3
117  uint8_t bin_shifts_; // +1 -> 4
118  char padding_[4]; // +4 -> 8
119 
122 
128 };
129 
130 
131 } // namespace hash
132 } // namespace storage
133 } // namespace foedus
134 #endif // FOEDUS_STORAGE_HASH_HASH_PARTITIONER_IMPL_HPP_
thread::ThreadGroupId PartitionId
As partition=NUMA node, this is just a synonym of foedus::thread::ThreadGroupId.
Definition: storage_id.hpp:65
friend std::ostream & operator<<(std::ostream &o, const HashPartitioner &v)
Definitions of IDs in this package and a few related constant values.
const PartitionId * get_bucket_owners() const
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
Partitioner for a hash storage.
Forward declarations of classes in root package.
static uint64_t object_size(uint16_t node_count, HashBin total_bin_count)
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
HashBin total_bin_count_
Size of the entire hash.
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
void sort_batch(const Partitioner::SortBatchArguments &args) const
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
Tiny metadata of partitioner for every storage used while log gleaning.
Partitioning and sorting logic for one storage.
Definition: partitioner.hpp:70
void partition_batch(const Partitioner::PartitionBatchArguments &args) const
Resolves an offset in a volatile page pool to an actual pointer and vice versa.
ErrorStack design_partition(const Partitioner::DesignPartitionArguments &args)
Definitions of IDs in this package and a few related constant values.
PartitionId bin_owners_[8]
partition of each hash bin.
bool partitionable_
if false, every record goes to node-0.