loc
Loading...
Searching...
No Matches
coordinator.h
1/*
2//@HEADER
3// *****************************************************************************
4// coordinator.h
5// DARMA/loc => Location Coordinator
6// Copyright 2019-2024 NTESS (see LICENSE for full details)
7// *****************************************************************************
8//@HEADER
9*/
10
11#if !defined INCLUDED_LOC_COORDINATOR_H
12#define INCLUDED_LOC_COORDINATOR_H
13
14#include "loc/common.h"
15#include "loc/communicator.h"
16#include "loc/lookup/lookup.h"
17#include "loc/record/record.h"
18
19#include <functional>
20#include <unordered_map>
21#include <unordered_set>
22#include <vector>
23
24namespace loc {
25
47template <typename EntityID, typename Comm>
49 static_assert(
50 Communicator<Comm, Coordinator<EntityID, Comm>>,
51 "Coordinator requires a Comm satisfying loc::Communicator"
52 );
53
54 using ThisType = Coordinator<EntityID, Comm>;
55 using LocRecType = LocRecord<EntityID>;
56 using HandleType = typename Comm::template HandleType<ThisType>;
57 using NodeAction = std::function<void(NodeType)>;
58 using ExistsAction = std::function<void(bool, NodeType)>;
59
66 explicit Coordinator(
67 Comm& in_comm, LocationSizeType in_max_cache_size = default_max_cache_size
68 );
69
70 Coordinator(Coordinator const&) = delete;
71 Coordinator(Coordinator&&) = delete;
72 Coordinator& operator=(Coordinator const&) = delete;
73
80 void registerEntity(EntityID const& id, NodeType home);
81
88 void entityImmigrated(EntityID const& id, NodeType home, NodeType from);
89
96 void entityEmigrated(EntityID const& id, NodeType new_node);
97
101 void unregisterEntity(EntityID const& id);
102
113 void getLocation(EntityID const& id, NodeType home, NodeAction action);
114
122 void entityExists(EntityID const& id, NodeType home, ExistsAction action);
123
125 bool isCached(EntityID const& id) const;
126
128 void clearCache();
129
131 NodeType thisNode() const;
132
133public:
134 //
135 // Control-plane RPC handlers. These are invoked by the communicator on
136 // message receipt (via Comm::send<&handler>); they are not part of the
137 // user-facing API but must be public so their member-pointers are usable.
138 //
139
141 void updateHome(EntityID id, NodeType node);
142
144 void locationRequest(EntityID id, NodeType requester);
145
147 void resolveResponse(EntityID id, NodeType node);
148
150 void existsRequest(EntityID id, NodeType requester);
151
153 void existsResponse(EntityID id, bool exists, NodeType node);
154
155private:
157 LocRecType makeRec(EntityID const& id, NodeType node) const;
158
160 static void flushPending(
161 std::unordered_map<EntityID, std::vector<NodeAction>>& map,
162 EntityID const& id, NodeType node
163 );
164
171 void announceLocation(EntityID const& id, NodeType node);
172
173private:
174 Comm& comm_;
175 NodeType this_node_ = no_node;
176 HandleType handle_{};
177
179 std::unordered_set<EntityID> local_registered_;
180
183
185 std::unordered_map<EntityID, std::vector<NodeAction>> pending_;
186
188 std::unordered_map<EntityID, std::vector<ExistsAction>> pending_exists_;
189
191 std::unordered_map<EntityID, std::vector<NodeType>> pending_home_;
192
194 std::unordered_map<EntityID, std::unordered_set<NodeType>> loc_asks_;
195};
196
197} /* end namespace loc */
198
199#include "loc/coordinator.impl.h"
200
201#endif /*INCLUDED_LOC_COORDINATOR_H*/
void updateHome(EntityID id, NodeType node)
[home] Learn/refresh where an entity lives.
Definition coordinator.impl.h:124
void unregisterEntity(EntityID const &id)
Unregister an entity that no longer lives here.
Definition coordinator.impl.h:56
void entityExists(EntityID const &id, NodeType home, ExistsAction action)
Check whether an entity exists anywhere in the system.
Definition coordinator.impl.h:85
void registerEntity(EntityID const &id, NodeType home)
Register an entity as living on this rank.
Definition coordinator.impl.h:29
void existsResponse(EntityID id, bool exists, NodeType node)
[asker] Home answered an existence request.
Definition coordinator.impl.h:176
void locationRequest(EntityID id, NodeType requester)
[home] A rank asks where an entity lives.
Definition coordinator.impl.h:129
void existsRequest(EntityID id, NodeType requester)
[home] A rank asks whether an entity exists.
Definition coordinator.impl.h:157
bool isCached(EntityID const &id) const
Whether a resolved location for id is held locally (local or cached).
Definition coordinator.impl.h:109
void getLocation(EntityID const &id, NodeType home, NodeAction action)
Resolve the current location of an entity.
Definition coordinator.impl.h:62
void resolveResponse(EntityID id, NodeType node)
[asker] Home answered a location request.
Definition coordinator.impl.h:149
void entityImmigrated(EntityID const &id, NodeType home, NodeType from)
Register an entity that immigrated here from another rank.
Definition coordinator.impl.h:41
void entityEmigrated(EntityID const &id, NodeType new_node)
Note that an entity has emigrated off this rank to new_node.
Definition coordinator.impl.h:48
Coordinator(Comm &in_comm, LocationSizeType in_max_cache_size=default_max_cache_size)
Construct and collectively register with the communicator.
Definition coordinator.impl.h:19
NodeType thisNode() const
This rank.
Definition coordinator.impl.h:119
void clearCache()
Drop all cached (non-home) resolutions.
Definition coordinator.impl.h:114
Combined lookup over the home-node directory and the local LRU cache.
Definition lookup.h:27
A single location record: the last-known node for an entity along with whether that node is this rank...
Definition record.h:28