libfoedus-core
FOEDUS Core Library
masstree_storage_pimpl.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_PIMPL_HPP_
19 #define FOEDUS_STORAGE_MASSTREE_MASSTREE_STORAGE_PIMPL_HPP_
20 #include <stdint.h>
21 
22 #include <mutex>
23 #include <string>
24 #include <vector>
25 
26 #include "foedus/attachable.hpp"
27 #include "foedus/compiler.hpp"
28 #include "foedus/cxx11.hpp"
29 #include "foedus/fwd.hpp"
30 #include "foedus/cache/fwd.hpp"
31 #include "foedus/log/fwd.hpp"
32 #include "foedus/memory/fwd.hpp"
34 #include "foedus/storage/fwd.hpp"
35 #include "foedus/storage/page.hpp"
43 #include "foedus/thread/thread.hpp"
44 #include "foedus/xct/xct_id.hpp"
45 
46 namespace foedus {
47 namespace storage {
48 namespace masstree {
51  // this is backed by shared memory. not instantiation. just reinterpret_cast.
52  MasstreeStorageControlBlock() = delete;
54 
55  bool exists() const { return status_ == kExists || status_ == kMarkedForDeath; }
56 
75 
76  // Do NOT reorder members up to here. The layout must be compatible with StorageControlBlock
77  // Type-specific shared members below.
78 
89 };
90 
98 class MasstreeStoragePimpl final : public Attachable<MasstreeStorageControlBlock> {
99  public:
103  storage->get_engine(),
104  storage->get_control_block()) {}
105 
106  ErrorStack create(const MasstreeMetadata& metadata);
107  ErrorStack load(const StorageControlBlock& snapshot_block);
109  ErrorStack drop();
110 
111  bool exists() const { return control_block_->exists(); }
112  StorageId get_id() const { return control_block_->meta_.id_; }
113  const StorageName& get_name() const { return control_block_->meta_.name_; }
114  const MasstreeMetadata& get_meta() const { return control_block_->meta_; }
116  return control_block_->root_page_pointer_;
117  }
119 
121  thread::Thread* context,
122  bool for_write,
123  MasstreeIntermediatePage** root);
124 
130  thread::Thread* context,
131  MasstreePage* layer_root,
132  uint8_t current_layer,
133  bool for_writes,
134  KeySlice slice,
136 
139  thread::Thread* context,
140  const void* key,
141  KeyLength key_length,
142  bool for_writes,
143  RecordLocation* result);
146  thread::Thread* context,
147  KeySlice key,
148  bool for_writes,
149  RecordLocation* result);
150 
155  thread::Thread* context,
156  const void* key,
157  KeyLength key_length,
158  PayloadLength payload_count,
159  PayloadLength physical_payload_hint,
160  RecordLocation* result);
162  thread::Thread* context,
163  KeySlice key,
164  PayloadLength payload_count,
165  PayloadLength physical_payload_hint,
166  RecordLocation* result);
167 
170  thread::Thread* context,
171  const RecordLocation& location,
172  void* payload,
173  PayloadLength* payload_capacity);
175  thread::Thread* context,
176  const RecordLocation& location,
177  void* payload,
178  PayloadLength payload_offset,
179  PayloadLength payload_count);
180 
183  thread::Thread* context,
184  const RecordLocation& location,
185  log::RecordLogType* log_entry);
186 
189  thread::Thread* context,
190  const RecordLocation& location,
191  const void* be_key,
192  KeyLength key_length,
193  const void* payload,
194  PayloadLength payload_count);
195 
198  thread::Thread* context,
199  const RecordLocation& location,
200  const void* be_key,
201  KeyLength key_length);
202 
205  thread::Thread* context,
206  const RecordLocation& location,
207  const void* be_key,
208  KeyLength key_length,
209  const void* payload,
210  PayloadLength payload_count);
211 
214  thread::Thread* context,
215  const RecordLocation& location,
216  const void* be_key,
217  KeyLength key_length,
218  const void* payload,
219  PayloadLength payload_offset,
220  PayloadLength payload_count);
221 
223  template <typename PAYLOAD>
225  thread::Thread* context,
226  const RecordLocation& location,
227  const void* be_key,
228  KeyLength key_length,
229  PAYLOAD* value,
230  PayloadLength payload_offset);
231 
235  thread::Thread* context,
236  uint8_t layer,
237  MasstreePage* layer_root);
239  thread::Thread* context,
240  KeySlice low_fence,
241  HighFence high_fence,
244  thread::Thread* context,
245  KeySlice low_fence,
246  HighFence high_fence,
247  MasstreeBorderPage* page);
248 
251  Engine* engine,
252  bool volatile_only,
253  uint32_t max_pages);
255  Engine* engine,
256  cache::SnapshotFileSet* fileset,
257  MasstreePage* parent,
258  bool follow_volatile,
259  uint32_t* remaining_pages);
261  Engine* engine,
262  cache::SnapshotFileSet* fileset,
263  const DualPagePointer& pointer,
264  bool follow_volatile,
265  uint32_t* remaining_pages);
266 
271 
280  thread::Thread* context,
281  bool for_writes,
282  storage::DualPagePointer* pointer,
283  MasstreePage** page);
286  thread::Thread* context,
287  bool for_writes,
288  MasstreeBorderPage* parent,
289  SlotIndex record_index,
290  MasstreePage** page) ALWAYS_INLINE;
291 
294  thread::Thread* context,
295  bool install_volatile,
296  bool cache_snapshot,
297  KeySlice from,
298  KeySlice to);
300  thread::Thread* context,
301  bool install_volatile,
302  bool cache_snapshot,
303  KeySlice from,
304  KeySlice to,
305  MasstreePage* page);
307  thread::Thread* context,
308  DualPagePointer* pointer,
309  bool vol_on,
310  bool snp_on,
311  KeySlice from,
312  KeySlice to);
313 
315  xct::RwLockableXctId* old_address,
317 
320  Engine* engine,
323  const MasstreePage* layer_root,
324  const memory::GlobalVolatilePageResolver& resolver,
327  const MasstreePage* layer_root,
328  const memory::GlobalVolatilePageResolver& resolver,
331  const MasstreeIntermediatePage* cur,
332  const memory::GlobalVolatilePageResolver& resolver,
334 
337  thread::Thread* context,
338  uint32_t desired_count,
339  bool disable_no_record_split);
340  ErrorStack fatify_first_root_double(thread::Thread* context, bool disable_no_record_split);
346  thread::Thread* context,
347  uint32_t* out);
348 
350 };
351 static_assert(sizeof(MasstreeStoragePimpl) <= kPageSize, "MasstreeStoragePimpl is too large");
352 static_assert(
353  sizeof(MasstreeStorageControlBlock) <= soc::GlobalMemoryAnchors::kStorageMemorySize,
354  "MasstreeStorageControlBlock is too large.");
355 } // namespace masstree
356 } // namespace storage
357 } // namespace foedus
358 #endif // FOEDUS_STORAGE_MASSTREE_MASSTREE_STORAGE_PIMPL_HPP_
ErrorCode prefetch_pages_follow(thread::Thread *context, DualPagePointer *pointer, bool vol_on, bool snp_on, KeySlice from, KeySlice to)
ErrorCode peek_volatile_page_boundaries_this_layer(const MasstreePage *layer_root, const memory::GlobalVolatilePageResolver &resolver, const MasstreeStorage::PeekBoundariesArguments &args)
DualPagePointer root_page_pointer_
Points to the root page (or something equivalent).
ErrorCode peek_volatile_page_boundaries(Engine *engine, const MasstreeStorage::PeekBoundariesArguments &args)
Defined in masstree_storage_peek.cpp.
ErrorCode find_border_physical(thread::Thread *context, MasstreePage *layer_root, uint8_t current_layer, bool for_writes, KeySlice slice, MasstreeBorderPage **border) __attribute__((always_inline))
Find a border node in the layer that corresponds to the given key slice.
MasstreeMetadata meta_
metadata of this storage.
Represents a pointer to another page (usually a child page).
Definition: storage_id.hpp:271
The storage has been marked for drop and can't be used.
Definition: storage_id.hpp:164
uint16_t PayloadLength
Represents a byte-length of a payload in this package.
Definition: masstree_id.hpp:92
ErrorCode peek_volatile_page_boundaries_this_layer_recurse(const MasstreeIntermediatePage *cur, const memory::GlobalVolatilePageResolver &resolver, const MasstreeStorage::PeekBoundariesArguments &args)
ErrorStack fatify_first_root(thread::Thread *context, uint32_t desired_count, bool disable_no_record_split)
Defined in masstree_storage_fatify.cpp.
Definitions of IDs in this package and a few related constant values.
uint16_t SlotIndex
Index of a record in a (border) page.
ErrorCode peek_volatile_page_boundaries_next_layer(const MasstreePage *layer_root, const memory::GlobalVolatilePageResolver &resolver, const MasstreeStorage::PeekBoundariesArguments &args)
Forward declarations of classes in log manager package.
ErrorCode reserve_record_normalized(thread::Thread *context, KeySlice key, PayloadLength payload_count, PayloadLength physical_payload_hint, RecordLocation *result)
ErrorCode locate_record_normalized(thread::Thread *context, KeySlice key, bool for_writes, RecordLocation *result)
Identifies page and record for the normalized 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
Represents a record of write-access during a transaction.
Definition: xct_access.hpp:168
Represents one thread running on one NUMA core.
Definition: thread.hpp:48
ErrorCode retrieve_part_general(thread::Thread *context, const RecordLocation &location, void *payload, PayloadLength payload_offset, PayloadLength payload_count)
ErrorCode follow_page(thread::Thread *context, bool for_writes, storage::DualPagePointer *pointer, MasstreePage **page)
Thread::follow_page_pointer() for masstree.
ErrorStack verify_single_thread_border(thread::Thread *context, KeySlice low_fence, HighFence high_fence, MasstreeBorderPage *page)
Result of track_moved_record().
Definition: xct_id.hpp:1180
Represents a pointer to a volatile page with modification count for preventing ABA.
Definition: storage_id.hpp:194
Forward declarations of classes in root package.
Persistent status part of Transaction ID.
Definition: xct_id.hpp:955
Represents one border page in Masstree Storage.
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
ErrorCode prefetch_pages_normalized(thread::Thread *context, bool install_volatile, bool cache_snapshot, KeySlice from, KeySlice to)
defined in masstree_storage_prefetch.cpp
ErrorCode overwrite_general(thread::Thread *context, const RecordLocation &location, const void *be_key, KeyLength key_length, const void *payload, PayloadLength payload_offset, PayloadLength payload_count)
implementation of overwrite_record family.
The storage has been created and ready for use.
Definition: storage_id.hpp:158
uint64_t KeySlice
Each key slice is an 8-byte integer.
Holds a set of read-only file objects for snapshot files.
ErrorCode retrieve_general(thread::Thread *context, const RecordLocation &location, void *payload, PayloadLength *payload_capacity)
implementation of get_record family.
ErrorStack hcc_reset_all_temperature_stat_follow(VolatilePagePointer page_id)
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
Common base of MasstreeIntermediatePage and MasstreeBorderPage.
Forward declarations of classes in cache package.
ErrorStack load(const StorageControlBlock &snapshot_block)
A mutex that can be placed in shared memory and used from multiple processes.
The MCS reader-writer lock variant of LockableXctId.
Definition: xct_id.hpp:1132
ErrorStack fatify_first_root_double(thread::Thread *context, bool disable_no_record_split)
ErrorCode insert_general(thread::Thread *context, const RecordLocation &location, const void *be_key, KeyLength key_length, const void *payload, PayloadLength payload_count)
implementation of insert_record family.
Forward declarations of classes in storage package.
MasstreeStorageControlBlock * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111
Definitions of IDs in this package and a few related constant values.
ErrorCode reserve_record(thread::Thread *context, const void *key, KeyLength key_length, PayloadLength payload_count, PayloadLength physical_payload_hint, RecordLocation *result)
Like locate_record(), this is also a logical operation.
ErrorCode register_record_write_log(thread::Thread *context, const RecordLocation &location, log::RecordLogType *log_entry)
Used in the following methods.
ErrorStack hcc_reset_all_temperature_stat_recurse(MasstreePage *parent)
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
ErrorCode get_first_root(thread::Thread *context, bool for_write, MasstreeIntermediatePage **root)
Root-node related, such as a method to retrieve 1st-root, to grow, etc.
ErrorStack debugout_single_thread_recurse(Engine *engine, cache::SnapshotFileSet *fileset, MasstreePage *parent, bool follow_volatile, uint32_t *remaining_pages)
Attachable Resources on Shared Memory.
Definition: attachable.hpp:58
Used only for debugging as this is not space efficient.
Forward declarations of classes in memory package.
ErrorCode increment_general(thread::Thread *context, const RecordLocation &location, const void *be_key, KeyLength key_length, PAYLOAD *value, PayloadLength payload_offset)
implementation of increment_record family.
ErrorCode prefetch_pages_normalized_recurse(thread::Thread *context, bool install_volatile, bool cache_snapshot, KeySlice from, KeySlice to, MasstreePage *page)
ErrorCode delete_general(thread::Thread *context, const RecordLocation &location, const void *be_key, KeyLength key_length)
implementation of delete_record family.
ErrorCode follow_layer(thread::Thread *context, bool for_writes, MasstreeBorderPage *parent, SlotIndex record_index, MasstreePage **page) __attribute__((always_inline))
Follows to next layer's root page.
ErrorStack hcc_reset_all_temperature_stat()
For stupid reasons (I'm lazy!) these are defined in _debug.cpp.
ErrorStack verify_single_thread(thread::Thread *context)
These are defined in masstree_storage_verify.cpp.
ErrorStack verify_single_thread_intermediate(thread::Thread *context, KeySlice low_fence, HighFence high_fence, MasstreeIntermediatePage *page)
ErrorStack drop()
Storage-wide operations, such as drop, create, etc.
Resolves an offset in a volatile page pool to an actual pointer and vice versa.
ErrorStack create(const MasstreeMetadata &metadata)
Represents one intermediate page in Masstree Storage.
ErrorStack debugout_single_thread_follow(Engine *engine, cache::SnapshotFileSet *fileset, const DualPagePointer &pointer, bool follow_volatile, uint32_t *remaining_pages)
Base class for log type of record-wise operation.
Forward declarations of classes in masstree storage package.
ErrorCode upsert_general(thread::Thread *context, const RecordLocation &location, const void *be_key, KeyLength key_length, const void *payload, PayloadLength payload_count)
implementation of upsert_record family.
#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
MasstreeStorageControlBlock * get_control_block() const
Definition: attachable.hpp:97
return value of MasstreeStoragePimpl::locate_record()/reserve_record().
const uint16_t kPageSize
A constant defining the page size (in bytes) of both snapshot pages and volatile pages.
Definition: storage_id.hpp:45
ErrorStack verify_single_thread_layer(thread::Thread *context, uint8_t layer, MasstreePage *layer_root)
ErrorCode
Enum of error codes defined in error_code.xmacro.
Definition: error_code.hpp:85
static ErrorCode check_next_layer_bit(xct::XctId observed) __attribute__((always_inline))
ErrorCode approximate_count_root_children(thread::Thread *context, uint32_t *out)
Returns the count of direct children in the first-root node.
bool first_root_locked_
Used to synchronize updates to root_page_pointer_.
xct::TrackMovedRecordResult track_moved_record(xct::RwLockableXctId *old_address, xct::WriteXctAccess *write_set) __attribute__((always_inline))
StorageStatus
Status of a storage.
Definition: storage_id.hpp:154
ErrorCode locate_record(thread::Thread *context, const void *key, KeyLength key_length, bool for_writes, RecordLocation *result)
Identifies page and record for the key.
ErrorStack debugout_single_thread(Engine *engine, bool volatile_only, uint32_t max_pages)
These are defined in masstree_storage_debug.cpp.