Derecho  0.9
Distributed systems toolkit for RDMA
view.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <cstdint>
9 #include <iostream>
10 #include <memory>
11 #include <vector>
12 
14 #include "derecho_modes.hpp"
15 #include "detail/derecho_sst.hpp"
17 #include <derecho/sst/sst.hpp>
20 
21 namespace derecho {
22 enum PORT_TYPE { GMS = 1,
23  RPC,
24  SST,
25  RDMC };
26 
32 public:
36  std::vector<node_id_t> members;
39  std::vector<int> is_sender;
41  std::vector<std::tuple<ip_addr_t, uint16_t, uint16_t, uint16_t, uint16_t>> member_ips_and_ports;
43  std::vector<node_id_t> joined;
45  std::vector<node_id_t> departed;
49  int32_t my_rank;
51  const std::string profile;
54  int rank_of(const node_id_t& who) const;
56  int sender_rank_of(uint32_t rank) const;
58  uint32_t num_senders() const;
61  SubView(int32_t num_members);
62 
63  DEFAULT_SERIALIZATION_SUPPORT(SubView, mode, members, is_sender,
64  member_ips_and_ports, joined, departed, profile);
65  SubView(Mode mode, const std::vector<node_id_t>& members,
66  std::vector<int> is_sender,
67  const std::vector<std::tuple<ip_addr_t, uint16_t, uint16_t, uint16_t, uint16_t>>& member_ips_and_ports,
68  const std::vector<node_id_t>& joined,
69  const std::vector<node_id_t>& departed,
70  const std::string &profile)
71  : mode(mode),
72  members(members),
73  is_sender(is_sender),
74  member_ips_and_ports(member_ips_and_ports),
75  joined(joined),
76  departed(departed),
77  my_rank(-1),
78  profile(profile) {}
79 
80  SubView(Mode mode, const std::vector<node_id_t>& members,
81  std::vector<int> is_sender,
82  const std::vector<std::tuple<ip_addr_t, uint16_t, uint16_t, uint16_t, uint16_t>>& member_ips_and_ports,
83  std::string profile);
84 
91  void init_joined_departed(const SubView& previous_subview);
92 };
93 
95 public:
97  const int32_t vid;
99  const std::vector<node_id_t> members;
101  const std::vector<std::tuple<ip_addr_t, uint16_t, uint16_t, uint16_t, uint16_t>> member_ips_and_ports;
104  std::vector<char> failed; //Note: std::vector<bool> is broken, so we pretend these char values are C-style booleans
108  int32_t num_failed;
110  std::vector<node_id_t> joined;
112  std::vector<node_id_t> departed;
114  const int32_t num_members;
116  int32_t my_rank;
120  bool is_adequately_provisioned = true;
126  std::unique_ptr<MulticastGroup> multicast_group;
128  std::shared_ptr<DerechoSST> gmsSST;
133  std::vector<std::type_index> subgroup_type_order;
139  std::map<subgroup_type_id_t, std::vector<subgroup_id_t>> subgroup_ids_by_type_id;
143  std::vector<std::vector<SubView>> subgroup_shard_views;
145  std::map<subgroup_id_t, uint32_t> my_subgroups;
147  std::map<node_id_t, uint32_t> node_id_to_rank;
148 
149  bool i_know_i_am_leader = false; // I am the leader (and know it)
150 
160  SubView make_subview(const std::vector<node_id_t>& with_members, const Mode mode = Mode::ORDERED, const std::vector<int>& is_sender = {}, std::string profile = "default") const;
161 
163  int rank_of(const std::tuple<ip_addr_t, uint16_t, uint16_t, uint16_t, uint16_t>& who) const;
165  int rank_of(const node_id_t& who) const;
167  int find_rank_of_leader() const;
169  bool i_am_leader() const;
171  bool i_am_new_leader();
173  void merge_changes();
175  void wedge();
176 
180  int subview_rank_of_shard_leader(subgroup_id_t subgroup_id, uint32_t shard_index) const;
181 
184  std::string debug_string() const;
185 
186  DEFAULT_SERIALIZATION_SUPPORT(View, vid, members, member_ips_and_ports,
187  failed, num_failed, joined, departed,
188  num_members, next_unassigned_rank,
189  subgroup_ids_by_type_id, subgroup_shard_views, my_subgroups);
190 
196  View(const int32_t vid, const std::vector<node_id_t>& members,
197  const std::vector<std::tuple<ip_addr_t, uint16_t, uint16_t, uint16_t, uint16_t>>& member_ips_and_ports,
198  const std::vector<char>& failed, const int32_t num_failed,
199  const std::vector<node_id_t>& joined,
200  const std::vector<node_id_t>& departed, const int32_t num_members,
201  const int32_t next_unassigned_rank,
202  const std::map<subgroup_type_id_t, std::vector<subgroup_id_t>>& subgroup_ids_by_type_id,
203  const std::vector<std::vector<SubView>>& subgroup_shard_views,
204  const std::map<subgroup_id_t, uint32_t>& my_subgroups);
205 
207  View(const int32_t vid, const std::vector<node_id_t>& members,
208  const std::vector<std::tuple<ip_addr_t, uint16_t, uint16_t, uint16_t, uint16_t>>& member_ips_and_ports,
209  const std::vector<char>& failed,
210  const std::vector<node_id_t>& joined,
211  const std::vector<node_id_t>& departed, const int32_t my_rank,
212  const int32_t next_unassigned_rank,
213  const std::vector<std::type_index>& subgroup_type_order);
214 };
215 
216 } // namespace derecho
uint32_t subgroup_id_t
Type alias for the internal Subgroup IDs generated by ViewManager.
std::vector< std::vector< SubView > > subgroup_shard_views
Maps subgroup ID -> shard number -> SubView for that subgroup/shard.
Definition: view.hpp:143
const std::vector< node_id_t > members
Node IDs of members in the current view, indexed by their SST rank.
Definition: view.hpp:99
std::vector< int > is_sender
vector selecting the senders, 0 for non-sender, non-0 for sender
Definition: view.hpp:39
uint32_t subgroup_type_id_t
Type of the numeric ID used to refer to subgroup types within a Group; this is currently computed as ...
int32_t next_unassigned_rank
The rank of the lowest-ranked member that is not assigned to a subgroup in this View.
Definition: view.hpp:124
int rank_of(const node_id_t &who) const
Looks up the sub-view rank of a node ID.
Definition: view.cpp:44
SubView(int32_t num_members)
Creates an empty new SubView with num_members members.
Definition: view.cpp:15
int32_t my_rank
The rank of this node within the subgroup/shard, or -1 if this node is not a member of the subgroup/s...
Definition: view.hpp:49
std::map< subgroup_id_t, uint32_t > my_subgroups
Lists the (subgroup ID, shard num) pairs that this node is a member of.
Definition: view.hpp:145
std::unique_ptr< MulticastGroup > multicast_group
RDMC manager object used for sending multicasts.
Definition: view.hpp:126
const std::string profile
Settings for the subview.
Definition: view.hpp:51
std::vector< node_id_t > departed
List of IDs of nodes that left since the previous view, if any.
Definition: view.hpp:112
std::vector< node_id_t > departed
List of IDs of nodes that left since the previous view, if any.
Definition: view.hpp:45
std::vector< char > failed
failed[i] is true if members[i] is considered to have failed.
Definition: view.hpp:104
std::shared_ptr< DerechoSST > gmsSST
Pointer to the SST instance used by the GMS in this View.
Definition: view.hpp:128
A non-POD type which wishes to mark itself byte representable should extend this class.
std::vector< std::tuple< ip_addr_t, uint16_t, uint16_t, uint16_t, uint16_t > > member_ips_and_ports
IP addresses and ports of members in this subgroup/shard, with the same indices as members...
Definition: view.hpp:41
std::map< subgroup_type_id_t, std::vector< subgroup_id_t > > subgroup_ids_by_type_id
Maps the (type, index) pairs used by users to identify subgroups to the internal subgroup IDs generat...
Definition: view.hpp:139
int32_t num_failed
Number of current outstanding failures in this view.
Definition: view.hpp:108
const std::vector< std::tuple< ip_addr_t, uint16_t, uint16_t, uint16_t, uint16_t > > member_ips_and_ports
IP addresses and ports (gms, rpc, sst, rdmc in order) of members in the current view, indexed by their SST rank.
Definition: view.hpp:101
int sender_rank_of(uint32_t rank) const
Looks up the sender rank of a given member.
Definition: view.cpp:53
const int32_t vid
Sequential view ID: 0, 1, ...
Definition: view.hpp:97
uint32_t node_id_t
Type alias for Node IDs in a Derecho group.
The subset of a View associated with a single shard, or a single subgroup if the subgroup is non-shar...
Definition: view.hpp:31
std::vector< node_id_t > members
Node IDs of members in this subgroup/shard, indexed by their order in the SST.
Definition: view.hpp:36
uint32_t num_senders() const
returns the number of senders in the subview
Definition: view.cpp:66
Mode mode
Operation mode, raw mode does not do stability and delivery.
Definition: view.hpp:34
void init_joined_departed(const SubView &previous_subview)
Initialization helper method that initializes the joined and departed lists given the previous View&#39;s...
Definition: view.cpp:76
std::vector< std::type_index > subgroup_type_order
The order of subgroup types as they were declared in the Group&#39;s template parameters.
Definition: view.hpp:133
int32_t my_rank
The rank of this node (as returned by rank_of())
Definition: view.hpp:116
std::vector< node_id_t > joined
List of IDs of nodes that joined since the previous view, if any.
Definition: view.hpp:110
PORT_TYPE
Definition: view.hpp:22
SubView(Mode mode, const std::vector< node_id_t > &members, std::vector< int > is_sender, const std::vector< std::tuple< ip_addr_t, uint16_t, uint16_t, uint16_t, uint16_t >> &member_ips_and_ports, const std::vector< node_id_t > &joined, const std::vector< node_id_t > &departed, const std::string &profile)
Definition: view.hpp:65
std::map< node_id_t, uint32_t > node_id_to_rank
Reverse index of members[]; maps node ID -> SST rank.
Definition: view.hpp:147
std::vector< node_id_t > joined
List of IDs of nodes that joined since the previous view, if any.
Definition: view.hpp:43
DEFAULT_SERIALIZATION_SUPPORT(SubView, mode, members, is_sender, member_ips_and_ports, joined, departed, profile)
const int32_t num_members
Number of members in this view.
Definition: view.hpp:114