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

#include <rpc_manager.hpp>

Inheritance diagram for derecho::Replicated< T >:
Inheritance graph
[legend]
Collaboration diagram for derecho::Replicated< T >:
Collaboration graph
[legend]

Public Member Functions

 Replicated (subgroup_type_id_t type_id, node_id_t nid, subgroup_id_t subgroup_id, uint32_t subgroup_index, uint32_t shard_num, rpc::RPCManager &group_rpc_manager, Factory< T > client_object_factory, _Group *group)
 Constructs a Replicated<T> that enables sending and receiving RPC function calls for an object of type T. More...
 
 Replicated (subgroup_type_id_t type_id, node_id_t nid, subgroup_id_t subgroup_id, uint32_t subgroup_index, uint32_t shard_num, rpc::RPCManager &group_rpc_manager, _Group *group)
 Constructs a Replicated<T> for an object without actually constructing an instance of that object; the resulting Replicated will be in an invalid state until receive_object() is called. More...
 
 Replicated (Replicated &&rhs)
 
 Replicated (const Replicated &)=delete
 
virtual ~Replicated ()
 
virtual bool is_persistent () const
 
bool is_valid () const
 
uint32_t get_shard_num () const
 
template<rpc::FunctionTag tag, typename... Args>
auto p2p_send (node_id_t dest_node, Args &&... args)
 Sends a peer-to-peer message to a single member of the subgroup that replicates this Replicated<T>, invoking the RPC function identified by the FunctionTag template parameter. More...
 
template<rpc::FunctionTag tag, typename... Args>
auto ordered_send (Args &&... args)
 Sends a multicast to the entire subgroup that replicates this Replicated<T>, invoking the RPC function identified by the FunctionTag template parameter. More...
 
void send (unsigned long long int payload_size, const std::function< void(char *buf)> &msg_generator)
 Submits a call to send a "raw" (byte array) message in a multicast to this object's subgroup; the message will be generated by invoking msg_generator inside this function. More...
 
std::size_t object_size () const
 
void send_object (tcp::socket &receiver_socket) const
 Serializes and sends the state of the "wrapped" object (of type T) for this Replicated<T> over the given socket. More...
 
void send_object_raw (tcp::socket &receiver_socket) const
 Serializes and sends the state of the "wrapped" object (of type T) for this Replicated<T> over the given socket without first sending its size. More...
 
std::size_t receive_object (char *buffer)
 Updates the state of the "wrapped" object by replacing it with the object serialized in a buffer. More...
 
const uint64_t compute_global_stability_frontier ()
 
const HLC getFrontier ()
 
const persistent::version_t get_minimum_latest_persisted_version () noexcept(false)
 Returns the minimum among the "latest version" numbers of all Persistent fields of this object, i.e. More...
 
virtual void make_version (const persistent::version_t &ver, const HLC &hlc) noexcept(false)
 make a version for all the persistent<T> members. More...
 
virtual void persist (const persistent::version_t version) noexcept(false)
 persist the data to the latest version More...
 
virtual void trim (const persistent::version_t &earliest_version) noexcept(false)
 trim the logs to a version, inclusively. More...
 
virtual void truncate (const persistent::version_t &latest_version)
 Truncate the logs of all Persistent<T> members back to the version specified. More...
 
virtual void post_next_version (const persistent::version_t &version, const uint64_t &ts_us)
 Post the next version to be handled. More...
 
virtual std::tuple< persistent::version_t, uint64_t > get_next_version ()
 Get the next version to be handled. More...
 
virtual void register_persistent_member (const char *object_name, const persistent::VersionFunc &vf, const persistent::PersistFunc &pf, const persistent::TrimFunc &tf, const persistent::LatestPersistedGetterFunc &gf, persistent::TruncateFunc tcf) noexcept(false)
 Register a persistent member. More...
 
- Public Member Functions inherited from derecho::ReplicatedObject
virtual ~ReplicatedObject ()=default
 

Public Attributes

std::unique_ptr< std::unique_ptr< T > > user_object_ptr
 The user-provided state object with some RPC methods. More...
 

Private Attributes

std::unique_ptr< persistent::PersistentRegistrypersistent_registry_ptr
 persistent registry for persistent<t> More...
 
const node_id_t node_id
 The ID of this node. More...
 
const subgroup_id_t subgroup_id
 The internally-generated subgroup ID of the subgroup that replicates this object. More...
 
const uint32_t subgroup_index
 
const uint32_t shard_num
 The index, within the subgroup, of the shard that replicates this object. More...
 
rpc::RPCManagergroup_rpc_manager
 Reference to the RPCManager for the Group this Replicated is in. More...
 
std::unique_ptr< rpc::RemoteInvocableOf< T > > wrapped_this
 The actual implementation of Replicated<T>, hiding its ugly template parameters. More...
 
_Groupgroup
 
persistent::version_t next_version = INVALID_VERSION
 The version number being processed and corresponding timestamp. More...
 
uint64_t next_timestamp_us = 0
 

Detailed Description

template<typename T>
class derecho::Replicated< T >

Definition at line 29 of file rpc_manager.hpp.

Constructor & Destructor Documentation

◆ Replicated() [1/4]

template<typename T >
derecho::Replicated< T >::Replicated ( subgroup_type_id_t  type_id,
node_id_t  nid,
subgroup_id_t  subgroup_id,
uint32_t  subgroup_index,
uint32_t  shard_num,
rpc::RPCManager group_rpc_manager,
Factory< T >  client_object_factory,
_Group group 
)

Constructs a Replicated<T> that enables sending and receiving RPC function calls for an object of type T.

Parameters
type_idA unique ID for type T within the Group that owns this Replicated<T>
nidThe ID of the node on which this Replicated<T> is running.
subgroup_idThe internally-generated subgroup ID for the subgroup that participates in replicating this object
subgroup_indexThe index of the subgroup that replicates this object within (only) the set of subgroups that replicate type T; zero-indexed.
shard_numThe zero-indexed shard number of the shard (within subgroup subgroup_id) that participates in replicating this object
group_rpc_managerA reference to the RPCManager for the Group that owns this Replicated<T>
client_object_factoryA factory functor that can create instances of T.

Definition at line 14 of file replicated_impl.hpp.

◆ Replicated() [2/4]

template<typename T >
derecho::Replicated< T >::Replicated ( subgroup_type_id_t  type_id,
node_id_t  nid,
subgroup_id_t  subgroup_id,
uint32_t  subgroup_index,
uint32_t  shard_num,
rpc::RPCManager group_rpc_manager,
_Group group 
)

Constructs a Replicated<T> for an object without actually constructing an instance of that object; the resulting Replicated will be in an invalid state until receive_object() is called.

This should be used when a new subgroup member expects to receive the replicated object's state after joining.

Parameters
type_idA unique ID for type T within the Group that owns this Replicated<T>
nidThis node's node ID
subgroup_idThe internally-generated subgroup ID for the subgroup that participates in replicating this object
subgroup_indexThe index of the subgroup that replicates this object within (only) the set of subgroups that replicate type T; zero-indexed.
shard_numThe zero-indexed shard number of the shard (within subgroup subgroup_id) that participates in replicating this object
group_rpc_managerA reference to the RPCManager for the Group that owns this Replicated<T>

Definition at line 37 of file replicated_impl.hpp.

◆ Replicated() [3/4]

template<typename T >
derecho::Replicated< T >::Replicated ( Replicated< T > &&  rhs)

Definition at line 54 of file replicated_impl.hpp.

◆ Replicated() [4/4]

template<typename T>
derecho::Replicated< T >::Replicated ( const Replicated< T > &  )
delete

◆ ~Replicated()

template<typename T >
derecho::Replicated< T >::~Replicated ( )
virtual

Definition at line 67 of file replicated_impl.hpp.

Member Function Documentation

◆ compute_global_stability_frontier()

template<typename T >
const uint64_t derecho::Replicated< T >::compute_global_stability_frontier ( )

Definition at line 200 of file replicated_impl.hpp.

◆ get_minimum_latest_persisted_version()

template<typename T >
const persistent::version_t derecho::Replicated< T >::get_minimum_latest_persisted_version ( )
virtualnoexcept

Returns the minimum among the "latest version" numbers of all Persistent fields of this object, i.e.

the longest consistent cut of all the logs.

Returns
A version number

Implements derecho::ReplicatedObject.

Definition at line 195 of file replicated_impl.hpp.

◆ get_next_version()

template<typename T>
virtual std::tuple<persistent::version_t,uint64_t> derecho::Replicated< T >::get_next_version ( )
inlinevirtual

Get the next version to be handled.

Definition at line 298 of file replicated.hpp.

◆ get_shard_num()

template<typename T>
uint32_t derecho::Replicated< T >::get_shard_num ( ) const
inline
Returns
The shard of the Replicated<T>'s subgroup that the current node belongs to, and that this Replicated<T> updates when it sends multicasts.

Definition at line 170 of file replicated.hpp.

◆ getFrontier()

template<typename T>
const HLC derecho::Replicated< T >::getFrontier ( )
inlinevirtual

Implements persistent::ITemporalQueryFrontierProvider.

Definition at line 242 of file replicated.hpp.

◆ is_persistent()

template<typename T>
virtual bool derecho::Replicated< T >::is_persistent ( ) const
inlinevirtual
Returns
The value of has_persistent_fields<T> for this Replicated<T>'s template parameter. This is true if any field of the user object T is persistent.

Implements derecho::ReplicatedObject.

Definition at line 153 of file replicated.hpp.

◆ is_valid()

template<typename T>
bool derecho::Replicated< T >::is_valid ( ) const
inlinevirtual
Returns
True if this Replicated<T> actually contains a reference to a replicated object, false if it is "empty" because this node is not a member of the subgroup that replicates T.

Implements derecho::ReplicatedObject.

Definition at line 162 of file replicated.hpp.

◆ make_version()

template<typename T>
virtual void derecho::Replicated< T >::make_version ( const persistent::version_t ver,
const HLC hlc 
)
inlinevirtualnoexcept

make a version for all the persistent<T> members.

Parameters
ver- the version number to be made

Implements derecho::ReplicatedObject.

Definition at line 259 of file replicated.hpp.

◆ object_size()

template<typename T >
std::size_t derecho::Replicated< T >::object_size ( ) const
virtual
Returns
The serialized size of the object, of type T, that holds the state of this Replicated<T>.

Implements derecho::ReplicatedObject.

Definition at line 145 of file replicated_impl.hpp.

◆ ordered_send()

template<typename T >
template<rpc::FunctionTag tag, typename... Args>
auto derecho::Replicated< T >::ordered_send ( Args &&...  args)

Sends a multicast to the entire subgroup that replicates this Replicated<T>, invoking the RPC function identified by the FunctionTag template parameter.

The caller must keep the returned QueryResults object in scope in order to receive replies.

Parameters
argsThe arguments to the RPC function
Returns
An instance of rpc::QueryResults<Ret>, where Ret is the return type of the RPC function being invoked.

Definition at line 102 of file replicated_impl.hpp.

◆ p2p_send()

template<typename T >
template<rpc::FunctionTag tag, typename... Args>
auto derecho::Replicated< T >::p2p_send ( node_id_t  dest_node,
Args &&...  args 
)

Sends a peer-to-peer message to a single member of the subgroup that replicates this Replicated<T>, invoking the RPC function identified by the FunctionTag template parameter.

Parameters
dest_nodeThe ID of the node that the P2P message should be sent to
argsThe arguments to the RPC function being invoked
Returns
An instance of rpc::QueryResults<Ret>, where Ret is the return type of the RPC function being invoked

Definition at line 76 of file replicated_impl.hpp.

◆ persist()

template<typename T >
void derecho::Replicated< T >::persist ( const persistent::version_t  version)
virtualnoexcept

persist the data to the latest version

Implements derecho::ReplicatedObject.

Definition at line 180 of file replicated_impl.hpp.

◆ post_next_version()

template<typename T>
virtual void derecho::Replicated< T >::post_next_version ( const persistent::version_t version,
const uint64_t &  ts_us 
)
inlinevirtual

Post the next version to be handled.

Implements derecho::ReplicatedObject.

Definition at line 290 of file replicated.hpp.

◆ receive_object()

template<typename T >
std::size_t derecho::Replicated< T >::receive_object ( char *  buffer)
virtual

Updates the state of the "wrapped" object by replacing it with the object serialized in a buffer.

Returns the number of bytes read from the buffer, in case the caller needs to know.

Parameters
bufferA buffer containing a serialized T, which will replace this Replicated<T>'s wrapped T
Returns
The number of bytes read from the buffer.

Implements derecho::ReplicatedObject.

Definition at line 167 of file replicated_impl.hpp.

◆ register_persistent_member()

template<typename T>
virtual void derecho::Replicated< T >::register_persistent_member ( const char *  object_name,
const persistent::VersionFunc vf,
const persistent::PersistFunc pf,
const persistent::TrimFunc tf,
const persistent::LatestPersistedGetterFunc gf,
persistent::TruncateFunc  tcf 
)
inlinevirtualnoexcept

Register a persistent member.

Parameters
vf- the version function
pf- the persistent function
tf- the trim function

Definition at line 308 of file replicated.hpp.

◆ send()

template<typename T >
void derecho::Replicated< T >::send ( unsigned long long int  payload_size,
const std::function< void(char *buf)> &  msg_generator 
)

Submits a call to send a "raw" (byte array) message in a multicast to this object's subgroup; the message will be generated by invoking msg_generator inside this function.

Definition at line 139 of file replicated_impl.hpp.

◆ send_object()

template<typename T >
void derecho::Replicated< T >::send_object ( tcp::socket receiver_socket) const
virtual

Serializes and sends the state of the "wrapped" object (of type T) for this Replicated<T> over the given socket.

(This includes sending the object's size before its data, so the receiver knows the size of buffer to allocate).

Parameters
receiver_socket

Implements derecho::ReplicatedObject.

Definition at line 150 of file replicated_impl.hpp.

◆ send_object_raw()

template<typename T >
void derecho::Replicated< T >::send_object_raw ( tcp::socket receiver_socket) const
virtual

Serializes and sends the state of the "wrapped" object (of type T) for this Replicated<T> over the given socket without first sending its size.

Should only be used when sending a list of objects, preceded by their total size, otherwise the recipient will have no way of knowing how large a buffer to allocate for this object.

Parameters
receiver_socket

Implements derecho::ReplicatedObject.

Definition at line 159 of file replicated_impl.hpp.

◆ trim()

template<typename T>
virtual void derecho::Replicated< T >::trim ( const persistent::version_t earliest_version)
inlinevirtualnoexcept

trim the logs to a version, inclusively.

Parameters
earliest_version- the version number, before which, logs are going to be trimmed

Definition at line 273 of file replicated.hpp.

◆ truncate()

template<typename T>
virtual void derecho::Replicated< T >::truncate ( const persistent::version_t latest_version)
inlinevirtual

Truncate the logs of all Persistent<T> members back to the version specified.

This deletes recently-used data, so it should only be called during failure recovery when some versions must be rolled back.

Parameters
latest_versionThe latest version number that should remain in the logs

Implements derecho::ReplicatedObject.

Definition at line 283 of file replicated.hpp.

Member Data Documentation

◆ group

template<typename T>
_Group* derecho::Replicated< T >::group
private

Definition at line 96 of file replicated.hpp.

◆ group_rpc_manager

template<typename T>
rpc::RPCManager& derecho::Replicated< T >::group_rpc_manager
private

Reference to the RPCManager for the Group this Replicated is in.

Definition at line 93 of file replicated.hpp.

◆ next_timestamp_us

template<typename T>
uint64_t derecho::Replicated< T >::next_timestamp_us = 0
private

Definition at line 99 of file replicated.hpp.

◆ next_version

template<typename T>
persistent::version_t derecho::Replicated< T >::next_version = INVALID_VERSION
private

The version number being processed and corresponding timestamp.

Definition at line 98 of file replicated.hpp.

◆ node_id

template<typename T>
const node_id_t derecho::Replicated< T >::node_id
private

The ID of this node.

Definition at line 82 of file replicated.hpp.

◆ persistent_registry_ptr

template<typename T>
std::unique_ptr<persistent::PersistentRegistry> derecho::Replicated< T >::persistent_registry_ptr
private

persistent registry for persistent<t>

Definition at line 68 of file replicated.hpp.

◆ shard_num

template<typename T>
const uint32_t derecho::Replicated< T >::shard_num
private

The index, within the subgroup, of the shard that replicates this object.

This needs to be stored in order to detect if a node has moved to a different shard within the same subgroup (and hence its Replicated state is obsolete).

Definition at line 91 of file replicated.hpp.

◆ subgroup_id

template<typename T>
const subgroup_id_t derecho::Replicated< T >::subgroup_id
private

The internally-generated subgroup ID of the subgroup that replicates this object.

Definition at line 84 of file replicated.hpp.

◆ subgroup_index

template<typename T>
const uint32_t derecho::Replicated< T >::subgroup_index
private

Definition at line 85 of file replicated.hpp.

◆ user_object_ptr

template<typename T>
std::unique_ptr<std::unique_ptr<T> > derecho::Replicated< T >::user_object_ptr

The user-provided state object with some RPC methods.

Stored by pointer-to-pointer because it must stay pinned at a specific location in memory, and otherwise Replicated<T> would be unmoveable.

Definition at line 77 of file replicated.hpp.

◆ wrapped_this

template<typename T>
std::unique_ptr<rpc::RemoteInvocableOf<T> > derecho::Replicated< T >::wrapped_this
private

The actual implementation of Replicated<T>, hiding its ugly template parameters.

Definition at line 95 of file replicated.hpp.


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