libfoedus-core
FOEDUS Core Library
partitioner.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_PARTITIONER_HPP_
19 #define FOEDUS_STORAGE_PARTITIONER_HPP_
20 
21 #include <stdint.h>
22 
23 #include <iosfwd>
24 
25 #include "foedus/attachable.hpp"
26 #include "foedus/cxx11.hpp"
27 #include "foedus/epoch.hpp"
28 #include "foedus/error_stack.hpp"
29 #include "foedus/fwd.hpp"
30 #include "foedus/cache/fwd.hpp"
31 #include "foedus/memory/fwd.hpp"
36 
37 namespace foedus {
38 namespace storage {
70 class Partitioner CXX11_FINAL : public Attachable<PartitionerMetadata> {
71  public:
80  Partitioner(Engine* engine, StorageId id);
81 
83  const PartitionerMetadata& get_metadata() const;
85  bool is_valid() const;
86  StorageId get_storage_id() const { return id_;}
87  StorageType get_storage_type() const { return type_; }
88 
98  bool is_partitionable();
99 
105  };
106 
114 
124  uint32_t logs_count_;
127  };
128 
137  void partition_batch(const PartitionBatchArguments& args);
138 
146  uint32_t logs_count_;
169  uint32_t* written_count_;
170  };
171 
183  void sort_batch(const SortBatchArguments& args);
184 
185  friend std::ostream& operator<<(std::ostream& o, const Partitioner& v);
186 
187  private:
189  StorageId id_;
191  StorageType type_;
192 };
193 
210  // This object is placed on shared memory. We only reinterpret them.
213 
214  void initialize() {
215  mutex_.initialize();
216  clear_counts();
217  }
218  void uninitialize() {
220  }
221  void clear_counts() {
222  valid_ = false;
223  data_offset_ = 0;
224  data_size_ = 0;
225  }
226 
237  bool valid_;
242  uint32_t data_offset_;
246  uint32_t data_size_;
247 
253  void* locate_data(Engine* engine);
254 
264  ErrorCode allocate_data(Engine* engine, soc::SharedMutexScope* locked, uint32_t data_size);
265 
270  static PartitionerMetadata* get_metadata(Engine* engine, StorageId id);
273 
274  friend std::ostream& operator<<(std::ostream& o, const PartitionerMetadata& v);
275 };
276 
277 } // namespace storage
278 } // namespace foedus
279 #endif // FOEDUS_STORAGE_PARTITIONER_HPP_
Packages handling of 4-bytes representation of position in log buffers.
Definition: log_buffer.hpp:38
bool valid_
Whether this partitioner information (metadata+data) has been constructed.
uint32_t * written_count_
[OUT] how many logs written to output_buffer.
uint32_t shortest_key_length_
[masstree/hash] shortest key length in the log entries.
friend std::ostream & operator<<(std::ostream &o, const Partitioner &v)
PartitionId * results_
[OUT] this method will set the partition of logs[i] to results[i].
const snapshot::LogBuffer & log_buffer_
Converts from positions to physical pointers.
thread::ThreadGroupId PartitionId
As partition=NUMA node, this is just a synonym of foedus::thread::ThreadGroupId.
Definition: storage_id.hpp:65
void sort_batch(const SortBatchArguments &args)
Called from log reducer to sort log entries by keys.
uint32_t logs_count_
number of entries to process.
memory::AlignedMemory * work_memory_
Working memory to be used in this method.
Epoch base_epoch_
All log entries in this inputs are assured to be after this epoch.
Definitions of IDs in this package and a few related constant values.
Typedefs of ID types used in snapshot package.
uint32_t StorageId
Unique ID for storage.
Definition: storage_id.hpp:55
void initialize(bool recursive=false)
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
uint32_t logs_count_
number of entries to process.
uint32_t BufferPosition
Represents a position in some buffer.
Definition: snapshot_id.hpp:72
Forward declarations of classes in root package.
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
Represents a time epoch.
Definition: epoch.hpp:61
Holds a set of read-only file objects for snapshot files.
Forward declarations of classes in cache package.
A mutex that can be placed in shared memory and used from multiple processes.
StorageType get_storage_type() const
Definition: partitioner.hpp:87
snapshot::BufferPosition * output_buffer_
sorted results are written to this variable.
Partitioner(Engine *engine, StorageId id)
Instantiate an instance for the given storage.
Definition: partitioner.cpp:84
static PartitionerMetadata * get_index0_metadata(Engine *engine)
Returns the special index-0 entry that manages data block allocation for partitioners.
Definition: partitioner.cpp:45
uint32_t data_size_
The size of the partitioner data.
#define CXX11_FINAL
Used in public headers in place of "final" of C++11.
Definition: cxx11.hpp:131
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
ErrorCode allocate_data(Engine *engine, soc::SharedMutexScope *locked, uint32_t data_size)
Allocates a patitioner data in shared memory of the given size.
Definition: partitioner.cpp:61
const snapshot::BufferPosition * log_positions_
positions of log records.
Auto-lock scope object for SharedMutex.
StorageId get_storage_id() const
Definition: partitioner.hpp:86
uint32_t longest_key_length_
[masstree/hash] longest key length in the log entries.
soc::SharedMutex mutex_
Serialize concurrent initialization of this partitioner.
Attachable Resources on Shared Memory.
Definition: attachable.hpp:58
uint32_t data_offset_
Relative offset from the beginning of partitioner data block that points to variable-sized partitione...
Forward declarations of classes in memory package.
StorageType
Type of the storage, such as hash.
Definition: storage_id.hpp:122
bool is_partitionable()
returns if this storage is partitionable.
Definition: partitioner.cpp:94
#define CXX11_FUNC_DELETE
Used in public headers in place of " = delete" of C++11.
Definition: cxx11.hpp:128
Tiny metadata of partitioner for every storage used while log gleaning.
void * locate_data(Engine *engine)
Returns the partitioner data pointed from this metadata.
Definition: partitioner.cpp:51
Represents one memory block aligned to actual OS/hardware pages.
void partition_batch(const PartitionBatchArguments &args)
Identifies the partition of each log record in a batched fashion.
memory::AlignedMemory * work_memory_
Working memory to be used in this method.
Partitioning and sorting logic for one storage.
Definition: partitioner.hpp:70
bool is_valid() const
whether this object is ready for partitioning.
Definition: partitioner.cpp:92
const snapshot::BufferPosition * log_positions_
positions of log records.
ErrorStack design_partition(const DesignPartitionArguments &args)
Determines partitioning scheme for this storage.
friend std::ostream & operator<<(std::ostream &o, const PartitionerMetadata &v)
const snapshot::LogBuffer & log_buffer_
Converts from positions to physical pointers.
ErrorCode
Enum of error codes defined in error_code.xmacro.
Definition: error_code.hpp:85
const PartitionerMetadata & get_metadata() const
Returns tiny metadata of the partitioner in shared memory.
Definition: partitioner.cpp:91
PartitionId local_partition_
The node the caller (mapper) resides in.
static PartitionerMetadata * get_metadata(Engine *engine, StorageId id)
Returns the shared memory for the given storage ID.
Definition: partitioner.cpp:38