Derecho  0.9
Distributed systems toolkit for RDMA
Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
derecho::Group< ReplicatedTypes > Class Template Reference

The top-level object for creating a Derecho group. More...

#include <group.hpp>

Inheritance diagram for derecho::Group< ReplicatedTypes >:
Inheritance graph
[legend]
Collaboration diagram for derecho::Group< ReplicatedTypes >:
Collaboration graph
[legend]

Public Member Functions

void set_replicated_pointer (std::type_index type, uint32_t subgroup_num, void **ret)
 
void set_external_caller_pointer (std::type_index type, uint32_t subgroup_num, void **ret)
 
 Group (const CallbackSet &callbacks, const SubgroupInfo &subgroup_info, IDeserializationContext *deserialization_context, std::vector< view_upcall_t > _view_upcalls={}, Factory< ReplicatedTypes >... factories)
 Constructor that starts a new managed Derecho group with this node as the leader. More...
 
 Group (const SubgroupInfo &subgroup_info, Factory< ReplicatedTypes >... factories)
 Constructor that starts a new managed Derecho group with this node as the leader. More...
 
 ~Group ()
 
template<typename SubgroupType >
Replicated< SubgroupType > & get_subgroup (uint32_t subgroup_index=0)
 Gets the "handle" for the subgroup of the specified type and index, which is a Replicated<T>, assuming this node is a member of the desired subgroup. More...
 
template<typename SubgroupType >
ExternalCaller< SubgroupType > & get_nonmember_subgroup (uint32_t subgroup_index=0)
 Gets the "handle" for a subgroup of the specified type and index, assuming this node is not a member of the subgroup. More...
 
template<typename SubgroupType >
ShardIterator< SubgroupType > get_shard_iterator (uint32_t subgroup_index=0)
 
void leave (bool group_shutdown=true)
 Causes this node to cleanly leave the group by setting itself to "failed.". More...
 
std::vector< node_id_tget_members ()
 Returns a vector listing the nodes that are currently members of the group. More...
 
template<typename SubgroupType >
std::vector< std::vector< node_id_t > > get_subgroup_members (uint32_t subgroup_index=0)
 Gets a list of the nodes currently assigned to the subgroup of the specified type and index, organized by shard. More...
 
std::int32_t get_my_rank ()
 Returns the order of this node in the sequence of members of the group. More...
 
node_id_t get_my_id ()
 Returns the id of local node. More...
 
template<typename SubgroupType >
std::int32_t get_my_shard (uint32_t subgroup_index=0)
 Returns the shard number that this node is a member of in the specified subgroup (by subgroup type and index), or -1 if this node is not a member of any shard in the specified subgroup. More...
 
void report_failure (const node_id_t who)
 Reports to the GMS that the given node has failed. More...
 
void barrier_sync ()
 Waits until all members of the group have called this function. More...
 
void debug_print_status () const
 
template<typename SubgroupType >
int32_t get_my_shard (uint32_t subgroup_index)
 
- Public Member Functions inherited from derecho::_Group
virtual ~_Group ()=default
 
template<typename SubgroupType >
auto & get_subgroup (uint32_t subgroup_num=0)
 
template<typename SubgroupType >
auto & get_nonmember_subgroup (uint32_t subgroup_num=0)
 
template<typename SubgroupType >
std::size_t get_number_of_shards (uint32_t subgroup_index=0)
 
template<typename SubgroupType >
std::vector< std::vector< node_id_t > > get_subgroup_members (uint32_t subgroup_index=0)
 
- Public Member Functions inherited from derecho::GroupProjection< ReplicatedTypes >
Replicated< ReplicatedTypes > & get_subgroup (uint32_t subgroup_num=0)
 
ExternalCaller< ReplicatedTypes > & get_nonmember_subgroup (uint32_t subgroup_index=0)
 
std::vector< std::vector< node_id_t > > get_subgroup_members (uint32_t subgroup_index=0)
 
std::size_t get_number_of_shards (uint32_t subgroup_index=0)
 

Protected Member Functions

uint32_t get_index_of_type (const std::type_info &) override
 
ViewManagerget_view_manager () override
 

Private Types

using pred_handle = sst::Predicates< DerechoSST >::pred_handle
 
template<typename T >
using external_caller_index_map = std::map< uint32_t, ExternalCaller< T > >
 

Private Member Functions

void receive_objects (const std::set< std::pair< subgroup_id_t, node_id_t >> &subgroups_and_leaders)
 Updates the state of the replicated objects that correspond to subgroups identified in the provided map, by receiving serialized state from the shard leader whose ID is paired with that subgroup ID. More...
 
void set_up_components ()
 Constructor helper that wires together the component objects of Group. More...
 
template<typename... Empty>
std::enable_if_t< 0==sizeof...(Empty), std::set< std::pair< subgroup_id_t, node_id_t > > > construct_objects (const View &, const vector_int64_2d &)
 Base case for the construct_objects template. More...
 
template<typename FirstType , typename... RestTypes>
std::set< std::pair< subgroup_id_t, node_id_t > > construct_objects (const View &curr_view, const vector_int64_2d &old_shard_leaders)
 Constructor helper that unpacks this Group's template parameter pack. More...
 

Private Attributes

const node_id_t my_id
 
bool is_starting_leader
 
std::optional< tcp::socketleader_connection
 
IDeserializationContextuser_deserialization_context
 The shared pointer holding deserialization context is obsolete. More...
 
PersistenceManager persistence_manager
 Persist the objects. More...
 
std::shared_ptr< tcp::tcp_connectionstcp_sockets
 Contains a TCP connection to each member of the group, for the purpose of transferring state information to new members during a view change. More...
 
ViewManager view_manager
 Contains all state related to managing Views, including the MulticastGroup and SST (since those change when the view changes). More...
 
rpc::RPCManager rpc_manager
 Contains all state related to receiving and handling RPC function calls for any Replicated objects implemented by this group. More...
 
mutils::KindMap< Factory, ReplicatedTypes... > factories
 Maps a type to the Factory for that type. More...
 
mutils::KindMap< replicated_index_map, ReplicatedTypes... > replicated_objects
 Maps each type T to a map of (index -> Replicated<T>) for that type's subgroup(s). More...
 
mutils::KindMap< external_caller_index_map, ReplicatedTypes... > external_callers
 Maps each type T to a map of (index -> ExternalCaller<T>) for the subgroup(s) of that type that this node is not a member of. More...
 
std::map< subgroup_id_t, std::reference_wrapper< ReplicatedObject > > objects_by_subgroup_id
 Alternate view of the Replicated<T>s, indexed by subgroup ID. More...
 

Detailed Description

template<typename... ReplicatedTypes>
class derecho::Group< ReplicatedTypes >

The top-level object for creating a Derecho group.

This implements the group management service (GMS) features and contains a MulticastGroup instance that manages the actual sending and tracking of messages within the group.

Template Parameters
ReplicatedTypesThe types of user-provided objects that will represent state and RPC functions for subgroups of this group.

Definition at line 122 of file group.hpp.

Member Typedef Documentation

◆ external_caller_index_map

template<typename... ReplicatedTypes>
template<typename T >
using derecho::Group< ReplicatedTypes >::external_caller_index_map = std::map<uint32_t, ExternalCaller<T> >
private

Definition at line 136 of file group.hpp.

◆ pred_handle

template<typename... ReplicatedTypes>
using derecho::Group< ReplicatedTypes >::pred_handle = sst::Predicates<DerechoSST>::pred_handle
private

Definition at line 132 of file group.hpp.

Constructor & Destructor Documentation

◆ Group() [1/2]

template<typename... ReplicatedTypes>
derecho::Group< ReplicatedTypes >::Group ( const CallbackSet callbacks,
const SubgroupInfo subgroup_info,
IDeserializationContext deserialization_context,
std::vector< view_upcall_t _view_upcalls = {},
Factory< ReplicatedTypes >...  factories 
)

Constructor that starts a new managed Derecho group with this node as the leader.

Parameters
callbacksThe set of callback functions for message delivery events in this group.
subgroup_infoThe set of functions that define how membership in each subgroup and shard will be determined in this group.
deserialization_contextThe context used for deserialization purpose. The application is responsible to keep it alive during Group object lifetime.
_view_upcallsA list of functions to be called when the group experiences a View-Change event (optional).
factoriesA variable number of Factory functions, one for each template parameter of Group, providing a way to construct instances of each Replicated Object

Definition at line 119 of file group_impl.hpp.

◆ Group() [2/2]

template<typename... ReplicatedTypes>
derecho::Group< ReplicatedTypes >::Group ( const SubgroupInfo subgroup_info,
Factory< ReplicatedTypes >...  factories 
)

Constructor that starts a new managed Derecho group with this node as the leader.

Parameters
subgroup_infoThe set of functions that define how membership in each subgroup and shard will be determined in this group.
factoriesA variable number of Factory functions, one for each template parameter of Group, providing a way to construct instances of each Replicated Object

Definition at line 205 of file group_impl.hpp.

◆ ~Group()

template<typename... ReplicatedTypes>
derecho::Group< ReplicatedTypes >::~Group ( )

Definition at line 209 of file group_impl.hpp.

Member Function Documentation

◆ barrier_sync()

template<typename... ReplicatedTypes>
void derecho::Group< ReplicatedTypes >::barrier_sync ( )

Waits until all members of the group have called this function.

Definition at line 431 of file group_impl.hpp.

◆ construct_objects() [1/2]

template<typename... ReplicatedTypes>
template<typename... Empty>
std::enable_if_t<0 == sizeof...(Empty), std::set<std::pair<subgroup_id_t, node_id_t> > > derecho::Group< ReplicatedTypes >::construct_objects ( const View ,
const vector_int64_2d  
)
inlineprivate

Base case for the construct_objects template.

Note that the neat "varargs trick" (defining construct_objects(...) as the base case) doesn't work because varargs can't match const references, and will force a copy constructor on View. So std::enable_if is the only way to match an empty template pack.

Definition at line 219 of file group.hpp.

◆ construct_objects() [2/2]

template<typename... ReplicatedTypes>
template<typename FirstType , typename... RestTypes>
std::set< std::pair< subgroup_id_t, node_id_t > > derecho::Group< ReplicatedTypes >::construct_objects ( const View curr_view,
const vector_int64_2d old_shard_leaders 
)
private

Constructor helper that unpacks this Group's template parameter pack.

Constructs Replicated<T> wrappers for each object being replicated, using the corresponding Factory<T> saved in Group::factories. If this node is not a member of the subgroup for a type T, an "empty" Replicated<T> will be constructed with no corresponding object. If this node is joining an existing group and there was a previous leader for its shard of a subgroup, an "empty" Replicated<T> will also be constructed for that subgroup, since all object state will be received from the shard leader.

Parameters
curr_viewA reference to the current view as reported by View_manager
old_shard_leadersThe array of old shard leaders for each subgroup (indexed by subgroup ID), which will contain -1 if there is no previous leader for that shard.
Returns
The set of subgroup IDs that are un-initialized because this node is joining an existing group and needs to receive initial object state, paired with the ID of the node that should be contacted to receive that state.

Definition at line 220 of file group_impl.hpp.

◆ debug_print_status()

template<typename... ReplicatedTypes>
void derecho::Group< ReplicatedTypes >::debug_print_status ( ) const

Definition at line 436 of file group_impl.hpp.

◆ get_index_of_type()

template<typename... ReplicatedTypes>
uint32_t derecho::Group< ReplicatedTypes >::get_index_of_type ( const std::type_info &  ti)
overrideprotectedvirtual

Implements derecho::_Group.

Definition at line 93 of file group_impl.hpp.

◆ get_members()

template<typename... ReplicatedTypes>
std::vector< node_id_t > derecho::Group< ReplicatedTypes >::get_members ( )

Returns a vector listing the nodes that are currently members of the group.

Definition at line 405 of file group_impl.hpp.

◆ get_my_id()

template<typename... ReplicatedTypes>
node_id_t derecho::Group< ReplicatedTypes >::get_my_id ( )

Returns the id of local node.

Definition at line 426 of file group_impl.hpp.

◆ get_my_rank()

template<typename... ReplicatedTypes>
int32_t derecho::Group< ReplicatedTypes >::get_my_rank ( )

Returns the order of this node in the sequence of members of the group.

Definition at line 421 of file group_impl.hpp.

◆ get_my_shard() [1/2]

template<typename... ReplicatedTypes>
template<typename SubgroupType >
std::int32_t derecho::Group< ReplicatedTypes >::get_my_shard ( uint32_t  subgroup_index = 0)

Returns the shard number that this node is a member of in the specified subgroup (by subgroup type and index), or -1 if this node is not a member of any shard in the specified subgroup.

◆ get_my_shard() [2/2]

template<typename... ReplicatedTypes>
template<typename SubgroupType >
int32_t derecho::Group< ReplicatedTypes >::get_my_shard ( uint32_t  subgroup_index)

Definition at line 416 of file group_impl.hpp.

◆ get_nonmember_subgroup()

template<typename... ReplicatedTypes>
template<typename SubgroupType >
ExternalCaller< SubgroupType > & derecho::Group< ReplicatedTypes >::get_nonmember_subgroup ( uint32_t  subgroup_index = 0)

Gets the "handle" for a subgroup of the specified type and index, assuming this node is not a member of the subgroup.

The returned ExternalCaller can be used to make peer-to-peer RPC calls to a specific member of the subgroup.

Parameters
subgroup_indexThe index of the subgroup within the set of subgroups that replicate the same type of object.
Template Parameters
SubgroupTypeThe object type identifying the subgroup
Returns
A reference to the ExternalCaller for this subgroup
Exceptions
invalid_subgroup_exceptionIf this node is actually a member of the requested subgroup, or if no such subgroup exists

Definition at line 335 of file group_impl.hpp.

◆ get_shard_iterator()

template<typename... ReplicatedTypes>
template<typename SubgroupType >
ShardIterator< SubgroupType > derecho::Group< ReplicatedTypes >::get_shard_iterator ( uint32_t  subgroup_index = 0)

Definition at line 345 of file group_impl.hpp.

◆ get_subgroup()

template<typename... ReplicatedTypes>
template<typename SubgroupType >
Replicated< SubgroupType > & derecho::Group< ReplicatedTypes >::get_subgroup ( uint32_t  subgroup_index = 0)

Gets the "handle" for the subgroup of the specified type and index, which is a Replicated<T>, assuming this node is a member of the desired subgroup.

The Replicated<T> will contain the replicated state of an object of type T (if it has any state) and be usable to send multicasts to this node's shard of the subgroup.

Parameters
subgroup_indexThe index of the subgroup within the set of subgroups that replicate the same type of object. Defaults to 0, so if there is only one subgroup of type T, it can be retrieved with get_subgroup<T>();
Template Parameters
SubgroupTypeThe object type identifying the subgroup
Returns
A reference to a Replicated<SubgroupType>
Exceptions
subgroup_provisioning_exceptionIf there are no subgroups because the current View is inadequately provisioned
invalid_subgroup_exceptionIf this node is not a member of the requested subgroup.

Definition at line 322 of file group_impl.hpp.

◆ get_subgroup_members()

template<typename... ReplicatedTypes>
template<typename SubgroupType >
std::vector< std::vector< node_id_t > > derecho::Group< ReplicatedTypes >::get_subgroup_members ( uint32_t  subgroup_index = 0)

Gets a list of the nodes currently assigned to the subgroup of the specified type and index, organized by shard.

The outer vector has an entry for each shard in the subgroup, and the vector at each position contains the IDs of the nodes in that shard.

Definition at line 411 of file group_impl.hpp.

◆ get_view_manager()

template<typename... ReplicatedTypes>
ViewManager & derecho::Group< ReplicatedTypes >::get_view_manager ( )
overrideprotectedvirtual

Implements derecho::GroupProjection< ReplicatedTypes >.

Definition at line 103 of file group_impl.hpp.

◆ leave()

template<typename... ReplicatedTypes>
void derecho::Group< ReplicatedTypes >::leave ( bool  group_shutdown = true)

Causes this node to cleanly leave the group by setting itself to "failed.".

Parameters
group_shutdownTrue if all nodes in the group are going to leave.

Definition at line 396 of file group_impl.hpp.

◆ receive_objects()

template<typename... ReplicatedTypes>
void derecho::Group< ReplicatedTypes >::receive_objects ( const std::set< std::pair< subgroup_id_t, node_id_t >> &  subgroups_and_leaders)
private

Updates the state of the replicated objects that correspond to subgroups identified in the provided map, by receiving serialized state from the shard leader whose ID is paired with that subgroup ID.

Parameters
subgroups_and_leadersPairs of (subgroup ID, leader's node ID) for subgroups that need to have their state initialized from the leader.

Definition at line 364 of file group_impl.hpp.

◆ report_failure()

template<typename... ReplicatedTypes>
void derecho::Group< ReplicatedTypes >::report_failure ( const node_id_t  who)

Reports to the GMS that the given node has failed.

Definition at line 391 of file group_impl.hpp.

◆ set_external_caller_pointer()

template<typename... ReplicatedTypes>
void derecho::Group< ReplicatedTypes >::set_external_caller_pointer ( std::type_index  type,
uint32_t  subgroup_num,
void **  ret 
)
virtual

Implements derecho::GroupProjection< ReplicatedTypes >.

Definition at line 108 of file group_impl.hpp.

◆ set_replicated_pointer()

template<typename... ReplicatedTypes>
void derecho::Group< ReplicatedTypes >::set_replicated_pointer ( std::type_index  type,
uint32_t  subgroup_num,
void **  ret 
)
virtual

Implements derecho::GroupProjection< ReplicatedTypes >.

Definition at line 83 of file group_impl.hpp.

◆ set_up_components()

template<typename... ReplicatedTypes>
void derecho::Group< ReplicatedTypes >::set_up_components ( )
private

Constructor helper that wires together the component objects of Group.

Definition at line 299 of file group_impl.hpp.

Member Data Documentation

◆ external_callers

template<typename... ReplicatedTypes>
mutils::KindMap<external_caller_index_map, ReplicatedTypes...> derecho::Group< ReplicatedTypes >::external_callers
private

Maps each type T to a map of (index -> ExternalCaller<T>) for the subgroup(s) of that type that this node is not a member of.

The ExternalCaller for subgroup i of type T can be used to contact any member of any shard of that subgroup, so shards are not indexed.

Definition at line 182 of file group.hpp.

◆ factories

template<typename... ReplicatedTypes>
mutils::KindMap<Factory, ReplicatedTypes...> derecho::Group< ReplicatedTypes >::factories
private

Maps a type to the Factory for that type.

Definition at line 166 of file group.hpp.

◆ is_starting_leader

template<typename... ReplicatedTypes>
bool derecho::Group< ReplicatedTypes >::is_starting_leader
private

Definition at line 139 of file group.hpp.

◆ leader_connection

template<typename... ReplicatedTypes>
std::optional<tcp::socket> derecho::Group< ReplicatedTypes >::leader_connection
private

Definition at line 140 of file group.hpp.

◆ my_id

template<typename... ReplicatedTypes>
const node_id_t derecho::Group< ReplicatedTypes >::my_id
private

Definition at line 138 of file group.hpp.

◆ objects_by_subgroup_id

template<typename... ReplicatedTypes>
std::map<subgroup_id_t, std::reference_wrapper<ReplicatedObject> > derecho::Group< ReplicatedTypes >::objects_by_subgroup_id
private

Alternate view of the Replicated<T>s, indexed by subgroup ID.

The entry at index X is a reference to the Replicated<T> for this node's shard of subgroup X, which may or may not be valid. The references are the abstract base type ReplicatedObject because they are only used for state transfer, not ordered sends. Since the values in this map are references to objects that are owned by replicated_objects, it is NOT thread-safe to use it outside of view_manager's predicates - a reference may become temporarily null during a view change if the Replicated<T> it points to is deleted by the view change. Note that this is a std::map solely so that we can initialize it out-of-order; its keys are continuous integers starting at 0 and it should be a std::vector.

Definition at line 195 of file group.hpp.

◆ persistence_manager

template<typename... ReplicatedTypes>
PersistenceManager derecho::Group< ReplicatedTypes >::persistence_manager
private

Persist the objects.

Once persisted, persistence_manager updates the SST so that the persistent progress is known by group members.

Definition at line 154 of file group.hpp.

◆ replicated_objects

template<typename... ReplicatedTypes>
mutils::KindMap<replicated_index_map, ReplicatedTypes...> derecho::Group< ReplicatedTypes >::replicated_objects
private

Maps each type T to a map of (index -> Replicated<T>) for that type's subgroup(s).

If this node is not a member of a subgroup for a type, the map will have no entry for that type and index. (Instead, external_callers will have an entry for that type-index pair). If this node is a member of a subgroup, the Replicated<T> will refer to the one shard that this node belongs to.

Definition at line 175 of file group.hpp.

◆ rpc_manager

template<typename... ReplicatedTypes>
rpc::RPCManager derecho::Group< ReplicatedTypes >::rpc_manager
private

Contains all state related to receiving and handling RPC function calls for any Replicated objects implemented by this group.

Definition at line 164 of file group.hpp.

◆ tcp_sockets

template<typename... ReplicatedTypes>
std::shared_ptr<tcp::tcp_connections> derecho::Group< ReplicatedTypes >::tcp_sockets
private

Contains a TCP connection to each member of the group, for the purpose of transferring state information to new members during a view change.

This connection pool is shared between Group and ViewManager

Definition at line 158 of file group.hpp.

◆ user_deserialization_context

template<typename... ReplicatedTypes>
IDeserializationContext* derecho::Group< ReplicatedTypes >::user_deserialization_context
private

The shared pointer holding deserialization context is obsolete.

I (Weijia) removed it because it complicated things: the deserialization context is generally a big object containing the group handle; however, the group handle need to hold a shared pointer to the object, which causes a dependency loop and results in an object indirectly holding a shared pointer to its self. Another side effect is double free. So I change it back to the raw pointer. The user deserialization context for all objects serialized and deserialized.

Definition at line 150 of file group.hpp.

◆ view_manager

template<typename... ReplicatedTypes>
ViewManager derecho::Group< ReplicatedTypes >::view_manager
private

Contains all state related to managing Views, including the MulticastGroup and SST (since those change when the view changes).

Definition at line 161 of file group.hpp.


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