libfoedus-core
FOEDUS Core Library
foedus::restart::RestartManagerPimpl Class Referencefinal

Pimpl object of RestartManager. More...

Detailed Description

Pimpl object of RestartManager.

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

Definition at line 44 of file restart_manager_pimpl.hpp.

#include <restart_manager_pimpl.hpp>

Inheritance diagram for foedus::restart::RestartManagerPimpl:
Collaboration diagram for foedus::restart::RestartManagerPimpl:

Public Member Functions

 RestartManagerPimpl ()=delete
 
 RestartManagerPimpl (Engine *engine)
 
ErrorStack initialize_once () override
 
ErrorStack uninitialize_once () override
 
ErrorStack recover ()
 Recover the state of database from recent snapshot files and transaction logs. More...
 
ErrorStack redo_meta_logs (Epoch durable_epoch, Epoch snapshot_epoch)
 Redo metadata operation (create/drop storage) since the latest snapshot. More...
 
- 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_
 
RestartManagerControlBlockcontrol_block_
 

Constructor & Destructor Documentation

foedus::restart::RestartManagerPimpl::RestartManagerPimpl ( )
delete
foedus::restart::RestartManagerPimpl::RestartManagerPimpl ( Engine engine)
inlineexplicit

Definition at line 47 of file restart_manager_pimpl.hpp.

Member Function Documentation

ErrorStack foedus::restart::RestartManagerPimpl::initialize_once ( )
overridevirtual

Implements foedus::DefaultInitializable.

Definition at line 40 of file restart_manager_pimpl.cpp.

References CHECK_ERROR, control_block_, engine_, ERROR_STACK, foedus::soc::SocManager::get_shared_memory_repo(), foedus::Engine::get_soc_manager(), foedus::Engine::get_xct_manager(), foedus::xct::XctManager::is_initialized(), foedus::Engine::is_master(), foedus::kErrorCodeDepedentModuleUnavailableInit, foedus::kRetOk, and recover().

40  {
43  }
45  get_global_memory_anchors()->restart_manager_memory_;
46 
47  // Restart manager works only in master
48  if (engine_->is_master()) {
49  LOG(INFO) << "Initializing RestartManager..";
50 
51  // after all other initializations, we trigger recovery procedure.
53  }
54  return kRetOk;
55 }
#define ERROR_STACK(e)
Instantiates ErrorStack with the given foedus::error_code, creating an error stack with the current f...
bool is_initialized() const override
Returns whether the object has been already initialized or not.
Definition: xct_manager.cpp:31
0x0005 : "GENERAL: A dependent module is not initialized yet. This implies a wrong initialization ord...
Definition: error_code.hpp:109
bool is_master() const
Returns if this engine object is a master instance.
Definition: engine.cpp:68
RestartManagerControlBlock * control_block_
ErrorStack recover()
Recover the state of database from recent snapshot files and transaction logs.
xct::XctManager * get_xct_manager() const
See Transaction Manager.
Definition: engine.cpp:61
#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
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::restart::RestartManagerPimpl::recover ( )

Recover the state of database from recent snapshot files and transaction logs.

Precondition
is_initialized(), and all other modules in the engine is_initialized().

Definition at line 71 of file restart_manager_pimpl.cpp.

References CHECK_ERROR, engine_, foedus::log::LogManager::get_durable_global_epoch(), foedus::Engine::get_log_manager(), foedus::snapshot::SnapshotManager::get_pimpl(), foedus::snapshot::SnapshotManager::get_snapshot_epoch(), foedus::Engine::get_snapshot_manager(), foedus::Engine::get_storage_manager(), foedus::snapshot::SnapshotManagerPimpl::handle_snapshot_triggered(), foedus::Epoch::kEpochInitialDurable, foedus::kRetOk, redo_meta_logs(), foedus::storage::StorageManager::reinitialize_for_recovered_snapshot(), and foedus::Epoch::value().

Referenced by initialize_once().

71  {
72  Epoch durable_epoch = engine_->get_log_manager()->get_durable_global_epoch();
73  Epoch snapshot_epoch = engine_->get_snapshot_manager()->get_snapshot_epoch();
74  LOG(INFO) << "Recovering the database... durable_epoch=" << durable_epoch
75  << ", snapshot_epoch=" << snapshot_epoch;
76 
77  if (durable_epoch.value() == Epoch::kEpochInitialDurable) {
78  if (!snapshot_epoch.is_valid()) {
79  LOG(INFO) << "The database is in initial state. Nothing to recover.";
80  return kRetOk;
81  } else {
82  // this means durable_epoch wraps around. nothing wrong, but worth logging.
83  LOG(INFO) << "Interesting. durable_epoch is initial value, but we have snapshot."
84  << " This means epoch wrapped around!";
85  }
86  }
87 
88  if (durable_epoch == snapshot_epoch) {
89  LOG(INFO) << "The snapshot is up-to-date. No need to recover.";
90  return kRetOk;
91  }
92 
93  LOG(INFO) << "There are logs that are durable but not yet snapshotted.";
94  CHECK_ERROR(redo_meta_logs(durable_epoch, snapshot_epoch));
95  LOG(INFO) << "Launching snapshot..";
96  snapshot::SnapshotManagerPimpl* snapshot_pimpl = engine_->get_snapshot_manager()->get_pimpl();
97  snapshot::Snapshot the_snapshot;
98  CHECK_ERROR(snapshot_pimpl->handle_snapshot_triggered(&the_snapshot));
99  LOG(INFO) << "Finished initial snapshot during start-up.";
100 
101  // This fixes Bug #127.
102  // Right after the recovery-snapshot, any non-null volatile root pages becomes stale.
103  // we need to replace them with the new snapshot pages.
105 
106  LOG(INFO) << "Now we can start processing transaction";
107  return kRetOk;
108 }
SnapshotManagerPimpl * get_pimpl()
Do not use this unless you know what you are doing.
storage::StorageManager * get_storage_manager() const
See Storage Manager.
Definition: engine.cpp:60
log::LogManager * get_log_manager() const
See Log Manager.
Definition: engine.cpp:49
Epoch get_durable_global_epoch() const
Returns the durable epoch of the entire engine.
Definition: log_manager.cpp:36
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
const ErrorStack kRetOk
Normal return value for no-error case.
ErrorStack redo_meta_logs(Epoch durable_epoch, Epoch snapshot_epoch)
Redo metadata operation (create/drop storage) since the latest snapshot.
snapshot::SnapshotManager * get_snapshot_manager() const
See Snapshot Manager.
Definition: engine.cpp:56
As there is no transaction in ep-1, initial durable_epoch is 1.
Definition: epoch.hpp:70
ErrorStack reinitialize_for_recovered_snapshot()
Special method called only from recovery manager.
Epoch get_snapshot_epoch() const
Returns the most recently snapshot-ed epoch, all logs upto this epoch is safe to delete.

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::restart::RestartManagerPimpl::redo_meta_logs ( Epoch  durable_epoch,
Epoch  snapshot_epoch 
)

Redo metadata operation (create/drop storage) since the latest snapshot.

Essentially this is the only thing the restart manager has to do.

Definition at line 110 of file restart_manager_pimpl.cpp.

References foedus::memory::AlignedMemory::alloc(), ASSERT_ND, foedus::log::LogOptions::construct_meta_log_path(), foedus::storage::StorageManager::drop_storage_apply(), foedus::log::LogOptions::emulation_, engine_, foedus::fs::file_size(), foedus::memory::AlignedMemory::get_block(), foedus::xct::XctId::get_epoch(), foedus::log::LogHeader::get_kind(), foedus::savepoint::SavepointManager::get_meta_logger_offsets(), foedus::Engine::get_options(), foedus::Engine::get_savepoint_manager(), foedus::Engine::get_storage_manager(), foedus::log::LogHeader::get_type(), foedus::log::BaseLogType::header_, foedus::Epoch::is_valid(), foedus::fs::DirectIoFile::kDirectIoSeekSet, foedus::log::kLogCodeArrayCreate, foedus::log::kLogCodeDropLogType, foedus::log::kLogCodeEpochMarker, foedus::log::kLogCodeFiller, foedus::log::kLogCodeHashCreate, foedus::log::kLogCodeInvalid, foedus::log::kLogCodeMasstreeCreate, foedus::log::kLogCodeSequentialCreate, foedus::memory::AlignedMemory::kNumaAllocOnnode, foedus::log::kRecordLogs, foedus::kRetOk, foedus::EngineOptions::log_, foedus::log::LogHeader::log_length_, foedus::log::LogHeader::storage_id_, WRAP_ERROR_CODE, and foedus::log::LogHeader::xct_id_.

Referenced by recover().

110  {
111  ASSERT_ND(!snapshot_epoch.is_valid() || snapshot_epoch < durable_epoch);
112  LOG(INFO) << "Redoing metadata operations from " << snapshot_epoch << " to " << durable_epoch;
113 
114  // Because metadata log is tiny, we do nothing complex here. Just read them all.
115  fs::Path path(engine_->get_options().log_.construct_meta_log_path());
116  fs::DirectIoFile file(path, engine_->get_options().log_.emulation_);
117  WRAP_ERROR_CODE(file.open(true, false, false, false));
118  uint64_t oldest_offset;
119  uint64_t durable_offset;
120  engine_->get_savepoint_manager()->get_meta_logger_offsets(&oldest_offset, &durable_offset);
121  ASSERT_ND(oldest_offset % (1 << 12) == 0);
122  ASSERT_ND(durable_offset % (1 << 12) == 0);
123  ASSERT_ND(oldest_offset <= durable_offset);
124  ASSERT_ND(fs::file_size(path) >= durable_offset);
125  uint32_t read_size = durable_offset - oldest_offset;
126 
127  LOG(INFO) << "Will read " << read_size << " bytes from meta log";
128 
129  // Assuming it's tiny, just read it in one shot.
130  memory::AlignedMemory buffer;
131  buffer.alloc(read_size, 1U << 12, memory::AlignedMemory::kNumaAllocOnnode, 0);
132 
133  WRAP_ERROR_CODE(file.seek(oldest_offset, fs::DirectIoFile::kDirectIoSeekSet));
134  WRAP_ERROR_CODE(file.read_raw(read_size, buffer.get_block()));
135 
136  char* buf = reinterpret_cast<char*>(buffer.get_block());
137  uint32_t cur = 0;
138  uint32_t processed = 0;
139  storage::StorageManager* stm = engine_->get_storage_manager();
140  while (cur < read_size) {
141  log::BaseLogType* entry = reinterpret_cast<log::BaseLogType*>(buf + cur);
142  ASSERT_ND(entry->header_.get_kind() != log::kRecordLogs);
143  const uint32_t log_length = entry->header_.log_length_;
144  cur += log_length;
145  log::LogCode type = entry->header_.get_type();
147  if (type == log::kLogCodeFiller || type == log::kLogCodeEpochMarker) {
148  continue;
149  }
150  Epoch epoch = entry->header_.xct_id_.get_epoch();
151  if (epoch > durable_epoch) {
152  LOG(FATAL) << "WTF. This should have been checked in meta logger's startup??";
153  }
154  if (snapshot_epoch.is_valid() && epoch <= snapshot_epoch) {
155  continue;
156  }
157  switch (type) {
159  LOG(INFO) << "Redoing DROP STORAGE-" << entry->header_.storage_id_;
160  stm->drop_storage_apply(entry->header_.storage_id_);
161  ++processed;
162  break;
167  reinterpret_cast<storage::CreateLogType*>(entry)->apply_storage(
168  engine_,
169  entry->header_.storage_id_);
170  ++processed;
171  break;
172  default:
173  LOG(ERROR) << "Unexpected log type in metadata log:" << entry->header_;
174  }
175  }
176 
177  file.close();
178  LOG(INFO) << "Redone " << processed << " metadata operations";
179  return kRetOk;
180 }
LogCode
A unique identifier of all log types.
Definition: log_type.hpp:87
numa_alloc_onnode() and numa_free().
storage::StorageManager * get_storage_manager() const
See Storage Manager.
Definition: engine.cpp:60
record targetted logs
Definition: log_type.hpp:103
const EngineOptions & get_options() const
Definition: engine.cpp:39
savepoint::SavepointManager * get_savepoint_manager() const
See Savepoint Manager.
Definition: engine.cpp:53
0x1027 : foedus::storage::hash::HashCreateLogType .
Definition: log_type.hpp:120
0x1021 : foedus::storage::array::ArrayCreateLogType .
Definition: log_type.hpp:114
uint64_t file_size(const Path &p)
Returns size of the file.
Definition: filesystem.cpp:120
std::string construct_meta_log_path() const
metadata log file is placed in node-0/logger-0 folder
Definition: log_options.cpp:51
foedus::fs::DeviceEmulationOptions emulation_
Settings to emulate slower logging device.
const ErrorStack kRetOk
Normal return value for no-error case.
0 is reserved as a non-existing log type.
Definition: log_type.hpp:89
0x3001 : foedus::log::FillerLogType .
Definition: log_type.hpp:111
void get_meta_logger_offsets(uint64_t *oldest_offset, uint64_t *durable_offset) const
Returns the saved information of metadata logger in lateset savepoint.
#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.
0x1031 : foedus::storage::masstree::MasstreeCreateLogType .
Definition: log_type.hpp:125
0x1025 : foedus::storage::sequential::SequentialCreateLogType .
Definition: log_type.hpp:118
The offset is set to offset bytes.
0x1011 : foedus::storage::DropLogType .
Definition: log_type.hpp:113
0x3002 : foedus::log::EpochMarkerLogType .
Definition: log_type.hpp:112

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::restart::RestartManagerPimpl::uninitialize_once ( )
overridevirtual

Implements foedus::DefaultInitializable.

Definition at line 57 of file restart_manager_pimpl.cpp.

References foedus::ErrorStackBatch::emprace_back(), engine_, ERROR_STACK, foedus::snapshot::SnapshotManager::get_pimpl(), foedus::Engine::get_snapshot_manager(), foedus::Engine::get_xct_manager(), foedus::xct::XctManager::is_initialized(), foedus::Engine::is_master(), foedus::kErrorCodeDepedentModuleUnavailableUninit, foedus::snapshot::SnapshotManagerPimpl::stop_snapshot_thread(), and SUMMARIZE_ERROR_BATCH.

57  {
58  ErrorStackBatch batch;
61  }
62  if (engine_->is_master()) {
63  LOG(INFO) << "Uninitializing RestartManager..";
64  // restart manager essentially has nothing to release, but because this is the first module
65  // to uninit, we place "stop them first" kind of operations here.
66  engine_->get_snapshot_manager()->get_pimpl()->stop_snapshot_thread(); // stop snapshot thread
67  }
68  return SUMMARIZE_ERROR_BATCH(batch);
69 }
SnapshotManagerPimpl * get_pimpl()
Do not use this unless you know what you are doing.
#define ERROR_STACK(e)
Instantiates ErrorStack with the given foedus::error_code, creating an error stack with the current f...
bool is_initialized() const override
Returns whether the object has been already initialized or not.
Definition: xct_manager.cpp:31
bool is_master() const
Returns if this engine object is a master instance.
Definition: engine.cpp:68
#define SUMMARIZE_ERROR_BATCH(x)
This macro calls ErrorStackBatch::summarize() with automatically provided parameters.
xct::XctManager * get_xct_manager() const
See Transaction Manager.
Definition: engine.cpp:61
void stop_snapshot_thread()
This is a hidden API called at the beginning of engine shutdown (namely restart manager).
snapshot::SnapshotManager * get_snapshot_manager() const
See Snapshot Manager.
Definition: engine.cpp:56
0x0006 : "GENERAL: A dependent module is already uninitialized. This implies a wrong uninitialization...
Definition: error_code.hpp:110

Here is the call graph for this function:

Member Data Documentation

RestartManagerControlBlock* foedus::restart::RestartManagerPimpl::control_block_

Definition at line 63 of file restart_manager_pimpl.hpp.

Referenced by initialize_once().

Engine* const foedus::restart::RestartManagerPimpl::engine_

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