libfoedus-core
FOEDUS Core Library
foedus::storage::StorageManagerPimpl Class Referencefinal

Pimpl object of StorageManager. More...

Detailed Description

Pimpl object of StorageManager.

A private pimpl object for StorageManager. Do not include this header from a client program unless you know what you are doing.

Definition at line 73 of file storage_manager_pimpl.hpp.

#include <storage_manager_pimpl.hpp>

Inheritance diagram for foedus::storage::StorageManagerPimpl:
Collaboration diagram for foedus::storage::StorageManagerPimpl:

Public Member Functions

 StorageManagerPimpl ()=delete
 
 StorageManagerPimpl (Engine *engine)
 
ErrorStack initialize_once () override
 
ErrorStack initialize_read_latest_snapshot ()
 
ErrorStack uninitialize_once () override
 
ErrorStack reinitialize_for_recovered_snapshot ()
 Special method called only from recovery manager. More...
 
StorageId issue_next_storage_id ()
 
StorageControlBlockget_storage (StorageId id)
 
StorageControlBlockget_storage (const StorageName &name)
 
bool exists (const StorageName &name)
 
ErrorStack drop_storage (StorageId id, Epoch *commit_epoch)
 
void drop_storage_apply (StorageId id)
 
ErrorStack create_storage (Metadata *metadata, Epoch *commit_epoch)
 
void create_storage_apply (const Metadata &metadata)
 
template<typename STORAGE >
ErrorStack create_storage_and_log (const Metadata *meta, Epoch *commit_epoch)
 
ErrorStack hcc_reset_all_temperature_stat (StorageId storage_id)
 Resets all volatile pages' temperature stat to be zero in the specified storage. More...
 
xct::TrackMovedRecordResult track_moved_record (StorageId storage_id, xct::RwLockableXctId *old_address, xct::WriteXctAccess *write)
 
ErrorStack clone_all_storage_metadata (snapshot::SnapshotMetadata *metadata)
 
uint32_t get_max_storages () const
 
- Public Member Functions inherited from foedus::DefaultInitializable
 DefaultInitializable ()
 
virtual ~DefaultInitializable ()
 
 DefaultInitializable (const DefaultInitializable &)=delete
 
DefaultInitializableoperator= (const DefaultInitializable &)=delete
 
ErrorStack initialize () override final
 Typical implementation of Initializable::initialize() that provides initialize-once semantics. More...
 
ErrorStack uninitialize () override final
 Typical implementation of Initializable::uninitialize() that provides uninitialize-once semantics. More...
 
bool is_initialized () const override final
 Returns whether the object has been already initialized or not. More...
 
- Public Member Functions inherited from foedus::Initializable
virtual ~Initializable ()
 

Public Attributes

Engine *const engine_
 
StorageManagerControlBlockcontrol_block_
 
StorageControlBlockstorages_
 Storage instances (pimpl objects) are allocated in this shared memory. More...
 
storage::StorageIdstorage_name_sort_
 This shared memory stores the ID of storages sorted by their names. More...
 

Constructor & Destructor Documentation

foedus::storage::StorageManagerPimpl::StorageManagerPimpl ( )
delete
foedus::storage::StorageManagerPimpl::StorageManagerPimpl ( Engine engine)
inlineexplicit

Definition at line 76 of file storage_manager_pimpl.hpp.

Member Function Documentation

ErrorStack foedus::storage::StorageManagerPimpl::clone_all_storage_metadata ( snapshot::SnapshotMetadata metadata)

Definition at line 470 of file storage_manager_pimpl.cpp.

References foedus::memory::AlignedMemory::alloc(), foedus::debugging::StopWatch::elapsed_ms(), foedus::memory::AlignedMemory::get_block(), foedus::memory::AlignedMemory::kNumaAllocOnnode, foedus::kRetOk, foedus::soc::GlobalMemoryAnchors::kStorageMemorySize, foedus::snapshot::SnapshotMetadata::largest_storage_id_, foedus::assorted::memory_fence_acq_rel(), foedus::debugging::StopWatch::stop(), foedus::snapshot::SnapshotMetadata::storage_control_blocks_, foedus::snapshot::SnapshotMetadata::storage_control_blocks_memory_, and storages_.

Referenced by foedus::storage::StorageManager::clone_all_storage_metadata().

471  {
472  debugging::StopWatch stop_watch;
474 
475  // not just the metadata, just copy the whole control block.
476  // this is a single memcpy, which should be much more efficient.
477  uint64_t memory_size
478  = static_cast<uint64_t>(metadata->largest_storage_id_ + 1)
480  metadata->storage_control_blocks_memory_.alloc(
481  memory_size,
482  1 << 12,
484  0);
485  metadata->storage_control_blocks_ = reinterpret_cast<storage::StorageControlBlock*>(
486  metadata->storage_control_blocks_memory_.get_block());
487  std::memcpy(metadata->storage_control_blocks_, storages_, memory_size);
488 
489  stop_watch.stop();
490  LOG(INFO) << "Duplicated metadata of " << metadata->largest_storage_id_
491  << " storages in " << stop_watch.elapsed_ms() << " milliseconds";
492  return kRetOk;
493 }
StorageControlBlock * storages_
Storage instances (pimpl objects) are allocated in this shared memory.
numa_alloc_onnode() and numa_free().
const ErrorStack kRetOk
Normal return value for no-error case.
void memory_fence_acq_rel()
Equivalent to std::atomic_thread_fence(std::memory_order_acq_rel).

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::storage::StorageManagerPimpl::create_storage ( Metadata metadata,
Epoch commit_epoch 
)

Definition at line 352 of file storage_manager_pimpl.cpp.

References ASSERT_ND, CHECK_ERROR, foedus::assorted::FixedString< MAXLEN, CHAR >::empty(), ERROR_STACK, exists(), get_max_storages(), get_storage(), foedus::storage::Metadata::id_, foedus::storage::StorageControlBlock::initialize(), foedus::INVALID_EPOCH, foedus::Epoch::is_valid(), issue_next_storage_id(), foedus::storage::kArrayStorage, foedus::kErrorCodeStrDuplicateStrname, foedus::kErrorCodeStrEmptyName, foedus::kErrorCodeStrTooManyStorages, foedus::storage::kHashStorage, foedus::storage::kMasstreeStorage, foedus::kRetOk, foedus::storage::kSequentialStorage, foedus::storage::StorageControlBlock::meta_, foedus::storage::Metadata::name_, storages_, foedus::storage::Metadata::type_, and foedus::assorted::FixedString< MAXLEN, CHAR >::zero_fill_remaining().

Referenced by foedus::storage::StorageManager::create_storage().

352  {
353  *commit_epoch = INVALID_EPOCH;
355  if (id >= get_max_storages()) {
357  }
358  if (metadata->name_.empty()) {
360  }
361  metadata->id_ = id;
362 
363  const StorageName& name = metadata->name_;
364  if (exists(name)) {
365  LOG(ERROR) << "This storage name already exists: " << name;
367  }
368 
369  get_storage(id)->initialize();
370  ASSERT_ND(!get_storage(id)->exists());
371  storages_[id].meta_.type_ = metadata->type_;
372 
373  metadata->name_.zero_fill_remaining(); // make valgrind overload happy.
374  ErrorStack result;
375  if (metadata->type_ == kArrayStorage) {
376  result = create_storage_and_log< array::ArrayStorage >(metadata, commit_epoch);
377  } else if (metadata->type_ == kHashStorage) {
378  result = create_storage_and_log< hash::HashStorage >(metadata, commit_epoch);
379  } else if (metadata->type_ == kMasstreeStorage) {
380  result = create_storage_and_log< masstree::MasstreeStorage >(metadata, commit_epoch);
381  } else if (metadata->type_ == kSequentialStorage) {
382  result = create_storage_and_log< sequential::SequentialStorage >(metadata, commit_epoch);
383  } else {
384  LOG(FATAL) << "WTF:" << metadata->type_;
385  }
386  CHECK_ERROR(result);
387 
388  ASSERT_ND(commit_epoch->is_valid());
389  ASSERT_ND(get_storage(id)->exists());
390  return kRetOk;
391 }
StorageControlBlock * storages_
Storage instances (pimpl objects) are allocated in this shared memory.
0x0803 : "STORAGE: This Storage Name already exists" .
Definition: error_code.hpp:169
Metadata meta_
common part of the metadata.
Definition: storage.hpp:84
#define ERROR_STACK(e)
Instantiates ErrorStack with the given foedus::error_code, creating an error stack with the current f...
uint32_t StorageId
Unique ID for storage.
Definition: storage_id.hpp:55
StorageControlBlock * get_storage(StorageId id)
assorted::FixedString< 60 > StorageName
Represents a unique name of a storage.
Definition: storage_id.hpp:58
0x0824 : "STORAGE: Storage name is empty" .
Definition: error_code.hpp:187
0x0822 : "STORAGE: Reached maximum number of storages. To register more storages, adjust StorageOptio...
Definition: error_code.hpp:185
StorageType type_
type of the storage.
Definition: metadata.hpp:105
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
const Epoch INVALID_EPOCH
A constant epoch object that represents an invalid epoch.
Definition: epoch.hpp:204
const ErrorStack kRetOk
Normal return value for no-error case.
#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

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename STORAGE >
ErrorStack foedus::storage::StorageManagerPimpl::create_storage_and_log ( const Metadata meta,
Epoch commit_epoch 
)

Definition at line 321 of file storage_manager_pimpl.cpp.

References ASSERT_ND, CHECK_ERROR, foedus::log::MetaLogBuffer::commit(), engine_, foedus::storage::StorageControlBlock::exists(), foedus::Engine::get_log_manager(), foedus::log::LogManager::get_meta_buffer(), foedus::storage::Metadata::id_, foedus::kRetOk, foedus::storage::Metadata::name_, storages_, and foedus::storage::Metadata::type_.

321  {
322  typedef typename STORAGE::ThisMetadata TheMetadata;
323  typedef typename STORAGE::ThisCreateLogType TheLogType;
324 
325  StorageId id = meta->id_;
326  StorageControlBlock* block = storages_ + id;
327  STORAGE storage(engine_, block);
328  const TheMetadata* casted_meta = reinterpret_cast< const TheMetadata *>(meta);
329  ASSERT_ND(!block->exists());
330  CHECK_ERROR(storage.create(*casted_meta));
331  ASSERT_ND(block->exists());
332 
333  if (commit_epoch) {
334  // if commit_epoch is null, it means "apply-only" mode in restart. do not log then
335  char log_buffer[sizeof(TheLogType)];
336  std::memset(log_buffer, 0, sizeof(log_buffer));
337  TheLogType* create_log = reinterpret_cast<TheLogType*>(log_buffer);
338  create_log->header_.storage_id_ = id;
339  create_log->header_.log_type_code_ = log::get_log_code<TheLogType>();
340  create_log->header_.log_length_ = sizeof(TheLogType);
341  create_log->metadata_ = *casted_meta;
342  ASSERT_ND(create_log->header_.storage_id_ == id);
343  ASSERT_ND(create_log->metadata_.id_ == id);
344  ASSERT_ND(create_log->metadata_.type_ == meta->type_);
345  ASSERT_ND(create_log->metadata_.name_ == meta->name_);
346 
347  engine_->get_log_manager()->get_meta_buffer()->commit(create_log, commit_epoch);
348  }
349  return kRetOk;
350 }
StorageControlBlock * storages_
Storage instances (pimpl objects) are allocated in this shared memory.
MetaLogBuffer * get_meta_buffer()
Definition: log_manager.cpp:61
uint32_t StorageId
Unique ID for storage.
Definition: storage_id.hpp:55
log::LogManager * get_log_manager() const
See Log Manager.
Definition: engine.cpp:49
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
void commit(BaseLogType *metalog, Epoch *commit_epoch)
Synchronously writes out the given log to metadata log file.
const ErrorStack kRetOk
Normal return value for no-error case.
#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

Here is the call graph for this function:

void foedus::storage::StorageManagerPimpl::create_storage_apply ( const Metadata metadata)

Definition at line 393 of file storage_manager_pimpl.cpp.

References ASSERT_ND, control_block_, foedus::assorted::FixedString< MAXLEN, CHAR >::empty(), exists(), get_storage(), foedus::storage::Metadata::id_, foedus::storage::StorageControlBlock::initialize(), foedus::ErrorStack::is_error(), foedus::storage::kArrayStorage, foedus::storage::kHashStorage, foedus::storage::kMasstreeStorage, foedus::storage::kSequentialStorage, foedus::storage::StorageManagerControlBlock::largest_storage_id_, foedus::storage::StorageControlBlock::meta_, foedus::storage::Metadata::name_, storages_, and foedus::storage::Metadata::type_.

Referenced by foedus::storage::StorageManager::create_storage_apply().

393  {
394  // this method is called only while restart, so no race.
395  ASSERT_ND(metadata.id_ > 0);
396  ASSERT_ND(!metadata.name_.empty());
397  StorageId id = metadata.id_;
400  }
401 
402  ASSERT_ND(!exists(metadata.name_));
403 
404  get_storage(id)->initialize();
405  ASSERT_ND(!get_storage(id)->exists());
406  storages_[id].meta_.type_ = metadata.type_;
407  ErrorStack result;
408  if (metadata.type_ == kArrayStorage) {
409  result = create_storage_and_log< array::ArrayStorage >(&metadata, nullptr);
410  } else if (metadata.type_ == kHashStorage) {
411  result = create_storage_and_log< hash::HashStorage >(&metadata, nullptr);
412  } else if (metadata.type_ == kMasstreeStorage) {
413  result = create_storage_and_log< masstree::MasstreeStorage >(&metadata, nullptr);
414  } else if (metadata.type_ == kSequentialStorage) {
415  result = create_storage_and_log< sequential::SequentialStorage >(&metadata, nullptr);
416  } else {
417  LOG(FATAL) << "WTF:" << metadata.type_;
418  }
419  if (result.is_error()) {
420  LOG(FATAL) << "create_storage_apply() failed. " << result
421  << " Failed to restart the engine";
422  }
423 
424  ASSERT_ND(get_storage(id)->exists());
425 }
StorageControlBlock * storages_
Storage instances (pimpl objects) are allocated in this shared memory.
Metadata meta_
common part of the metadata.
Definition: storage.hpp:84
uint32_t StorageId
Unique ID for storage.
Definition: storage_id.hpp:55
StorageManagerControlBlock * control_block_
StorageId largest_storage_id_
The largest StorageId we so far observed.
StorageControlBlock * get_storage(StorageId id)
StorageType type_
type of the storage.
Definition: metadata.hpp:105
#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

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::storage::StorageManagerPimpl::drop_storage ( StorageId  id,
Epoch commit_epoch 
)

Definition at line 264 of file storage_manager_pimpl.cpp.

References ASSERT_ND, CHECK_ERROR, foedus::log::MetaLogBuffer::commit(), engine_, ERROR_STACK, foedus::storage::StorageControlBlock::exists(), foedus::Engine::get_log_manager(), foedus::log::LogManager::get_meta_buffer(), foedus::Epoch::is_valid(), foedus::storage::kArrayStorage, foedus::kErrorCodeStrAlreadyDropped, foedus::storage::kHashStorage, foedus::storage::kMarkedForDeath, foedus::storage::kMasstreeStorage, foedus::kRetOk, foedus::storage::kSequentialStorage, foedus::storage::StorageControlBlock::meta_, foedus::storage::Metadata::name_, foedus::storage::DropLogType::populate(), foedus::storage::StorageControlBlock::status_, storages_, foedus::storage::Metadata::type_, and foedus::storage::StorageControlBlock::uninitialize().

Referenced by foedus::storage::StorageManager::drop_storage().

264  {
265  StorageControlBlock* block = storages_ + id;
266  if (!block->exists()) {
267  LOG(ERROR) << "This storage ID does not exist or has been already dropped: " << id;
269  }
270 
271  StorageName name = block->meta_.name_;
272  LOG(INFO) << "Dropping storage " << id << "(" << name << ")";
273  StorageType type = block->meta_.type_;
274  if (type == kArrayStorage) {
275  CHECK_ERROR(array::ArrayStorage(engine_, block).drop());
276  } else if (type == kHashStorage) {
277  CHECK_ERROR(hash::HashStorage(engine_, block).drop());
278  } else if (type == kMasstreeStorage) {
279  CHECK_ERROR(masstree::MasstreeStorage(engine_, block).drop());
280  } else if (type == kSequentialStorage) {
281  CHECK_ERROR(sequential::SequentialStorage(engine_, block).drop());
282  } else {
283  LOG(FATAL) << "WTF:" << type;
284  }
285 
286  char log_buffer[1 << 12];
287  std::memset(log_buffer, 0, sizeof(log_buffer));
288  DropLogType* drop_log = reinterpret_cast<DropLogType*>(log_buffer);
289  drop_log->populate(id);
290  engine_->get_log_manager()->get_meta_buffer()->commit(drop_log, commit_epoch);
291 
292  ASSERT_ND(commit_epoch->is_valid());
293  block->status_ = kMarkedForDeath;
294  ASSERT_ND(!block->exists());
295  block->uninitialize();
296  LOG(INFO) << "Dropped storage " << id << "(" << name << ")";
297  return kRetOk;
298 }
StorageControlBlock * storages_
Storage instances (pimpl objects) are allocated in this shared memory.
MetaLogBuffer * get_meta_buffer()
Definition: log_manager.cpp:61
The storage has been marked for drop and can't be used.
Definition: storage_id.hpp:164
#define ERROR_STACK(e)
Instantiates ErrorStack with the given foedus::error_code, creating an error stack with the current f...
0x0823 : "STORAGE: This storage does not exist or has been already dropped" .
Definition: error_code.hpp:186
log::LogManager * get_log_manager() const
See Log Manager.
Definition: engine.cpp:49
assorted::FixedString< 60 > StorageName
Represents a unique name of a storage.
Definition: storage_id.hpp:58
StorageType
Type of the storage, such as hash.
Definition: storage_id.hpp:122
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
void commit(BaseLogType *metalog, Epoch *commit_epoch)
Synchronously writes out the given log to metadata log file.
const ErrorStack kRetOk
Normal return value for no-error case.
#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

Here is the call graph for this function:

Here is the caller graph for this function:

void foedus::storage::StorageManagerPimpl::drop_storage_apply ( StorageId  id)

Definition at line 300 of file storage_manager_pimpl.cpp.

References ASSERT_ND, COERCE_ERROR, engine_, foedus::storage::StorageControlBlock::exists(), foedus::storage::kArrayStorage, foedus::storage::kHashStorage, foedus::storage::kMarkedForDeath, foedus::storage::kMasstreeStorage, foedus::storage::kSequentialStorage, foedus::storage::StorageControlBlock::meta_, foedus::storage::StorageControlBlock::status_, storages_, foedus::storage::Metadata::type_, and foedus::storage::StorageControlBlock::uninitialize().

Referenced by foedus::storage::StorageManager::drop_storage_apply(), and uninitialize_once().

300  {
301  StorageControlBlock* block = storages_ + id;
302  ASSERT_ND(block->exists());
303  StorageType type = block->meta_.type_;
304  if (type == kArrayStorage) {
305  COERCE_ERROR(array::ArrayStorage(engine_, block).drop());
306  } else if (type == kHashStorage) {
307  COERCE_ERROR(hash::HashStorage(engine_, block).drop());
308  } else if (type == kMasstreeStorage) {
309  COERCE_ERROR(masstree::MasstreeStorage(engine_, block).drop());
310  } else if (type == kSequentialStorage) {
311  COERCE_ERROR(sequential::SequentialStorage(engine_, block).drop());
312  } else {
313  LOG(FATAL) << "WTF:" << type;
314  }
315  block->status_ = kMarkedForDeath;
316  ASSERT_ND(!block->exists());
317  block->uninitialize();
318 }
StorageControlBlock * storages_
Storage instances (pimpl objects) are allocated in this shared memory.
The storage has been marked for drop and can't be used.
Definition: storage_id.hpp:164
#define COERCE_ERROR(x)
This macro calls x and aborts if encounters an error.
StorageType
Type of the storage, such as hash.
Definition: storage_id.hpp:122
#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

Here is the call graph for this function:

Here is the caller graph for this function:

bool foedus::storage::StorageManagerPimpl::exists ( const StorageName name)

Definition at line 253 of file storage_manager_pimpl.cpp.

References control_block_, foedus::storage::StorageManagerControlBlock::largest_storage_id_, foedus::storage::StorageManagerControlBlock::mod_lock_, and storages_.

Referenced by create_storage(), create_storage_apply(), initialize_read_latest_snapshot(), and uninitialize_once().

253  {
254  soc::SharedMutexScope guard(&control_block_->mod_lock_);
255  // TASK(Hideaki) so far sequential search
256  for (uint32_t i = 0; i <= control_block_->largest_storage_id_; ++i) {
257  if (storages_[i].meta_.name_ == name) {
258  return true;
259  }
260  }
261  return false;
262 }
StorageControlBlock * storages_
Storage instances (pimpl objects) are allocated in this shared memory.
StorageManagerControlBlock * control_block_
StorageId largest_storage_id_
The largest StorageId we so far observed.
soc::SharedMutex mod_lock_
In case there are multiple threads that add/delete/expand storages, those threads take this lock...

Here is the caller graph for this function:

uint32_t foedus::storage::StorageManagerPimpl::get_max_storages ( ) const

Definition at line 65 of file storage_manager_pimpl.cpp.

References engine_, foedus::Engine::get_options(), foedus::storage::StorageOptions::max_storages_, and foedus::EngineOptions::storage_.

Referenced by create_storage().

65  {
67 }
const EngineOptions & get_options() const
Definition: engine.cpp:39
uint32_t max_storages_
Maximum number of storages in this database.
storage::StorageOptions storage_

Here is the call graph for this function:

Here is the caller graph for this function:

StorageControlBlock* foedus::storage::StorageManagerPimpl::get_storage ( StorageId  id)
inline

Definition at line 93 of file storage_manager_pimpl.hpp.

References storages_.

Referenced by create_storage(), create_storage_apply(), foedus::storage::StorageManager::get_storage(), and initialize_read_latest_snapshot().

93 { return &storages_[id]; }
StorageControlBlock * storages_
Storage instances (pimpl objects) are allocated in this shared memory.

Here is the caller graph for this function:

StorageControlBlock * foedus::storage::StorageManagerPimpl::get_storage ( const StorageName name)

Definition at line 242 of file storage_manager_pimpl.cpp.

References control_block_, foedus::storage::StorageManagerControlBlock::largest_storage_id_, foedus::storage::StorageManagerControlBlock::mod_lock_, and storages_.

242  {
243  soc::SharedMutexScope guard(&control_block_->mod_lock_);
244  // TASK(Hideaki) so far sequential search
245  for (uint32_t i = 0; i <= control_block_->largest_storage_id_; ++i) {
246  if (storages_[i].meta_.name_ == name) {
247  return &storages_[i];
248  }
249  }
250  LOG(WARNING) << "Requested storage name '" << name << "' was not found";
251  return &storages_[0]; // storage ID 0 is always not-initialized
252 }
StorageControlBlock * storages_
Storage instances (pimpl objects) are allocated in this shared memory.
StorageManagerControlBlock * control_block_
StorageId largest_storage_id_
The largest StorageId we so far observed.
soc::SharedMutex mod_lock_
In case there are multiple threads that add/delete/expand storages, those threads take this lock...
ErrorStack foedus::storage::StorageManagerPimpl::hcc_reset_all_temperature_stat ( StorageId  storage_id)

Resets all volatile pages' temperature stat to be zero in the specified storage.

Used only in HCC-branch.

Definition at line 427 of file storage_manager_pimpl.cpp.

References ASSERT_ND, CHECK_ERROR, engine_, foedus::storage::StorageControlBlock::exists(), foedus::storage::kArrayStorage, foedus::storage::kHashStorage, foedus::storage::kMasstreeStorage, foedus::kRetOk, foedus::storage::StorageControlBlock::meta_, storages_, and foedus::storage::Metadata::type_.

427  {
428  StorageControlBlock* block = storages_ + storage_id;
429  ASSERT_ND(block->exists());
430  StorageType type = block->meta_.type_;
431  if (type == kMasstreeStorage) {
432  CHECK_ERROR(masstree::MasstreeStorage(engine_, block).hcc_reset_all_temperature_stat());
433  } else if (type == kHashStorage) {
434  CHECK_ERROR(hash::HashStorage(engine_, block).hcc_reset_all_temperature_stat());
435  } else if (type == kArrayStorage) {
436  CHECK_ERROR(array::ArrayStorage(engine_, block).hcc_reset_all_temperature_stat());
437  } else {
438  // Seq storage doesn't need it.
439  LOG(WARNING) << "This storage type doesn't need HCC counter reset. type=" << type;
440  }
441  return kRetOk;
442 }
StorageControlBlock * storages_
Storage instances (pimpl objects) are allocated in this shared memory.
StorageType
Type of the storage, such as hash.
Definition: storage_id.hpp:122
ErrorStack hcc_reset_all_temperature_stat(StorageId storage_id)
Resets all volatile pages' temperature stat to be zero in the specified storage.
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
const ErrorStack kRetOk
Normal return value for no-error case.
#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

Here is the call graph for this function:

ErrorStack foedus::storage::StorageManagerPimpl::initialize_once ( )
overridevirtual

Implements foedus::DefaultInitializable.

Definition at line 69 of file storage_manager_pimpl.cpp.

References CHECK_ERROR, control_block_, engine_, ERROR_STACK, foedus::soc::SharedMemoryRepo::get_global_memory_anchors(), foedus::Engine::get_log_manager(), foedus::soc::SocManager::get_shared_memory_repo(), foedus::Engine::get_soc_manager(), foedus::Engine::get_thread_pool(), foedus::storage::StorageManagerControlBlock::initialize(), initialize_read_latest_snapshot(), foedus::log::LogManager::is_initialized(), foedus::thread::ThreadPool::is_initialized(), foedus::Engine::is_master(), foedus::kErrorCodeDepedentModuleUnavailableInit, foedus::kRetOk, foedus::storage::StorageManagerControlBlock::largest_storage_id_, foedus::soc::GlobalMemoryAnchors::storage_manager_memory_, foedus::soc::GlobalMemoryAnchors::storage_memories_, storage_name_sort_, foedus::soc::GlobalMemoryAnchors::storage_name_sort_memory_, and storages_.

69  {
70  LOG(INFO) << "Initializing StorageManager..";
74  }
75 
76  // attach shared memories
77  soc::GlobalMemoryAnchors* anchors
79  control_block_ = anchors->storage_manager_memory_;
80  storages_ = anchors->storage_memories_;
81  storage_name_sort_ = anchors->storage_name_sort_memory_;
82 
83  if (engine_->is_master()) {
84  // initialize the shared memory. only on master engine
87 
88  // Then, initialize storages with latest snapshot
90  }
91  return kRetOk;
92 }
StorageControlBlock * storages_
Storage instances (pimpl objects) are allocated in this shared memory.
#define ERROR_STACK(e)
Instantiates ErrorStack with the given foedus::error_code, creating an error stack with the current f...
GlobalMemoryAnchors * get_global_memory_anchors()
bool is_initialized() const override
Returns whether the object has been already initialized or not.
Definition: log_manager.cpp:32
0x0005 : "GENERAL: A dependent module is not initialized yet. This implies a wrong initialization ord...
Definition: error_code.hpp:109
StorageManagerControlBlock * control_block_
StorageId largest_storage_id_
The largest StorageId we so far observed.
bool is_master() const
Returns if this engine object is a master instance.
Definition: engine.cpp:68
bool is_initialized() const override
Returns whether the object has been already initialized or not.
Definition: thread_pool.cpp:37
log::LogManager * get_log_manager() const
See Log Manager.
Definition: engine.cpp:49
storage::StorageId * storage_name_sort_
This shared memory stores the ID of storages sorted by their names.
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
const ErrorStack kRetOk
Normal return value for no-error case.
soc::SocManager * get_soc_manager() const
See SOC and IPC.
Definition: engine.cpp:59
thread::ThreadPool * get_thread_pool() const
See Thread and Thread-Group.
Definition: engine.cpp:52
SharedMemoryRepo * get_shared_memory_repo()
Returns the shared memories maintained across SOCs.
Definition: soc_manager.cpp:38

Here is the call graph for this function:

ErrorStack foedus::storage::StorageManagerPimpl::initialize_read_latest_snapshot ( )

Definition at line 94 of file storage_manager_pimpl.cpp.

References ASSERT_ND, CHECK_ERROR, foedus::storage::VolatilePagePointer::clear(), control_block_, foedus::debugging::StopWatch::elapsed_ms(), foedus::assorted::FixedString< MAXLEN, CHAR >::empty(), engine_, ERROR_STACK, exists(), foedus::savepoint::SavepointManager::get_latest_snapshot_id(), foedus::Engine::get_savepoint_manager(), foedus::Engine::get_snapshot_manager(), get_storage(), foedus::storage::Metadata::id_, foedus::storage::StorageControlBlock::initialize(), foedus::Engine::is_master(), foedus::storage::kArrayStorage, foedus::kErrorCodeStrUnsupportedMetadata, foedus::storage::kExists, foedus::storage::kHashStorage, foedus::storage::kMasstreeStorage, foedus::storage::kNotExists, foedus::snapshot::kNullSnapshotId, foedus::kRetOk, foedus::storage::kSequentialStorage, foedus::storage::StorageManagerControlBlock::largest_storage_id_, foedus::snapshot::SnapshotMetadata::largest_storage_id_, foedus::storage::StorageControlBlock::meta_, foedus::storage::Metadata::name_, foedus::snapshot::SnapshotManager::read_snapshot_metadata(), foedus::storage::StorageControlBlock::root_page_pointer_, foedus::storage::Metadata::root_snapshot_page_id_, foedus::storage::DualPagePointer::snapshot_pointer_, foedus::storage::StorageControlBlock::status_, foedus::debugging::StopWatch::stop(), foedus::snapshot::SnapshotMetadata::storage_control_blocks_, storages_, foedus::storage::Metadata::type_, and foedus::storage::DualPagePointer::volatile_pointer_.

Referenced by initialize_once().

94  {
96  LOG(INFO) << "Initializing list of storages with latest snapshot file...";
98  if (snapshot_id == snapshot::kNullSnapshotId) {
99  LOG(INFO) << "There was no previous snapshot. start from empty storages";
100  return kRetOk;
101  }
102 
103  snapshot::SnapshotMetadata metadata;
104  CHECK_ERROR(engine_->get_snapshot_manager()->read_snapshot_metadata(snapshot_id, &metadata));
105  LOG(INFO) << "Latest snapshot contains " << metadata.largest_storage_id_ << " storages";
106  control_block_->largest_storage_id_ = metadata.largest_storage_id_;
107 
108  debugging::StopWatch stop_watch;
109  uint32_t active_storages = 0;
110  for (uint32_t id = 1; id <= control_block_->largest_storage_id_; ++id) {
111  StorageControlBlock* block = storages_ + id;
112  const StorageControlBlock& snapshot_block = metadata.storage_control_blocks_[id];
113  if (snapshot_block.status_ != kExists) {
114  VLOG(0) << "Storage-" << id << " is a dropped storage.";
115  block->status_ = kNotExists;
116  } else {
117  VLOG(0) << "Storage-" << id << " exists in the snapshot.";
118  ASSERT_ND(snapshot_block.meta_.id_ == id);
119  ASSERT_ND(!snapshot_block.meta_.name_.empty());
120  ASSERT_ND(!exists(snapshot_block.meta_.name_));
121  block->initialize();
122  block->root_page_pointer_.snapshot_pointer_ = snapshot_block.meta_.root_snapshot_page_id_;
123  block->root_page_pointer_.volatile_pointer_.clear();
124 
125  block->meta_.type_ = snapshot_block.meta_.type_;
126  switch (snapshot_block.meta_.type_) {
127  case kArrayStorage:
128  CHECK_ERROR(array::ArrayStorage(engine_, block).load(snapshot_block));
129  break;
130  case kHashStorage:
131  CHECK_ERROR(hash::HashStorage(engine_, block).load(snapshot_block));
132  break;
133  case kMasstreeStorage:
134  CHECK_ERROR(masstree::MasstreeStorage(engine_, block).load(snapshot_block));
135  break;
136  case kSequentialStorage:
137  CHECK_ERROR(sequential::SequentialStorage(engine_, block).load(snapshot_block));
138  break;
139  default:
141  }
142 
143  ASSERT_ND(get_storage(id)->exists());
144 
145  ++active_storages;
146  }
147  }
148  stop_watch.stop();
149  LOG(INFO) << "Found " << active_storages
150  << " active storages in " << stop_watch.elapsed_ms() << " milliseconds";
151  return kRetOk;
152 }
StorageControlBlock * storages_
Storage instances (pimpl objects) are allocated in this shared memory.
snapshot::SnapshotId get_latest_snapshot_id() const
#define ERROR_STACK(e)
Instantiates ErrorStack with the given foedus::error_code, creating an error stack with the current f...
StorageManagerControlBlock * control_block_
StorageId largest_storage_id_
The largest StorageId we so far observed.
The storage has been created and ready for use.
Definition: storage_id.hpp:158
ErrorStack read_snapshot_metadata(SnapshotId snapshot_id, SnapshotMetadata *out)
Read the snapshot metadata file that contains storages as of the snapshot.
bool is_master() const
Returns if this engine object is a master instance.
Definition: engine.cpp:68
savepoint::SavepointManager * get_savepoint_manager() const
See Savepoint Manager.
Definition: engine.cpp:53
StorageControlBlock * get_storage(StorageId id)
uint16_t SnapshotId
Unique ID of Snapshot.
Definition: snapshot_id.hpp:43
const SnapshotId kNullSnapshotId
Definition: snapshot_id.hpp:45
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
const ErrorStack kRetOk
Normal return value for no-error case.
Initial state, which means the storage has not been created yet.
Definition: storage_id.hpp:156
0x0807 : "STORAGE: This metadata type is not yet supported" .
Definition: error_code.hpp:173
snapshot::SnapshotManager * get_snapshot_manager() const
See Snapshot Manager.
Definition: engine.cpp:56
#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
StorageStatus status_
Status of the storage.
Definition: storage.hpp:80

Here is the call graph for this function:

Here is the caller graph for this function:

StorageId foedus::storage::StorageManagerPimpl::issue_next_storage_id ( )

Definition at line 235 of file storage_manager_pimpl.cpp.

References control_block_, foedus::storage::StorageManagerControlBlock::largest_storage_id_, and foedus::storage::StorageManagerControlBlock::mod_lock_.

Referenced by create_storage(), and foedus::storage::StorageManager::issue_next_storage_id().

235  {
236  soc::SharedMutexScope guard(&control_block_->mod_lock_); // implies fence too
238  LOG(INFO) << "Incremented largest_storage_id_: " << control_block_->largest_storage_id_;
240 }
StorageManagerControlBlock * control_block_
StorageId largest_storage_id_
The largest StorageId we so far observed.
soc::SharedMutex mod_lock_
In case there are multiple threads that add/delete/expand storages, those threads take this lock...

Here is the caller graph for this function:

ErrorStack foedus::storage::StorageManagerPimpl::reinitialize_for_recovered_snapshot ( )

Special method called only from recovery manager.

1) initialize_once(), which calls initialize_read_latest_snapshot(). 2) if there are non-snapshotted and durable logs, recovery manager triggers snapshotting 3) then, reinitialize only root pages with this method.

Unlike usual snapshot, we can assume that there is no concurrent worker, so we can safely drop volatile root pages and re-create them with the new snapshot pages.

Definition at line 157 of file storage_manager_pimpl.cpp.

References ASSERT_ND, CHECK_ERROR, control_block_, foedus::debugging::StopWatch::elapsed_ms(), engine_, foedus::storage::StorageControlBlock::exists(), foedus::memory::EngineMemory::get_global_volatile_page_resolver(), foedus::storage::Page::get_header(), foedus::Engine::get_memory_manager(), foedus::storage::Page::get_snapshot_page_id(), foedus::storage::Page::get_volatile_page_id(), foedus::DefaultInitializable::initialize(), foedus::storage::VolatilePagePointer::is_null(), foedus::kRetOk, foedus::UninitializeGuard::kWarnIfUninitializeError, foedus::storage::StorageManagerControlBlock::largest_storage_id_, foedus::storage::PageHeader::page_id_, foedus::cache::SnapshotFileSet::read_page(), foedus::storage::StorageControlBlock::root_page_pointer_, foedus::storage::PageHeader::snapshot_, foedus::storage::DualPagePointer::snapshot_pointer_, foedus::debugging::StopWatch::stop(), foedus::storage::PageHeader::storage_id_, storages_, foedus::DefaultInitializable::uninitialize(), foedus::storage::DualPagePointer::volatile_pointer_, foedus::storage::VolatilePagePointer::word, and WRAP_ERROR_CODE.

Referenced by foedus::storage::StorageManager::reinitialize_for_recovered_snapshot().

157  {
158  LOG(INFO) << "Replacing existing, stale volatile root pages with the new root snapshot pages..";
159  auto* memory_manager = engine_->get_memory_manager();
160  const auto& resolver = memory_manager->get_global_volatile_page_resolver();
161  debugging::StopWatch stop_watch;
162  uint32_t refreshed_storages = 0;
163 
164  cache::SnapshotFileSet fileset(engine_);
165  CHECK_ERROR(fileset.initialize());
166  UninitializeGuard fileset_guard(&fileset, UninitializeGuard::kWarnIfUninitializeError);
167  for (uint32_t id = 1; id <= control_block_->largest_storage_id_; ++id) {
168  StorageControlBlock* block = storages_ + id;
169  const SnapshotPagePointer snapshot_page_id = block->root_page_pointer_.snapshot_pointer_;
170  const VolatilePagePointer volatile_page_id = block->root_page_pointer_.volatile_pointer_;
171  if (!block->exists()) {
172  continue;
173  } else if (snapshot_page_id == 0) {
174  continue;
175  } else if (volatile_page_id.is_null()) {
176  // some storage type allows null volatile root pages. In that case,
177  // we don't have to do anything at this point. When the initial non-read-ony request
178  // is made, the root volatile page will be automatically created.
179  continue;
180  }
181 
182  LOG(INFO) << "Re-initializing root of storage-" << id << " from the recovered snapshot."
183  << "Volatile page ID=" << volatile_page_id << ", Snapshot page ID=" << snapshot_page_id;
184  Page* volatile_page = resolver.resolve_offset(volatile_page_id);
185  ASSERT_ND(!volatile_page->get_header().snapshot_);
186  ASSERT_ND(volatile_page->get_header().storage_id_ == id);
187  ASSERT_ND(volatile_page->get_volatile_page_id() == volatile_page_id);
188 
189  // Here, we assume that the initially-allocated volatile root page does NOT have
190  // any child volatile page (it shouldn't!). Otherwise, the following overwrite
191  // will cause leaked volatile pages.
192  WRAP_ERROR_CODE(fileset.read_page(snapshot_page_id, volatile_page));
193  ASSERT_ND(volatile_page->get_header().snapshot_);
194  ASSERT_ND(volatile_page->get_header().storage_id_ == id);
195  ASSERT_ND(volatile_page->get_snapshot_page_id() == snapshot_page_id);
196  volatile_page->get_header().snapshot_ = false;
197  volatile_page->get_header().page_id_ = volatile_page_id.word;
198  ++refreshed_storages;
199  }
200 
201  CHECK_ERROR(fileset.uninitialize());
202  stop_watch.stop();
203  LOG(INFO) << "Refreshed " << refreshed_storages
204  << " storages with the recovered snapshot in " << stop_watch.elapsed_ms() << " milliseconds";
205  return kRetOk;
206 }
StorageControlBlock * storages_
Storage instances (pimpl objects) are allocated in this shared memory.
Automatically calls if uninitialize() wasn't called when it gets out of scope, and just complains whe...
const GlobalVolatilePageResolver & get_global_volatile_page_resolver() const
Returns the page resolver to convert volatile page ID to page pointer.
StorageManagerControlBlock * control_block_
StorageId largest_storage_id_
The largest StorageId we so far observed.
uint64_t SnapshotPagePointer
Page ID of a snapshot page.
Definition: storage_id.hpp:79
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
const ErrorStack kRetOk
Normal return value for no-error case.
#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
#define WRAP_ERROR_CODE(x)
Same as CHECK_ERROR(x) except it receives only an error code, thus more efficient.
memory::EngineMemory * get_memory_manager() const
See Memory Manager.
Definition: engine.cpp:50

Here is the call graph for this function:

Here is the caller graph for this function:

xct::TrackMovedRecordResult foedus::storage::StorageManagerPimpl::track_moved_record ( StorageId  storage_id,
xct::RwLockableXctId old_address,
xct::WriteXctAccess write 
)

Definition at line 452 of file storage_manager_pimpl.cpp.

References ASSERT_ND, engine_, foedus::storage::StorageControlBlock::exists(), foedus::storage::kHashStorage, foedus::storage::kMasstreeStorage, foedus::storage::StorageControlBlock::meta_, storages_, foedus::storage::hash::HashStorage::track_moved_record(), foedus::storage::masstree::MasstreeStorage::track_moved_record(), and foedus::storage::Metadata::type_.

Referenced by foedus::storage::StorageManager::track_moved_record().

455  {
456  // so far Masstree and Hash have tracking
457  StorageControlBlock* block = storages_ + storage_id;
458  ASSERT_ND(block->exists());
459  StorageType type = block->meta_.type_;
460  if (type == kMasstreeStorage) {
461  return masstree::MasstreeStorage(engine_, block).track_moved_record(old_address, write_set);
462  } else if (type == kHashStorage) {
463  return hash::HashStorage(engine_, block).track_moved_record(old_address, write_set);
464  } else {
465  LOG(ERROR) << "Unexpected storage type for a moved-record. Bug? type=" << type;
466  return xct::TrackMovedRecordResult();
467  }
468 }
StorageControlBlock * storages_
Storage instances (pimpl objects) are allocated in this shared memory.
StorageType
Type of the storage, such as hash.
Definition: storage_id.hpp:122
#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

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::storage::StorageManagerPimpl::uninitialize_once ( )
overridevirtual

Implements foedus::DefaultInitializable.

Definition at line 208 of file storage_manager_pimpl.cpp.

References ASSERT_ND, control_block_, drop_storage_apply(), foedus::ErrorStackBatch::emprace_back(), engine_, ERROR_STACK, exists(), foedus::Engine::get_log_manager(), foedus::Engine::get_thread_pool(), foedus::log::LogManager::is_initialized(), foedus::thread::ThreadPool::is_initialized(), foedus::Engine::is_master(), foedus::kErrorCodeDepedentModuleUnavailableUninit, foedus::storage::StorageManagerControlBlock::largest_storage_id_, storages_, SUMMARIZE_ERROR_BATCH, and foedus::storage::StorageManagerControlBlock::uninitialize().

208  {
209  LOG(INFO) << "Uninitializing StorageManager..";
210  ErrorStackBatch batch;
214  }
215  if (engine_->is_master()) {
216  // drop all existing storages just for releasing memories.
217  // this is not a real drop, so we just invoke drop_apply
218  uint32_t dropped = 0;
219  for (storage::StorageId i = 1; i <= control_block_->largest_storage_id_; ++i) {
220  if (storages_[i].exists()) {
221  // TASK(Hideaki) we should have a separate method for this once we add "marked-for-death"
222  // feature.
224  ++dropped;
225  ASSERT_ND(!storages_[i].exists());
226  }
227  }
228  LOG(INFO) << "Uninitialized " << dropped << " storages";
229 
231  }
232  return SUMMARIZE_ERROR_BATCH(batch);
233 }
StorageControlBlock * storages_
Storage instances (pimpl objects) are allocated in this shared memory.
#define ERROR_STACK(e)
Instantiates ErrorStack with the given foedus::error_code, creating an error stack with the current f...
uint32_t StorageId
Unique ID for storage.
Definition: storage_id.hpp:55
bool is_initialized() const override
Returns whether the object has been already initialized or not.
Definition: log_manager.cpp:32
StorageManagerControlBlock * control_block_
StorageId largest_storage_id_
The largest StorageId we so far observed.
bool is_master() const
Returns if this engine object is a master instance.
Definition: engine.cpp:68
bool is_initialized() const override
Returns whether the object has been already initialized or not.
Definition: thread_pool.cpp:37
log::LogManager * get_log_manager() const
See Log Manager.
Definition: engine.cpp:49
#define SUMMARIZE_ERROR_BATCH(x)
This macro calls ErrorStackBatch::summarize() with automatically provided parameters.
0x0006 : "GENERAL: A dependent module is already uninitialized. This implies a wrong uninitialization...
Definition: error_code.hpp:110
#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
thread::ThreadPool * get_thread_pool() const
See Thread and Thread-Group.
Definition: engine.cpp:52

Here is the call graph for this function:

Member Data Documentation

storage::StorageId* foedus::storage::StorageManagerPimpl::storage_name_sort_

This shared memory stores the ID of storages sorted by their names.

Accessing this, either read or write, must take mod_lock_. This is why get_storage(string) is more expensive.

Definition at line 135 of file storage_manager_pimpl.hpp.

Referenced by initialize_once().

StorageControlBlock* foedus::storage::StorageManagerPimpl::storages_

Storage instances (pimpl objects) are allocated in this shared memory.

Each storage instance must be within 4kb. If the storage type requires more than 4kb, just grab a page from volatile page pools and point to it from the storage object. Remember that all pages in volatile page pools are shared.

Definition at line 128 of file storage_manager_pimpl.hpp.

Referenced by clone_all_storage_metadata(), create_storage(), create_storage_and_log(), create_storage_apply(), drop_storage(), drop_storage_apply(), exists(), get_storage(), hcc_reset_all_temperature_stat(), initialize_once(), initialize_read_latest_snapshot(), reinitialize_for_recovered_snapshot(), track_moved_record(), and uninitialize_once().


The documentation for this class was generated from the following files: