libfoedus-core
FOEDUS Core Library
masstree_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_MASSTREE_MASSTREE_STORAGE_HPP_
19 #define FOEDUS_STORAGE_MASSTREE_MASSTREE_STORAGE_HPP_
20 
21 #include <iosfwd>
22 #include <string>
23 
24 #include "foedus/attachable.hpp"
25 #include "foedus/cxx11.hpp"
26 #include "foedus/fwd.hpp"
27 #include "foedus/initializable.hpp"
28 #include "foedus/storage/fwd.hpp"
33 #include "foedus/thread/fwd.hpp"
34 #include "foedus/xct/xct_id.hpp"
35 
36 namespace foedus {
37 namespace storage {
38 namespace masstree {
43 class MasstreeStorage CXX11_FINAL : public Storage<MasstreeStorageControlBlock> {
44  public:
48 
50  MasstreeStorage(Engine* engine, MasstreeStorageControlBlock* control_block);
51  MasstreeStorage(Engine* engine, StorageControlBlock* control_block);
52  MasstreeStorage(Engine* engine, StorageId id);
53  MasstreeStorage(Engine* engine, const StorageName& name);
54  MasstreeStorage(const MasstreeStorage& other);
56 
57  // Storage interface
59  ErrorStack create(const Metadata &metadata);
60  ErrorStack load(const StorageControlBlock& snapshot_block);
61  ErrorStack drop();
62  friend std::ostream& operator<<(std::ostream& o, const MasstreeStorage& v);
63 
64 
81  thread::Thread* context,
82  bool install_volatile,
83  bool cache_snapshot,
84  KeySlice from = kInfimumSlice,
86 
87  // TASK(Hideaki) implement non key-slice version of prefetch_pages. so far this is enough, tho.
88 
120  xct::RwLockableXctId* old_address,
121  xct::WriteXctAccess* write_set);
122 
124 
125  // get_record() methods
126 
145  thread::Thread* context,
146  const void* key,
147  KeyLength key_length,
148  void* payload,
149  PayloadLength* payload_capacity,
150  bool read_only);
151 
166  thread::Thread* context,
167  const void* key,
168  KeyLength key_length,
169  void* payload,
170  PayloadLength payload_offset,
171  PayloadLength payload_count,
172  bool read_only);
173 
187  template <typename PAYLOAD>
189  thread::Thread* context,
190  const void* key,
191  KeyLength key_length,
192  PAYLOAD* payload,
193  PayloadLength payload_offset,
194  bool read_only);
195 
207  thread::Thread* context,
208  KeySlice key,
209  void* payload,
210  PayloadLength* payload_capacity,
211  bool read_only);
212 
219  thread::Thread* context,
220  KeySlice key,
221  void* payload,
222  PayloadLength payload_offset,
223  PayloadLength payload_count,
224  bool read_only);
225 
231  template <typename PAYLOAD>
233  thread::Thread* context,
234  KeySlice key,
235  PAYLOAD* payload,
236  PayloadLength payload_offset,
237  bool read_only);
238 
239  // insert_record() methods
240 
253  thread::Thread* context,
254  const void* key,
255  KeyLength key_length,
256  const void* payload,
257  PayloadLength payload_count) ALWAYS_INLINE {
258  return insert_record(context, key, key_length, payload, payload_count, payload_count);
259  }
260 
268  thread::Thread* context,
269  const void* key,
270  KeyLength key_length,
271  const void* payload,
272  PayloadLength payload_count,
273  PayloadLength physical_payload_hint);
274 
285  thread::Thread* context,
286  const void* key,
287  KeyLength key_length) ALWAYS_INLINE {
288  return insert_record(context, key, key_length, CXX11_NULLPTR, 0U);
289  }
290 
299  thread::Thread* context,
300  KeySlice key,
301  const void* payload,
302  PayloadLength payload_count) ALWAYS_INLINE {
303  return insert_record_normalized(context, key, payload, payload_count, payload_count);
304  }
305 
310  thread::Thread* context,
311  KeySlice key,
312  const void* payload,
313  PayloadLength payload_count,
314  PayloadLength physical_payload_hint);
315 
322  return insert_record_normalized(context, key, CXX11_NULLPTR, 0U);
323  }
324 
325  // delete_record() methods
326 
336  ErrorCode delete_record(thread::Thread* context, const void* key, KeyLength key_length);
337 
344 
345  // upsert_record() methods
346 
364  thread::Thread* context,
365  const void* key,
366  KeyLength key_length,
367  const void* payload,
368  PayloadLength payload_count) ALWAYS_INLINE {
369  return upsert_record(context, key, key_length, payload, payload_count, payload_count);
370  }
371 
379  thread::Thread* context,
380  const void* key,
381  KeyLength key_length,
382  const void* payload,
383  PayloadLength payload_count,
384  PayloadLength physical_payload_hint);
385 
393  thread::Thread* context,
394  const void* key,
395  KeyLength key_length) ALWAYS_INLINE {
396  return upsert_record(context, key, key_length, CXX11_NULLPTR, 0U);
397  }
398 
407  thread::Thread* context,
408  KeySlice key,
409  const void* payload,
410  PayloadLength payload_count) ALWAYS_INLINE {
411  return upsert_record_normalized(context, key, payload, payload_count, payload_count);
412  }
413 
418  thread::Thread* context,
419  KeySlice key,
420  const void* payload,
421  PayloadLength payload_count,
422  PayloadLength physical_payload_hint);
423 
430  return upsert_record_normalized(context, key, CXX11_NULLPTR, 0U);
431  }
432 
433  // overwrite_record() methods
434 
449  thread::Thread* context,
450  const void* key,
451  KeyLength key_length,
452  const void* payload,
453  PayloadLength payload_offset,
454  PayloadLength payload_count);
455 
467  template <typename PAYLOAD>
469  thread::Thread* context,
470  const void* key,
471  KeyLength key_length,
472  PAYLOAD payload,
473  PayloadLength payload_offset);
474 
485  thread::Thread* context,
486  KeySlice key,
487  const void* payload,
488  PayloadLength payload_offset,
489  PayloadLength payload_count);
490 
497  template <typename PAYLOAD>
499  thread::Thread* context,
500  KeySlice key,
501  PAYLOAD payload,
502  PayloadLength payload_offset);
503 
504 
505  // increment_record() methods
506 
519  template <typename PAYLOAD>
521  thread::Thread* context,
522  const void* key,
523  KeyLength key_length,
524  PAYLOAD* value,
525  PayloadLength payload_offset);
526 
531  template <typename PAYLOAD>
533  thread::Thread* context,
534  KeySlice key,
535  PAYLOAD* value,
536  PayloadLength payload_offset);
537 
538  // TODO(Hideaki): Extend/shrink/update methods for payload. A bit faster than delete + insert.
539 
541 
550  Engine* engine,
551  bool volatile_only = false,
552  uint32_t max_pages = 1024U);
553 
559 
576  };
577 
590 
607  thread::Thread* context,
608  uint32_t desired_count,
609  bool disable_no_record_split = true);
610 
618  Layer layer,
619  KeyLength key_length,
620  PayloadLength payload_length);
621 };
622 } // namespace masstree
623 } // namespace storage
624 } // namespace foedus
625 #endif // FOEDUS_STORAGE_MASSTREE_MASSTREE_STORAGE_HPP_
uint32_t found_boundary_capacity_
[IN] capacity of found_boundaries_.
const KeySlice kInfimumSlice
ErrorCode get_record_normalized(thread::Thread *context, KeySlice key, void *payload, PayloadLength *payload_capacity, bool read_only)
Retrieves an entire record of the given primitive key in this Masstree.
const KeySlice * prefix_slices_
[IN] slices of higher layers that lead to the B-trie layer of interest.
uint16_t PayloadLength
Represents a byte-length of a payload in this package.
Definition: masstree_id.hpp:92
friend std::ostream & operator<<(std::ostream &o, const MasstreeStorage &v)
Definitions of IDs in this package and a few related constant values.
uint16_t SlotIndex
Index of a record in a (border) page.
#define CXX11_NULLPTR
Used in public headers in place of "nullptr" of C++11.
Definition: cxx11.hpp:132
Log type of CREATE MASSTREE STORAGE operation.
ErrorCode increment_record_normalized(thread::Thread *context, KeySlice key, PAYLOAD *value, PayloadLength payload_offset)
For primitive key.
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
KeySlice to_
[IN] lists up page boundaries up to this slice
Represents a record of write-access during a transaction.
Definition: xct_access.hpp:168
ErrorStack create(const Metadata &metadata)
Represents one thread running on one NUMA core.
Definition: thread.hpp:48
ErrorCode upsert_record(thread::Thread *context, const void *key, KeyLength key_length, const void *payload, PayloadLength payload_count) __attribute__((always_inline))
Inserts a new record of the given key or replaces the existing one, or so-called upsert.
Result of track_moved_record().
Definition: xct_id.hpp:1180
Forward declarations of classes in root package.
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
ErrorCode upsert_record_normalized(thread::Thread *context, KeySlice key) __attribute__((always_inline))
Upserts a new record without payload of the given primitive key in this Masstree. ...
uint64_t KeySlice
Each key slice is an 8-byte integer.
Definitions of IDs in this package and a few related constant values.
uint16_t KeyLength
Represents a byte-length of a key in this package.
Definition: masstree_id.hpp:69
ErrorCode upsert_record_normalized(thread::Thread *context, KeySlice key, const void *payload, PayloadLength payload_count) __attribute__((always_inline))
Upserts a new record of the given primitive key in this Masstree.
MasstreeStorage & operator=(const MasstreeStorage &other)
ErrorCode get_record_part_normalized(thread::Thread *context, KeySlice key, void *payload, PayloadLength payload_offset, PayloadLength payload_count, bool read_only)
Retrieves a part of the given primitive key in this Masstree.
The MCS reader-writer lock variant of LockableXctId.
Definition: xct_id.hpp:1132
ErrorCode upsert_record(thread::Thread *context, const void *key, KeyLength key_length) __attribute__((always_inline))
Upserts a new record without payload of the given key in this Masstree.
Metadata of one storage.
Definition: metadata.hpp:58
Represents one key-value store.
Definition: storage.hpp:116
xct::TrackMovedRecordResult track_moved_record(xct::RwLockableXctId *old_address, xct::WriteXctAccess *write_set)
Resolves a "moved" record.
uint8_t Layer
Represents the depth of a B-trie layer.
Definition: masstree_id.hpp:42
ErrorCode get_record_primitive(thread::Thread *context, const void *key, KeyLength key_length, PAYLOAD *payload, PayloadLength payload_offset, bool read_only)
Retrieves a part of the given key in this Masstree as a primitive value.
ErrorCode prefetch_pages_normalized(thread::Thread *context, bool install_volatile, bool cache_snapshot, KeySlice from=kInfimumSlice, KeySlice to=kSupremumSlice)
Prefetch data pages in this storage.
Forward declarations of classes in storage package.
Definitions of IDs in this package and a few related constant values.
ErrorCode insert_record_normalized(thread::Thread *context, KeySlice key) __attribute__((always_inline))
Inserts a new record without payload of the given primitive key in this Masstree. ...
#define CXX11_FINAL
Used in public headers in place of "final" of C++11.
Definition: cxx11.hpp:131
ErrorStack fatify_first_root(thread::Thread *context, uint32_t desired_count, bool disable_no_record_split=true)
Deliberately causes splits under the volatile root of first layer, or "fatify" it.
ErrorCode peek_volatile_page_boundaries(Engine *engine, const PeekBoundariesArguments &args)
Checks the volatile pages of this storage to give hints to decide page boundary keys.
ErrorCode get_record(thread::Thread *context, const void *key, KeyLength key_length, void *payload, PayloadLength *payload_capacity, bool read_only)
Retrieves an entire record of the given key in this Masstree.
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
uint32_t * found_boundary_count_
[OUT] number of found_boundaries_ entries returned
static SlotIndex estimate_records_per_page(Layer layer, KeyLength key_length, PayloadLength payload_length)
KeySlice * found_boundaries_
[OUT] fence-slices of border pages between from-to
ErrorCode overwrite_record_normalized(thread::Thread *context, KeySlice key, const void *payload, PayloadLength payload_offset, PayloadLength payload_count)
Overwrites a part of one record of the given primitive key in this Masstree.
ErrorStack load(const StorageControlBlock &snapshot_block)
ErrorCode delete_record_normalized(thread::Thread *context, KeySlice key)
Deletes a record of the given primitive key from this Masstree.
ErrorStack debugout_single_thread(Engine *engine, bool volatile_only=false, uint32_t max_pages=1024U)
A super-expensive and single-thread only debugging feature to write out gigantic human-readable texts...
ErrorStack verify_single_thread(thread::Thread *context)
ErrorCode delete_record(thread::Thread *context, const void *key, KeyLength key_length)
Deletes a record of the given key from this Masstree.
ErrorStack hcc_reset_all_temperature_stat()
Resets all volatile pages' temperature stat to be zero in this storage.
ErrorCode insert_record_normalized(thread::Thread *context, KeySlice key, const void *payload, PayloadLength payload_count) __attribute__((always_inline))
Inserts a new record of the given primitive key in this Masstree.
ErrorCode get_record_part(thread::Thread *context, const void *key, KeyLength key_length, void *payload, PayloadLength payload_offset, PayloadLength payload_count, bool read_only)
Retrieves a part of the given key in this Masstree.
ErrorCode increment_record(thread::Thread *context, const void *key, KeyLength key_length, PAYLOAD *value, PayloadLength payload_offset)
This one further optimizes overwrite methods for the frequent use case of incrementing some data in p...
ErrorCode get_record_primitive_normalized(thread::Thread *context, KeySlice key, PAYLOAD *payload, PayloadLength payload_offset, bool read_only)
Retrieves a part of the given primitive key in this Masstree as a primitive value.
ErrorCode overwrite_record_primitive_normalized(thread::Thread *context, KeySlice key, PAYLOAD payload, PayloadLength payload_offset)
Overwrites a part of one record of the given primitive key in this Masstree as a primitive value...
const KeySlice kSupremumSlice
ErrorCode overwrite_record(thread::Thread *context, const void *key, KeyLength key_length, const void *payload, PayloadLength payload_offset, PayloadLength payload_count)
Overwrites a part of one record of the given key in this Masstree.
Forward declarations of classes in masstree storage package.
Forward declarations of classes in thread package.
ErrorCode overwrite_record_primitive(thread::Thread *context, const void *key, KeyLength key_length, PAYLOAD payload, PayloadLength payload_offset)
Overwrites a part of one record of the given key in this Masstree as a primitive value.
#define ALWAYS_INLINE
A function suffix to hint that the function should always be inlined.
Definition: compiler.hpp:106
A base layout of shared data for all storage types.
Definition: storage.hpp:53
ErrorCode insert_record(thread::Thread *context, const void *key, KeyLength key_length, const void *payload, PayloadLength payload_count) __attribute__((always_inline))
Inserts a new record of the given key in this Masstree.
ErrorCode
Enum of error codes defined in error_code.xmacro.
Definition: error_code.hpp:85
KeySlice from_
[IN] lists up page boundaries from this slice
const MasstreeMetadata * get_masstree_metadata() const
ErrorCode insert_record(thread::Thread *context, const void *key, KeyLength key_length) __attribute__((always_inline))
Inserts a new record without payload of the given key in this Masstree.