20 #include <glog/logging.h>
70 LOG(INFO) <<
"Initializing StorageManager..";
96 LOG(INFO) <<
"Initializing list of storages with latest snapshot file...";
99 LOG(INFO) <<
"There was no previous snapshot. start from empty storages";
109 uint32_t active_storages = 0;
114 VLOG(0) <<
"Storage-" <<
id <<
" is a dropped storage.";
117 VLOG(0) <<
"Storage-" <<
id <<
" exists in the snapshot.";
149 LOG(INFO) <<
"Found " << active_storages
150 <<
" active storages in " << stop_watch.
elapsed_ms() <<
" milliseconds";
158 LOG(INFO) <<
"Replacing existing, stale volatile root pages with the new root snapshot pages..";
162 uint32_t refreshed_storages = 0;
173 }
else if (snapshot_page_id == 0) {
175 }
else if (volatile_page_id.
is_null()) {
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);
198 ++refreshed_storages;
203 LOG(INFO) <<
"Refreshed " << refreshed_storages
204 <<
" storages with the recovered snapshot in " << stop_watch.
elapsed_ms() <<
" milliseconds";
209 LOG(INFO) <<
"Uninitializing StorageManager..";
218 uint32_t dropped = 0;
228 LOG(INFO) <<
"Uninitialized " << dropped <<
" storages";
250 LOG(WARNING) <<
"Requested storage name '" << name <<
"' was not found";
267 LOG(ERROR) <<
"This storage ID does not exist or has been already dropped: " << id;
272 LOG(INFO) <<
"Dropping storage " <<
id <<
"(" << name <<
")";
283 LOG(FATAL) <<
"WTF:" << type;
286 char log_buffer[1 << 12];
287 std::memset(log_buffer, 0,
sizeof(log_buffer));
296 LOG(INFO) <<
"Dropped storage " <<
id <<
"(" << name <<
")";
313 LOG(FATAL) <<
"WTF:" << type;
320 template <
typename STORAGE>
322 typedef typename STORAGE::ThisMetadata TheMetadata;
323 typedef typename STORAGE::ThisCreateLogType TheLogType;
327 STORAGE storage(
engine_, block);
328 const TheMetadata* casted_meta =
reinterpret_cast< const TheMetadata *
>(meta);
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);
365 LOG(ERROR) <<
"This storage name already exists: " << name;
376 result = create_storage_and_log< array::ArrayStorage >(metadata, commit_epoch);
378 result = create_storage_and_log< hash::HashStorage >(metadata, commit_epoch);
380 result = create_storage_and_log< masstree::MasstreeStorage >(metadata, commit_epoch);
382 result = create_storage_and_log< sequential::SequentialStorage >(metadata, commit_epoch);
384 LOG(FATAL) <<
"WTF:" << metadata->
type_;
409 result = create_storage_and_log< array::ArrayStorage >(&metadata,
nullptr);
411 result = create_storage_and_log< hash::HashStorage >(&metadata,
nullptr);
413 result = create_storage_and_log< masstree::MasstreeStorage >(&metadata,
nullptr);
415 result = create_storage_and_log< sequential::SequentialStorage >(&metadata,
nullptr);
417 LOG(FATAL) <<
"WTF:" << metadata.
type_;
420 LOG(FATAL) <<
"create_storage_apply() failed. " << result
421 <<
" Failed to restart the engine";
439 LOG(WARNING) <<
"This storage type doesn't need HCC counter reset. type=" << type;
465 LOG(ERROR) <<
"Unexpected storage type for a moved-record. Bug? type=" << type;
491 <<
" storages in " << stop_watch.
elapsed_ms() <<
" milliseconds";
Log type of DROP STORAGE operation.
StorageControlBlock * storages_
Storage instances (pimpl objects) are allocated in this shared memory.
0x0803 : "STORAGE: This Storage Name already exists" .
MetaLogBuffer * get_meta_buffer()
void populate(StorageId storage_id)
Metadata meta_
common part of the metadata.
ErrorStack initialize_once() override
numa_alloc_onnode() and numa_free().
ErrorStack drop_storage(StorageId id, Epoch *commit_epoch)
snapshot::SnapshotId get_latest_snapshot_id() const
The storage has been marked for drop and can't be used.
ErrorCode read_page(storage::SnapshotPagePointer page_id, void *out)
void emprace_back(ErrorStack &&error_stack)
If the given ErrorStack is an error, this method adds it to the end of this batch.
ErrorStack uninitialize_once() override
Automatically calls if uninitialize() wasn't called when it gets out of scope, and just complains whe...
Declares all log types used in this storage type.
#define ERROR_STACK(e)
Instantiates ErrorStack with the given foedus::error_code, creating an error stack with the current f...
storage::StorageId * storage_name_sort_memory_
This memory stores the ID of storages sorted by their names.
uint32_t StorageId
Unique ID for storage.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Represents a record of write-access during a transaction.
Represents a key-value store based on a dense and regular array.
GlobalMemoryAnchors * get_global_memory_anchors()
ErrorStack reinitialize_for_recovered_snapshot()
Special method called only from recovery manager.
bool exists(const StorageName &name)
0x0823 : "STORAGE: This storage does not exist or has been already dropped" .
Declares all log types used in this storage type.
const GlobalVolatilePageResolver & get_global_volatile_page_resolver() const
Returns the page resolver to convert volatile page ID to page pointer.
double elapsed_ms() const
bool is_initialized() const override
Returns whether the object has been already initialized or not.
Result of track_moved_record().
0x0005 : "GENERAL: A dependent module is not initialized yet. This implies a wrong initialization ord...
Represents a pointer to a volatile page with modification count for preventing ABA.
StorageManagerControlBlock * control_block_
ErrorStack uninitialize() override final
Typical implementation of Initializable::uninitialize() that provides uninitialize-once semantics...
StorageId largest_storage_id_
The largest StorageId we so far observed.
Brings error stacktrace information as return value of functions.
xct::TrackMovedRecordResult track_moved_record(StorageId storage_id, xct::RwLockableXctId *old_address, xct::WriteXctAccess *write)
DualPagePointer root_page_pointer_
Points to the root page (or something equivalent).
void alloc(uint64_t size, uint64_t alignment, AllocType alloc_type, int numa_node) noexcept
Allocate a memory, releasing the current memory if exists.
ErrorStack create_storage_and_log(const Metadata *meta, Epoch *commit_epoch)
The storage has been created and ready for use.
Holds a set of read-only file objects for snapshot files.
ErrorStack read_snapshot_metadata(SnapshotId snapshot_id, SnapshotMetadata *out)
Read the snapshot metadata file that contains storages as of the snapshot.
const EngineOptions & get_options() const
uint32_t max_storages_
Maximum number of storages in this database.
#define COERCE_ERROR(x)
This macro calls x and aborts if encounters an error.
bool is_master() const
Returns if this engine object is a master instance.
xct::TrackMovedRecordResult track_moved_record(xct::RwLockableXctId *old_address, xct::WriteXctAccess *write_set)
Resolves a "moved" record.
savepoint::SavepointManager * get_savepoint_manager() const
See Savepoint Manager.
storage::StorageControlBlock * storage_memories_
Status of each storage instance is stored in this shared memory.
The MCS reader-writer lock variant of LockableXctId.
Represents an append/scan-only store.
storage::StorageManagerControlBlock * storage_manager_memory_
Tiny memory for storage manager.
Batches zero or more ErrorStack objects to represent in one ErrorStack.
VolatilePagePointer volatile_pointer_
xct::TrackMovedRecordResult track_moved_record(xct::RwLockableXctId *old_address, xct::WriteXctAccess *write_set)
Resolves a "moved" record.
VolatilePagePointer get_volatile_page_id() const
bool is_initialized() const override
Returns whether the object has been already initialized or not.
Declares common log types for all (or at least multiple) storage types.
StorageControlBlock * get_storage(StorageId id)
log::LogManager * get_log_manager() const
See Log Manager.
void create_storage_apply(const Metadata &metadata)
storage::StorageOptions storage_
Declares all log types used in this storage type.
uint64_t SnapshotPagePointer
Page ID of a snapshot page.
Calls Initializable::uninitialize() automatically when it gets out of scope.
ErrorStack initialize() override final
Typical implementation of Initializable::initialize() that provides initialize-once semantics...
bool empty() const noexcept
Test if string is empty.
uint64_t stop()
Take another current time tick.
SnapshotPagePointer snapshot_pointer_
Auto-lock scope object for SharedMutex.
soc::SharedMutex mod_lock_
In case there are multiple threads that add/delete/expand storages, those threads take this lock...
Just a marker to denote that the memory region represents a data page.
0x0824 : "STORAGE: Storage name is empty" .
0x0822 : "STORAGE: Reached maximum number of storages. To register more storages, adjust StorageOptio...
void * get_block() const
Returns the memory block.
uint16_t SnapshotId
Unique ID of Snapshot.
Represents a key-value store based on a dense and regular hash.
Represents a Masstree storage.
Just a set of pointers within global_memory_ for ease of use.
const SnapshotId kNullSnapshotId
StorageType
Type of the storage, such as hash.
#define SUMMARIZE_ERROR_BATCH(x)
This macro calls ErrorStackBatch::summarize() with automatically provided parameters.
ErrorStack hcc_reset_all_temperature_stat(StorageId storage_id)
Resets all volatile pages' temperature stat to be zero in the specified storage.
storage::StorageId * storage_name_sort_
This shared memory stores the ID of storages sorted by their names.
Declares all log types used in this storage type.
StorageId issue_next_storage_id()
#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.
void drop_storage_apply(StorageId id)
const ErrorStack kRetOk
Normal return value for no-error case.
soc::SocManager * get_soc_manager() const
See SOC and IPC.
Initial state, which means the storage has not been created yet.
uint32_t get_max_storages() const
xct::TrackMovedRecordResult track_moved_record(StorageId storage_id, xct::RwLockableXctId *old_address, xct::WriteXctAccess *write_set)
Resolves a "moved" record.
Atomic fence methods and load/store with fences that work for both C++11/non-C++11 code...
ErrorStack initialize_read_latest_snapshot()
0x0807 : "STORAGE: This metadata type is not yet supported" .
PageHeader & get_header()
At least the basic header exists in all pages.
snapshot::SnapshotManager * get_snapshot_manager() const
See Snapshot Manager.
ErrorStack reinitialize_for_recovered_snapshot()
Special method called only from recovery manager.
0x0006 : "GENERAL: A dependent module is already uninitialized. This implies a wrong uninitialization...
SnapshotPagePointer get_snapshot_page_id() const
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
A high-resolution stop watch.
StorageStatus status_
Status of the storage.
#define WRAP_ERROR_CODE(x)
Same as CHECK_ERROR(x) except it receives only an error code, thus more efficient.
A base layout of shared data for all storage types.
memory::EngineMemory * get_memory_manager() const
See Memory Manager.
thread::ThreadPool * get_thread_pool() const
See Thread and Thread-Group.
void zero_fill_remaining() const noexcept
Sets zeros to unused data_ region.
bool is_error() const
Returns if this return code is not kErrorCodeOk.
SharedMemoryRepo * get_shared_memory_repo()
Returns the shared memories maintained across SOCs.
void memory_fence_acq_rel()
Equivalent to std::atomic_thread_fence(std::memory_order_acq_rel).
ErrorStack clone_all_storage_metadata(snapshot::SnapshotMetadata *metadata)
ErrorStack create_storage(Metadata *metadata, Epoch *commit_epoch)