16 #include "../derecho_type_definitions.hpp" 17 #include "../view.hpp" 43 static_assert(std::is_trivially_copyable<Opcode>::value,
"Oh no! Opcode is not trivially copyable!");
50 std::unique_ptr<std::map<Opcode, receive_fun_t>>
receivers;
57 friend class ::derecho::Replicated;
59 friend class ::derecho::ExternalCaller;
78 bool thread_start =
false;
83 std::atomic<bool> thread_shutdown{
false};
96 uint32_t _buffer_size) : sender_id(_sender_id),
98 buffer_size(_buffer_size) {}
105 void p2p_receive_loop();
117 void p2p_message_handler(
node_id_t sender_id,
char* msg_buf, uint32_t buffer_size);
132 std::exception_ptr receive_message(
const Opcode& indx,
const node_id_t& received_from,
133 char const*
const buf, std::size_t payload_size,
134 const std::function<
char*(
int)>& out_alloc);
147 std::exception_ptr parse_and_receive(
char* buf, std::size_t size,
148 const std::function<
char*(
int)>& out_alloc);
155 receivers(new
std::decay_t<decltype(*receivers)>()),
156 view_manager(group_view_manager) {
157 if(deserialization_context_ptr !=
nullptr) {
158 rdv.push_back(deserialization_context_ptr);
160 rpc_thread = std::thread(&RPCManager::p2p_receive_loop,
this);
165 void create_connections();
171 void start_listening();
192 template <
typename UserProv
idedClass,
typename FunctionTuple>
197 return mutils::callFunc([&](
const auto&... unpacked_functions) {
198 return build_remote_invocable_class<UserProvidedClass>(nid, type_id, instance_id, *receivers,
204 void destroy_remote_invocable_class(uint32_t instance_id);
224 template <
typename UserProv
idedClass,
typename FunctionTuple>
226 return mutils::callFunc([&](
const auto&... unpacked_functions) {
230 decltype(
bind_to_instance(std::declval<std::unique_ptr<UserProvidedClass>*>(),
231 unpacked_functions))...>(nid, type_id,
232 instance_id, *receivers);
244 void new_view_callback(
const View& new_view);
258 char* msg_buf, uint32_t buffer_size);
293 template <
typename T>
295 .make_remote_invocable_class(std::declval<std::unique_ptr<T>*>(),
296 std::declval<uint32_t>(),
297 std::declval<uint32_t>(),
298 T::register_functions()))>;
300 template <
typename T>
302 .make_remote_invoker<T>(std::declval<uint32_t>(),
303 std::declval<uint32_t>(),
304 T::register_functions()))>;
uint32_t subgroup_id_t
Type alias for the internal Subgroup IDs generated by ViewManager.
The Deserialization Interface to be implemented by user applications.
wrapped< Tag, std::function< Ret(Args...)> > bind_to_instance(std::unique_ptr< NewClass > *_this, const partial_wrapped< Tag, Ret, NewClass, Args... > &partial)
Converts a partial_wrapped<> containing a pointer-to-member-function to a wrapped<> containing the sa...
std::condition_variable thread_start_cv
Notified when the P2P listening thread should start.
An RPC function call can be uniquely identified by the tuple (class, subgroup ID, function ID...
std::map< subgroup_id_t, std::queue< PendingBase_ref > > pending_results_to_fulfill
bool in_rpc_handler()
defined in rpc_manager.h
std::map< subgroup_id_t, std::list< PendingBase_ref > > fulfilled_pending_results
std::unique_ptr< sst::P2PConnections > connections
Contains an RDMA connection to each member of the group.
const uint32_t getConfUInt32(const std::string &key)
const node_id_t nid
The ID of the node this RPCManager is running on.
std::decay_t< decltype(*std::declval< RPCManager >() .make_remote_invocable_class(std::declval< std::unique_ptr< T > * >(), std::declval< uint32_t >(), std::declval< uint32_t >(), T::register_functions()))> RemoteInvocableOf
auto build_remote_invoker_for_class(const node_id_t nid, const uint32_t type_id, const uint32_t instance_id, std::map< Opcode, receive_fun_t > &rvrs)
Constructs a RemoteInvokerForClass that can act as a client for the class in the template parameter (...
std::mutex fifo_queue_mutex
std::mutex pending_results_mutex
This mutex guards both toFulfillQueue and fulfilledList.
std::thread fifo_worker_thread
p2p send and queries are queued in fifo worker
fifo_req(node_id_t _sender_id, char *_msg_buf, uint32_t _buffer_size)
auto make_remote_invoker(uint32_t type_id, uint32_t instance_id, FunctionTuple funs)
Given a subgroup ID and a list of functions, constructs a RemoteInvokerForClass for the type of objec...
ViewManager & view_manager
std::reference_wrapper< PendingBase > PendingBase_ref
uint32_t node_id_t
Type alias for Node IDs in a Derecho group.
std::mutex thread_start_mutex
Mutex for thread_start_cv.
std::vector< RemoteDeserializationContext_p > RemoteDeserialization_v
std::mutex p2p_connections_mutex
This provides mutual exclusion between the P2P listening thread and the view-change thread...
std::decay_t< decltype(*std::declval< RPCManager >() .make_remote_invoker< T >(std::declval< uint32_t >(), std::declval< uint32_t >(), T::register_functions()))> RemoteInvokerFor
auto make_remote_invocable_class(std::unique_ptr< UserProvidedClass > *cls, uint32_t type_id, uint32_t instance_id, FunctionTuple funs)
Given a pointer to an object and a list of its methods, constructs a RemoteInvocableClass for that ob...
Abstract base type for PendingResults.
RPCManager(ViewManager &group_view_manager, IDeserializationContext *deserialization_context_ptr)
mutils::RemoteDeserialization_v rdv
An emtpy DeserializationManager, in case we need it later.
#define CONF_DERECHO_LOCAL_ID
If a class which implements ByteRepresentable requires a context in order to correctly deserialize...
std::condition_variable fifo_queue_cv
std::unique_ptr< std::map< Opcode, receive_fun_t > > receivers
A map from FunctionIDs to RPC functions, either the "server" stubs that receive remote calls to invok...
std::queue< fifo_req > fifo_queue
std::condition_variable pending_results_cv
This condition variable is to resolve a race condition in using ToFulfillQueue and fulfilledList...