libfoedus-core
FOEDUS Core Library
foedus::soc::SocManager Class Referencefinal

SOC manager, which maintains the shared resource across SOCs and, if this engine is a master engine, manages child SOCs. More...

Detailed Description

SOC manager, which maintains the shared resource across SOCs and, if this engine is a master engine, manages child SOCs.

Initialization of this module is quite special because a master engine launches child SOCs potentially as different processes. Also, to avoid leak of shared memory, we take a bit complicated steps.

Initialization Order

When the user instantiates an Engine object, the engine is initialized in the following order:

  • Engine object constructor (which does almost nothing itself)
  • (Optional) The user pre-registers user procedures (for emulated or fork children SOCs only).
  • The user invokes Engine::initialize() of the master engine
  • CAUTION-FROM-HERE. SOCManager allocates shared memory of required sizes.
  • SOCManager in master engine launches child SOCs, waits for their progress.
  • SOCManager in child SOC engines attach the shared memory and acknowledge it via the shared memory.
  • CAUTION-UNTIL-HERE. SOCManager in master engine determines if either all SOCManagers attached the shared memory or there was some error. In either case, it marks the shared memory for reclamation (shmctl(IPC_RMID)).
  • Child SOCs move on to other modules' initialization.
  • Master SOCManager receives the result of child SOC initilization, then does remaining initialization, such as restart.

Notice the annotated region. If there is an unexpected crash in master engine during this period, we leak shared memory until reboot or manual reclamation (ipcrm command). We must avoid it as much as possible. Be extra careful!

Definition at line 60 of file soc_manager.hpp.

#include <soc_manager.hpp>

Inheritance diagram for foedus::soc::SocManager:
Collaboration diagram for foedus::soc::SocManager:

Public Member Functions

 SocManager (Engine *engine)
 
 ~SocManager ()
 
 SocManager ()=delete
 
 SocManager (const SocManager &)=delete
 
SocManageroperator= (const SocManager &)=delete
 
ErrorStack initialize () override
 Acquires resources in this object, usually called right after constructor. More...
 
bool is_initialized () const override
 Returns whether the object has been already initialized or not. More...
 
ErrorStack uninitialize () override
 An idempotent method to release all resources of this object, if any. More...
 
SharedMemoryRepoget_shared_memory_repo ()
 Returns the shared memories maintained across SOCs. More...
 
void * get_shared_user_memory () const
 Shortcut for get_shared_memory_repo()->get_global_user_memory() More...
 
uint64_t get_shared_user_memory_size () const
 
ErrorStack wait_for_master_module (bool init, ModuleType module)
 Wait for master engine to finish init/uninit the module. More...
 
ErrorStack wait_for_children_module (bool init, ModuleType module)
 Wait for other engines to finish init/uninit the module. More...
 
void report_engine_fatal_error ()
 Announce fatal error state of this (either master or child) engine if possible. More...
 
- Public Member Functions inherited from foedus::Initializable
virtual ~Initializable ()
 

Static Public Member Functions

static void trap_spawned_soc_main ()
 This should be called at the beginning of main() if the executable expects to be spawned as SOC engines. More...
 
static void trap_spawned_soc_main (const std::vector< proc::ProcAndName > &procedures)
 This version also receives user-defined procedures to be registered in this SOC. More...
 

Friends

class SocManagerPimpl
 

Constructor & Destructor Documentation

foedus::soc::SocManager::SocManager ( Engine engine)
explicit

Definition at line 26 of file soc_manager.cpp.

References SocManagerPimpl.

26  : pimpl_(nullptr) {
27  pimpl_ = new SocManagerPimpl(engine);
28 }
friend class SocManagerPimpl
Definition: soc_manager.hpp:62
foedus::soc::SocManager::~SocManager ( )

Definition at line 29 of file soc_manager.cpp.

29  {
30  delete pimpl_;
31  pimpl_ = nullptr;
32 }
foedus::soc::SocManager::SocManager ( )
delete
foedus::soc::SocManager::SocManager ( const SocManager )
delete

Member Function Documentation

SharedMemoryRepo * foedus::soc::SocManager::get_shared_memory_repo ( )

Returns the shared memories maintained across SOCs.

Definition at line 38 of file soc_manager.cpp.

References foedus::soc::SocManagerPimpl::memory_repo_.

Referenced by foedus::snapshot::LogGleaner::execute(), foedus::snapshot::LogReducerRef::get_buffer(), foedus::snapshot::LogReducerRef::get_cur_snapshot(), foedus::storage::PartitionerMetadata::get_index0_metadata(), foedus::storage::PartitionerMetadata::get_metadata(), foedus::restart::RestartManagerPimpl::initialize_once(), foedus::log::MetaLogger::initialize_once(), foedus::memory::NumaNodeMemory::initialize_once(), foedus::EnginePimpl::initialize_once(), foedus::storage::StorageManagerPimpl::initialize_once(), foedus::proc::ProcManagerPimpl::initialize_once(), foedus::log::LogManagerPimpl::initialize_once(), foedus::xct::XctManagerPimpl::initialize_once(), foedus::savepoint::SavepointManagerPimpl::initialize_once(), foedus::thread::ThreadPimpl::initialize_once(), foedus::snapshot::SnapshotManagerPimpl::initialize_once(), foedus::storage::PartitionerMetadata::locate_data(), foedus::snapshot::LogGleanerRef::LogGleanerRef(), foedus::snapshot::LogReducer::LogReducer(), foedus::snapshot::LogReducerRef::LogReducerRef(), foedus::memory::NumaNodeMemoryRef::NumaNodeMemoryRef(), foedus::EnginePimpl::on_module_initialized(), foedus::EnginePimpl::on_module_uninitialized(), foedus::savepoint::SavepointManagerPimpl::savepoint_main(), foedus::thread::ThreadRef::ThreadRef(), foedus::EnginePimpl::uninitialize_once(), and foedus::snapshot::SnapshotManagerPimpl::uninitialize_once().

38 { return &pimpl_->memory_repo_; }

Here is the caller graph for this function:

void * foedus::soc::SocManager::get_shared_user_memory ( ) const

Shortcut for get_shared_memory_repo()->get_global_user_memory()

Definition at line 40 of file soc_manager.cpp.

References foedus::soc::SharedMemoryRepo::get_global_user_memory(), and foedus::soc::SocManagerPimpl::memory_repo_.

Referenced by foedus::memory::EngineMemory::get_shared_user_memory().

40  {
41  return pimpl_->memory_repo_.get_global_user_memory();
42 }

Here is the call graph for this function:

Here is the caller graph for this function:

uint64_t foedus::soc::SocManager::get_shared_user_memory_size ( ) const
Returns
the byte size of shared user-controlled memory. Equivalent to SocOptions.shared_user_memory_size_kb_ << 10.

Definition at line 43 of file soc_manager.cpp.

References foedus::soc::SocManagerPimpl::engine_, foedus::Engine::get_options(), foedus::soc::SocOptions::shared_user_memory_size_kb_, and foedus::EngineOptions::soc_.

Referenced by foedus::memory::EngineMemory::get_shared_user_memory_size().

43  {
44  return pimpl_->engine_->get_options().soc_.shared_user_memory_size_kb_ * 1024ULL;
45 }
const EngineOptions & get_options() const
Definition: engine.cpp:39
uint64_t shared_user_memory_size_kb_
As part of the global shared memory, we reserve this size of 'user memory' that can be used for arbit...
Definition: soc_options.hpp:60

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::soc::SocManager::initialize ( )
overridevirtual

Acquires resources in this object, usually called right after constructor.

Precondition
is_initialized() == FALSE

If and only if the return value was not an error, is_initialized() will return TRUE. This method is usually not idempotent, but some implementation can choose to be. In that case, the implementation class should clarify that it's idempotent. This method is responsible for releasing all acquired resources when initialization fails. This method itself is NOT thread-safe. Do not call this in a racy situation.

Implements foedus::Initializable.

Definition at line 34 of file soc_manager.cpp.

References foedus::DefaultInitializable::initialize().

Referenced by foedus::EnginePimpl::initialize_once().

34 { return pimpl_->initialize(); }
ErrorStack initialize() override final
Typical implementation of Initializable::initialize() that provides initialize-once semantics...

Here is the call graph for this function:

Here is the caller graph for this function:

bool foedus::soc::SocManager::is_initialized ( ) const
overridevirtual

Returns whether the object has been already initialized or not.

Implements foedus::Initializable.

Definition at line 35 of file soc_manager.cpp.

References foedus::DefaultInitializable::is_initialized().

Referenced by foedus::EnginePimpl::initialize_modules(), and foedus::EnginePimpl::uninitialize_once().

35 { return pimpl_->is_initialized(); }
bool is_initialized() const override final
Returns whether the object has been already initialized or not.

Here is the call graph for this function:

Here is the caller graph for this function:

SocManager& foedus::soc::SocManager::operator= ( const SocManager )
delete
void foedus::soc::SocManager::report_engine_fatal_error ( )

Announce fatal error state of this (either master or child) engine if possible.

Definition at line 64 of file soc_manager.cpp.

References foedus::soc::SocManagerPimpl::report_engine_fatal_error().

Referenced by foedus::EnginePimpl::initialize_once().

Here is the call graph for this function:

Here is the caller graph for this function:

void foedus::soc::SocManager::trap_spawned_soc_main ( )
static

This should be called at the beginning of main() if the executable expects to be spawned as SOC engines.

This method detects if the process has been spawned from FOEDUS as an SOC engine. If so, it starts running as an SOC engine and exits the process (via _exit()) when done. This should be called as early as possible like following:

int main(int argc, char** argv) {
// user code ....
return 0;
}

If the process has not been spawned as FOEDUS's SOC engine, this method does nothing and immediately returns.

Definition at line 48 of file soc_manager.cpp.

48  {
49  std::vector< proc::ProcAndName > procedures;
50  trap_spawned_soc_main(procedures);
51 }
static void trap_spawned_soc_main()
This should be called at the beginning of main() if the executable expects to be spawned as SOC engin...
Definition: soc_manager.cpp:48
void foedus::soc::SocManager::trap_spawned_soc_main ( const std::vector< proc::ProcAndName > &  procedures)
static

This version also receives user-defined procedures to be registered in this SOC.

Parameters
[in]proceduresuser-defined procedures' name and function pointer in this process.

Example:

ErrorStack my_proc(foedus::thread::Thread* context, ...) {
...
return kRetOk;
}
int main(int argc, char** argv) {
std::vector< foedus::proc::ProcAndName > procedures;
procedures.push_back(foedus::proc::ProcAndName("my_proc", &my_proc));
... // register more
// user code ....
return 0;
}

Definition at line 53 of file soc_manager.cpp.

References foedus::soc::SocManagerPimpl::spawned_child_main().

53  {
55 }
static void spawned_child_main(const std::vector< proc::ProcAndName > &procedures)
Main routine of spawned SOCs.

Here is the call graph for this function:

ErrorStack foedus::soc::SocManager::uninitialize ( )
overridevirtual

An idempotent method to release all resources of this object, if any.

After this method, is_initialized() will return FALSE. Whether this method encounters an error or not, the implementation should make the best effort to release as many resources as possible. In other words, Do not leak all resources because of one issue. This method itself is NOT thread-safe. Do not call this in a racy situation.

Attention
This method is NOT automatically called from the destructor. This is due to the fundamental limitation in C++. Explicitly call this method as soon as you are done, checking the returned value. You can also use UninitializeGuard to ameliorate the issue, but it's not perfect.
Returns
The error this method encounters, if any. In case there are multiple errors while uninitialization, the implementation should use ErrorStackBatch to produce a batched ErrorStack object.

Implements foedus::Initializable.

Definition at line 36 of file soc_manager.cpp.

References foedus::DefaultInitializable::uninitialize().

Referenced by foedus::EnginePimpl::uninitialize_once().

36 { return pimpl_->uninitialize(); }
ErrorStack uninitialize() override final
Typical implementation of Initializable::uninitialize() that provides uninitialize-once semantics...

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::soc::SocManager::wait_for_children_module ( bool  init,
ModuleType  module 
)

Wait for other engines to finish init/uninit the module.

Definition at line 57 of file soc_manager.cpp.

References foedus::soc::SocManagerPimpl::wait_for_children_module().

Referenced by foedus::EnginePimpl::initialize_modules(), and foedus::EnginePimpl::uninitialize_once().

57  {
58  return pimpl_->wait_for_children_module(init, module);
59 }
ErrorStack wait_for_children_module(bool init, ModuleType module)

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::soc::SocManager::wait_for_master_module ( bool  init,
ModuleType  module 
)

Wait for master engine to finish init/uninit the module.

Definition at line 61 of file soc_manager.cpp.

References foedus::soc::SocManagerPimpl::wait_for_master_module().

Referenced by foedus::EnginePimpl::initialize_modules(), and foedus::EnginePimpl::uninitialize_once().

61  {
62  return pimpl_->wait_for_master_module(init, module);
63 }
ErrorStack wait_for_master_module(bool init, ModuleType module)

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class SocManagerPimpl
friend

Definition at line 62 of file soc_manager.hpp.

Referenced by SocManager().


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