libfoedus-core
FOEDUS Core Library
foedus::proc Namespace Reference

System and User Procedures. More...

Detailed Description

System and User Procedures.

This module manages computational tasks (Procedures here after) that can be executed on worker threads.

What is a procedure
In a nutshell, a procedure receives inputs and runs on one worker thread, then outputs the results along with error code/stack if failed. This is the unit of tasks one can give to Thread and Thread-Group module. Input/output are of arbitrary format. FOEDUS simply receives/sends a byte array of up to some size (configuration parameter) as data via shared memory. It's left to the procedure to serialize/deserialize the values. The only constraint is that the data must be self-contained. You can't put pointers in it. If some result must be stored in remotely-accessible manner, you can put them in a storage.
Procedure signature
Every procedure has the following function signature.
ErrorStack procedure(const ProcArguments& args);
  • context is the thread context of the pre-allocated thread that runs the impersonated session (see Thread-Pool and Impersonation for more details about impersonation).
  • input_buffer is an arbitrary input data given by the user themselves as of impersonation.
  • output_buffer is an arbitrary output data that will be returned to the session when the procedure completes.
Granulality of a procedure
Although a procedure in usual databases run just one transaction, a procedure in FOEDUS can run an arbitary number of transactions. A procedure can be the entire user application, too. Think of our procedure as a way to distribute user code to each SOC. Once attached to a worker thread, a procedure can run arbitrary code and it is the intended use. If you attach/detach an individual transaction as one procedure, the inter-process communication will cost a lot.
System and User Procedures
System procedures are a fixed set of procedures provided by FOEDUS itself. Users can invoke them, but they cannot add/modify them. As all system stored procedures are built-in to FOEDUS library, they are automatically avaialble in all SOCs. Names of system stored procedures start with "sys_". User procedures are what user code defines. To register the procedures, the user code has to do one of the followings.
Local-only User Procedures (function pointer)
This is the easiest way to define and execute user procedures. In fact, most test code uses this handy procedure type. The user simply defines a method and registers function pointer. However, this type of procedures can be used only when:
  • child SOC engines are of foedus::EngineType::kChildEmulated type.
  • child SOC engines are of foedus::EngineType::kChildForked type and the user pre-registers the function pointer BEFORE the fork (Engine's initialize()).
Individually registered User Procedures
Otherwise, the user has to register the procedures in each SOC because multiple processes do not share address space nor have necessarily same set of shared libraries loaded. We provide a few ways to register procedures in that case.
  • Shared libraries. Users can specify file/folder of shared libraries to load in each SOC. At the start up of each SOC, we load these shared libraries, which can register procedures.
  • Overwrite main() and use spawn() type of SOC launching. User can write their main() so that it initializes child SOC engines and then registers function pointers locally.
See also
SOC and IPC
foedus::EngineType

Classes

struct  ProcArguments
 Set of arguments, both inputs and outputs, given to each procedure. More...
 
class  ProcManager
 Procedure manager, which maintains the list of system/user procedures. More...
 
struct  ProcManagerControlBlock
 This small control block is used to synchronize the access to the array. More...
 
class  ProcManagerPimpl
 Pimpl object of ProcManager. More...
 
struct  ProcOptions
 Set of options for loading system/user procedures. More...
 

Typedefs

typedef assorted::FixedString< 60 > ProcName
 Represents a unique name of a procedure. More...
 
typedef uint32_t LocalProcId
 Represents a locally-unique ID of a procedure in one SOC. More...
 
typedef uint64_t GlobalProcId
 A globally unique ID of a procedure. More...
 
typedef ErrorStack(* Proc) (const ProcArguments &args)
 A function pointer of a user/system stored procedure. More...
 
typedef std::pair< ProcName, ProcProcAndName
 Just a std::pair<ProcName, Proc>. More...
 

Functions

GlobalProcId combined_global_proc_id (uint16_t node, LocalProcId local_id)
 
uint16_t extract_numa_node_from_global_proc_id (GlobalProcId id)
 
LocalProcId extract_local_id_from_global_proc_id (GlobalProcId id)
 

Variables

const LocalProcId kLocalProcInvalid = -1
 

Function Documentation

GlobalProcId foedus::proc::combined_global_proc_id ( uint16_t  node,
LocalProcId  local_id 
)
inline

Definition at line 67 of file proc_id.hpp.

67  {
68  return static_cast<GlobalProcId>(node) << 32 | local_id;
69 }
uint64_t GlobalProcId
A globally unique ID of a procedure.
Definition: proc_id.hpp:65
LocalProcId foedus::proc::extract_local_id_from_global_proc_id ( GlobalProcId  id)
inline

Definition at line 73 of file proc_id.hpp.

73  {
74  return static_cast<LocalProcId>(id);
75 }
uint32_t LocalProcId
Represents a locally-unique ID of a procedure in one SOC.
Definition: proc_id.hpp:56
uint16_t foedus::proc::extract_numa_node_from_global_proc_id ( GlobalProcId  id)
inline

Definition at line 70 of file proc_id.hpp.

70  {
71  return static_cast<uint16_t>(id >> 32);
72 }

Variable Documentation