libfoedus-core
FOEDUS Core Library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sequential_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_SEQUENTIAL_SEQUENTIAL_STORAGE_PIMPL_HPP_
19 #define FOEDUS_STORAGE_SEQUENTIAL_SEQUENTIAL_STORAGE_PIMPL_HPP_
20 #include <stdint.h>
21 
22 #include <atomic>
23 
24 #include "foedus/assert_nd.hpp"
25 #include "foedus/attachable.hpp"
26 #include "foedus/compiler.hpp"
27 #include "foedus/cxx11.hpp"
28 #include "foedus/engine.hpp"
30 #include "foedus/fwd.hpp"
32 #include "foedus/memory/fwd.hpp"
35 #include "foedus/storage/fwd.hpp"
43 #include "foedus/thread/fwd.hpp"
44 
45 namespace foedus {
46 namespace storage {
47 namespace sequential {
50  // this is backed by shared memory. not instantiation. just reinterpret_cast.
53 
54  bool exists() const { return status_ == kExists || status_ == kMarkedForDeath; }
56 
64 
65  // Do NOT reorder members up to here. The layout must be compatible with StorageControlBlock
66  // Type-specific shared members below.
67 
75 
77  std::atomic< Epoch::EpochInteger > cur_truncate_epoch_;
78 
89 };
90 
139 class SequentialStoragePimpl final : public Attachable<SequentialStorageControlBlock> {
140  public:
141  struct PointerPage {
143  };
144  SequentialStoragePimpl() = delete;
147  storage->get_engine(),
148  storage->get_control_block()) {
149  }
151  : Attachable<SequentialStorageControlBlock>(engine, control_block) {
152  }
153 
154  bool exists() const { return control_block_->exists(); }
155  StorageId get_id() const { return control_block_->meta_.id_; }
156  const StorageName& get_name() const { return control_block_->meta_.name_; }
157  ErrorStack create(const SequentialMetadata& metadata);
158  ErrorStack load(const StorageControlBlock& snapshot_block);
160  ErrorStack drop();
161  ErrorStack truncate(Epoch new_truncate_epoch, Epoch* commit_epoch);
162  void apply_truncate(const SequentialTruncateLogType& the_log);
163 
165  const memory::LocalPageResolver& resolver,
166  thread::ThreadId thread_id) const;
168  const memory::LocalPageResolver& resolver,
169  thread::ThreadId thread_id) const;
170 
173 
174 
184  void append_record(
185  thread::Thread* context,
186  xct::XctId owner_id,
187  const void *payload,
188  uint16_t payload_count);
189 
195  template <typename HANDLER>
196  ErrorCode for_every_page(HANDLER handler) const {
197  uint16_t nodes = engine_->get_options().thread_.group_count_;
198  uint16_t threads_per_node = engine_->get_options().thread_.thread_count_per_group_;
199  for (uint16_t node = 0; node < nodes; ++node) {
200  const memory::LocalPageResolver& resolver
202  for (uint16_t local_ordinal = 0; local_ordinal < threads_per_node; ++local_ordinal) {
203  thread::ThreadId thread_id = thread::compose_thread_id(node, local_ordinal);
204  for (SequentialPage* page = get_head(resolver, thread_id); page;) {
205  ASSERT_ND(page->header().page_id_);
206  CHECK_ERROR_CODE(handler(page));
207 
208  VolatilePagePointer next_pointer = page->next_page().volatile_pointer_;
209  memory::PagePoolOffset offset = next_pointer.get_offset();
210  if (offset != 0) {
211  page = reinterpret_cast<SequentialPage*>(resolver.resolve_offset(offset));
212  } else {
213  page = nullptr;
214  }
215  }
216  }
217  }
218  return kErrorCodeOk;
219  }
220 };
221 
222 static_assert(sizeof(SequentialStoragePimpl) <= kPageSize, "SequentialStoragePimpl is too large");
223 static_assert(
224  sizeof(SequentialStorageControlBlock) <= soc::GlobalMemoryAnchors::kStorageMemorySize,
225  "SequentialStorageControlBlock is too large.");
226 } // namespace sequential
227 } // namespace storage
228 } // namespace foedus
229 #endif // FOEDUS_STORAGE_SEQUENTIAL_SEQUENTIAL_STORAGE_PIMPL_HPP_
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
void append_record(thread::Thread *context, xct::XctId owner_id, const void *payload, uint16_t payload_count)
Appends an already-commited record to this volatile list.
Definitions of IDs in this package and a few related constant values.
Lock-free list of records stored in the volatile part of sequential storage.
ErrorStack load(const StorageControlBlock &snapshot_block)
std::atomic< Epoch::EpochInteger > cur_truncate_epoch_
The min epoch value (truncate-epoch) for all valid records in this storage.
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 one thread running on one NUMA core.
Definition: thread.hpp:48
uint32_t PagePoolOffset
Offset in PagePool that compactly represents the page address (unlike 8 bytes pointer).
Definition: memory_id.hpp:44
xct::RwLockableXctId cur_truncate_epoch_tid_
Protects accesses to cur_truncate_epoch_.
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
SequentialPage * get_tail(const memory::LocalPageResolver &resolver, thread::ThreadId thread_id) const
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
Represents a time epoch.
Definition: epoch.hpp:61
Engine * engine_
Most attachable object stores an engine pointer (local engine), so we define it here.
Definition: attachable.hpp:107
The storage has been created and ready for use.
Definition: storage_id.hpp:158
Represents one data page in Sequential Storage.
DualPagePointer root_page_pointer_
Points to the root page (or something equivalent).
const EngineOptions & get_options() const
Definition: engine.cpp:39
ThreadLocalOrdinal thread_count_per_group_
Number of Thread in each ThreadGroup.
A mutex that can be placed in shared memory and used from multiple processes.
VolatilePagePointer tail_pointer_pages_[kPointerPageCount]
Same above, but for tail pointers.
The MCS reader-writer lock variant of LockableXctId.
Definition: xct_id.hpp:1132
Represents an append/scan-only store.
Forward declarations of classes in sequential storage package.
0 means no-error.
Definition: error_code.hpp:87
Forward declarations of classes in storage package.
memory::PagePoolOffset get_offset() const
Definition: storage_id.hpp:202
ErrorStack truncate(Epoch new_truncate_epoch, Epoch *commit_epoch)
ErrorCode optimistic_read_truncate_epoch(thread::Thread *context, Epoch *out) const
SequentialStorageControlBlock * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
void apply_truncate(const SequentialTruncateLogType &the_log)
NumaNodeMemoryRef * get_node_memory(foedus::thread::ThreadGroupId group) const
const uint16_t kPointerPageCount
Each poiner page can contain 2^10 pointers (as the node is implicit, PagePoolOffset suffices) and we ...
Definitions of IDs in this package and a few related constant values.
Attachable Resources on Shared Memory.
Definition: attachable.hpp:58
uint16_t group_count_
Number of ThreadGroup in the engine.
storage::Page * resolve_offset(PagePoolOffset offset) const __attribute__((always_inline))
Resolves offset in this pool to storage::Page*.
ErrorCode for_every_page(HANDLER handler) const
Traverse all pages and call back the handler for every page.
Forward declarations of classes in memory package.
memory::PagePoolOffset * get_head_pointer(thread::ThreadId thread_id) const
ThreadId compose_thread_id(ThreadGroupId node, ThreadLocalOrdinal local_core)
Returns a globally unique ID of Thread (core) for the given node and ordinal in the node...
Definition: thread_id.hpp:123
#define CHECK_ERROR_CODE(x)
This macro calls x and checks its returned error code.
Definition: error_code.hpp:155
thread::ThreadOptions thread_
SequentialPage * get_head(const memory::LocalPageResolver &resolver, thread::ThreadId thread_id) const
uint16_t ThreadId
Typedef for a global ID of Thread (core), which is unique across NUMA nodes.
Definition: thread_id.hpp:80
SequentialStoragePimpl(Engine *engine, SequentialStorageControlBlock *control_block)
Resolves an offset in local (same NUMA node) page pool to a pointer and vice versa.
Log type of TRUNCATE SEQUENTIAL STORAGE operation.
ErrorStack create(const SequentialMetadata &metadata)
const LocalPageResolver & get_resolver() const
Gives an object to resolve an offset in this page pool (thus local) to an actual pointer and vice ver...
Definition: page_pool.cpp:146
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72
Forward declarations of classes in thread package.
A base layout of shared data for all storage types.
Definition: storage.hpp:53
SequentialStorageControlBlock * get_control_block() const
Definition: attachable.hpp:97
VolatilePagePointer head_pointer_pages_[kPointerPageCount]
Points to pages that store thread-private head pages to store thread-private volatile pages...
memory::EngineMemory * get_memory_manager() const
See Memory Manager.
Definition: engine.cpp:50
const uint16_t kPageSize
A constant defining the page size (in bytes) of both snapshot pages and volatile pages.
Definition: storage_id.hpp:45
ErrorCode
Enum of error codes defined in error_code.xmacro.
Definition: error_code.hpp:85
memory::PagePoolOffset * get_tail_pointer(thread::ThreadId thread_id) const
StorageStatus
Status of a storage.
Definition: storage_id.hpp:154