libfoedus-core
FOEDUS Core Library
array_storage.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_STORAGE_HPP_
19 #define FOEDUS_STORAGE_ARRAY_ARRAY_STORAGE_HPP_
20 
21 #include <cstring>
22 #include <iosfwd>
23 #include <string>
24 
25 #include "foedus/assert_nd.hpp"
26 #include "foedus/attachable.hpp"
27 #include "foedus/cxx11.hpp"
28 #include "foedus/fwd.hpp"
30 #include "foedus/storage/fwd.hpp"
37 #include "foedus/thread/fwd.hpp"
38 
39 namespace foedus {
40 namespace storage {
41 namespace array {
42 
47 class ArrayStorage CXX11_FINAL : public Storage<ArrayStorageControlBlock> {
48  public:
52 
53  ArrayStorage();
54  ArrayStorage(Engine* engine, ArrayStorageControlBlock* control_block);
55  ArrayStorage(Engine* engine, StorageControlBlock* control_block);
56  ArrayStorage(Engine* engine, StorageId id);
57  ArrayStorage(Engine* engine, const StorageName& name);
58  ArrayStorage(const ArrayStorage& other);
59  ArrayStorage& operator=(const ArrayStorage& other);
60 
61  // Storage interface
62  const ArrayMetadata* get_array_metadata() const;
63  ErrorStack create(const Metadata &metadata);
64  ErrorStack load(const StorageControlBlock& snapshot_block);
65  ErrorStack drop();
66 
82  thread::Thread* context,
83  bool install_volatile,
84  bool cache_snapshot,
85  ArrayOffset from,
86  ArrayOffset to);
87 
88  // this storage type doesn't use moved bit
89 
96  uint16_t get_payload_size() const;
97 
100 
102  uint8_t get_levels() const;
103 
113  ErrorCode get_record(thread::Thread* context, ArrayOffset offset, void *payload);
114 
126  void *payload, uint16_t payload_offset, uint16_t payload_count);
127 
139  template <typename T>
141  T *payload, uint16_t payload_offset);
142 
154  ErrorCode get_record_payload(thread::Thread* context, ArrayOffset offset, const void** payload);
155 
168  ErrorCode get_record_for_write(thread::Thread* context, ArrayOffset offset, Record** record);
169 
171  template <typename T>
173  thread::Thread* context,
174  uint16_t payload_offset,
175  uint16_t batch_size,
176  const ArrayOffset* offset_batch,
177  T *payload);
179  thread::Thread* context,
180  uint16_t batch_size,
181  const ArrayOffset* offset_batch,
182  const void** payload_batch);
184  thread::Thread* context,
185  uint16_t batch_size,
186  const ArrayOffset* offset_batch,
187  Record** record_batch);
188 
198  ErrorCode overwrite_record(thread::Thread* context, ArrayOffset offset, const void *payload) {
199  return overwrite_record(context, offset, payload, 0, get_payload_size());
200  }
212  const void *payload, uint16_t payload_offset, uint16_t payload_count);
213 
225  template <typename T>
227  T payload, uint16_t payload_offset);
228 
242  thread::Thread* context,
243  ArrayOffset offset,
244  Record* record,
245  const void *payload,
246  uint16_t payload_offset,
247  uint16_t payload_count);
248 
261  template <typename T>
263  thread::Thread* context,
264  ArrayOffset offset,
265  Record* record,
266  T payload,
267  uint16_t payload_offset);
268 
283  template <typename T>
285  T *value, uint16_t payload_offset);
286 
301  template <typename T>
303  thread::Thread* context,
304  ArrayOffset offset,
305  T value,
306  uint16_t payload_offset);
307 
308 
309  friend std::ostream& operator<<(std::ostream& o, const ArrayStorage& v);
310 
316 
318 };
319 
320 } // namespace array
321 } // namespace storage
322 } // namespace foedus
323 #endif // FOEDUS_STORAGE_ARRAY_ARRAY_STORAGE_HPP_
ErrorCode increment_record(thread::Thread *context, ArrayOffset offset, T *value, uint16_t payload_offset)
This one further optimizes overwrite_record_primitive() for the frequent use case of incrementing som...
ErrorCode get_record_for_write_batch(thread::Thread *context, uint16_t batch_size, const ArrayOffset *offset_batch, Record **record_batch)
Represents one record in our key-value store.
Definition: record.hpp:33
Definitions of IDs in this package and a few related constant values.
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.
const ArrayMetadata * get_array_metadata() const
Represents one thread running on one NUMA core.
Definition: thread.hpp:48
uint64_t ArrayOffset
The only key type in array storage.
Definition: array_id.hpp:48
ArrayStorage & operator=(const ArrayStorage &other)
uint16_t get_payload_size() const
Returns byte size of one record in this array storage without internal overheads. ...
Forward declarations of classes in root package.
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
Forward declarations of classes in array storage package.
friend std::ostream & operator<<(std::ostream &o, const ArrayStorage &v)
ErrorStack create(const Metadata &metadata)
ErrorCode overwrite_record(thread::Thread *context, ArrayOffset offset, const void *payload)
Overwrites one record of the given offset in this array storage.
ErrorCode get_record_primitive_batch(thread::Thread *context, uint16_t payload_offset, uint16_t batch_size, const ArrayOffset *offset_batch, T *payload)
batched interface
ArrayOffset get_array_size() const
Returns the size of this array.
ErrorStack verify_single_thread(thread::Thread *context)
Metadata of one storage.
Definition: metadata.hpp:58
ErrorCode get_record(thread::Thread *context, ArrayOffset offset, void *payload)
Retrieves one record of the given offset in this array storage.
Represents one key-value store.
Definition: storage.hpp:116
Forward declarations of classes in storage package.
ErrorCode prefetch_pages(thread::Thread *context, bool install_volatile, bool cache_snapshot, ArrayOffset from, ArrayOffset to)
Prefetch data pages in this storage.
#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 get_record_payload(thread::Thread *context, ArrayOffset offset, const void **payload)
Retrieves a pointer to the entire payload.
Metadata of an array storage.
ErrorStack hcc_reset_all_temperature_stat()
Resets all volatile pages' temperature stat to be zero in this storage.
Log type of CREATE ARRAY STORAGE operation.
uint8_t get_levels() const
Returns the number of levels.
ErrorCode get_record_for_write(thread::Thread *context, ArrayOffset offset, Record **record)
Retrieves a pointer to the entire record for write (thus always in volatile page).
ErrorCode increment_record_oneshot(thread::Thread *context, ArrayOffset offset, T value, uint16_t payload_offset)
This is a faster increment that does not return the value after increment.
ErrorCode get_record_payload_batch(thread::Thread *context, uint16_t batch_size, const ArrayOffset *offset_batch, const void **payload_batch)
ErrorCode get_record_primitive(thread::Thread *context, ArrayOffset offset, T *payload, uint16_t payload_offset)
Retrieves a part of record of the given offset as a primitive type in this array storage.
Definitions of IDs in this package and a few related constant values.
Forward declarations of classes in thread package.
A base layout of shared data for all storage types.
Definition: storage.hpp:53
ErrorCode
Enum of error codes defined in error_code.xmacro.
Definition: error_code.hpp:85
ErrorCode overwrite_record_primitive(thread::Thread *context, ArrayOffset offset, T payload, uint16_t payload_offset)
Overwrites a part of record of the given offset as a primitive type in this array storage...
ErrorStack load(const StorageControlBlock &snapshot_block)