Derecho  0.9
Distributed systems toolkit for RDMA
derecho_sst.cpp
Go to the documentation of this file.
1 #include <atomic>
2 #include <cstring>
4 
5 namespace derecho {
6 
7 void DerechoSST::init_local_row_from_previous(const DerechoSST& old_sst, const int row, const int num_changes_installed) {
8  const int local_row = get_local_index();
9  static thread_local std::mutex copy_mutex;
10  std::unique_lock<std::mutex> lock(copy_mutex);
11  //Copy elements [changes_installed...n] of the old changes array to the beginning of the new changes array
12  memcpy(const_cast<node_id_t*>(changes[local_row]),
13  const_cast<const node_id_t*>(old_sst.changes[row] + num_changes_installed),
14  (old_sst.changes.size() - num_changes_installed) * sizeof(node_id_t));
15  //Do the same thing with the joiner_ips arrays and joiner_xxx_ports arrays
16  memcpy(const_cast<uint32_t*>(joiner_ips[local_row]),
17  const_cast<const uint32_t*>(old_sst.joiner_ips[row] + num_changes_installed),
18  (old_sst.joiner_ips.size() - num_changes_installed) * sizeof(uint32_t));
19  memcpy(const_cast<uint16_t*>(joiner_gms_ports[local_row]),
20  const_cast<const uint16_t*>(old_sst.joiner_gms_ports[row] + num_changes_installed),
21  (old_sst.joiner_gms_ports.size() - num_changes_installed) * sizeof(uint16_t));
22  memcpy(const_cast<uint16_t*>(joiner_rpc_ports[local_row]),
23  const_cast<const uint16_t*>(old_sst.joiner_rpc_ports[row] + num_changes_installed),
24  (old_sst.joiner_rpc_ports.size() - num_changes_installed) * sizeof(uint16_t));
25  memcpy(const_cast<uint16_t*>(joiner_sst_ports[local_row]),
26  const_cast<const uint16_t*>(old_sst.joiner_sst_ports[row] + num_changes_installed),
27  (old_sst.joiner_sst_ports.size() - num_changes_installed) * sizeof(uint16_t));
28  memcpy(const_cast<uint16_t*>(joiner_rdmc_ports[local_row]),
29  const_cast<const uint16_t*>(old_sst.joiner_rdmc_ports[row] + num_changes_installed),
30  (old_sst.joiner_rdmc_ports.size() - num_changes_installed) * sizeof(uint16_t));
31  for(size_t i = 0; i < suspected.size(); ++i) {
32  suspected[local_row][i] = false;
33  }
34  for(size_t i = 0; i < global_min_ready.size(); ++i) {
35  global_min_ready[local_row][i] = false;
36  }
37  for(size_t i = 0; i < global_min.size(); ++i) {
38  global_min[local_row][i] = 0;
39  }
40  num_changes[local_row] = old_sst.num_changes[row];
41  num_committed[local_row] = old_sst.num_committed[row];
42  num_acked[local_row] = old_sst.num_acked[row];
43  num_installed[local_row] = old_sst.num_installed[row] + num_changes_installed;
44  wedged[local_row] = false;
45 }
46 
47 void DerechoSST::init_local_change_proposals(const int other_row) {
48  const int local_row = get_local_index();
49  static thread_local std::mutex copy_mutex;
50  std::unique_lock<std::mutex> lock(copy_mutex);
51  memcpy(const_cast<node_id_t*>(changes[local_row]),
52  const_cast<const node_id_t*>(changes[other_row]),
53  changes.size() * sizeof(node_id_t));
54  memcpy(const_cast<uint32_t*>(joiner_ips[local_row]),
55  const_cast<const uint32_t*>(joiner_ips[other_row]),
56  joiner_ips.size() * sizeof(uint32_t));
57  memcpy(const_cast<uint16_t*>(joiner_gms_ports[local_row]),
58  const_cast<const uint16_t*>(joiner_gms_ports[other_row]),
59  joiner_gms_ports.size() * sizeof(uint16_t));
60  memcpy(const_cast<uint16_t*>(joiner_rpc_ports[local_row]),
61  const_cast<const uint16_t*>(joiner_rpc_ports[other_row]),
62  joiner_rpc_ports.size() * sizeof(uint16_t));
63  memcpy(const_cast<uint16_t*>(joiner_sst_ports[local_row]),
64  const_cast<const uint16_t*>(joiner_sst_ports[other_row]),
65  joiner_sst_ports.size() * sizeof(uint16_t));
66  memcpy(const_cast<uint16_t*>(joiner_rdmc_ports[local_row]),
67  const_cast<const uint16_t*>(joiner_rdmc_ports[other_row]),
68  joiner_rdmc_ports.size() * sizeof(uint16_t));
69  num_changes[local_row] = num_changes[other_row];
70  num_committed[local_row] = num_committed[other_row];
71  num_acked[local_row] = num_acked[other_row];
72  num_installed[local_row] = num_installed[other_row];
73 }
74 
75 std::string DerechoSST::to_string() const {
76  std::stringstream s;
77  uint num_rows = get_num_rows();
78  for(uint row = 0; row < num_rows; ++row) {
79  s << "row=" << row << " ";
80  s << "vid=" << vid[row] << " ";
81  s << "suspected={ ";
82  for(unsigned int n = 0; n < suspected.size(); n++) {
83  s << (suspected[row][n] ? "T" : "F") << " ";
84  }
85 
86  s << "}, num_changes=" << num_changes[row] << ", num_committed="
87  << num_committed[row] << ", num_installed=" << num_installed[row];
88  s << ", changes={ ";
89  for(int n = 0; n < (num_changes[row] - num_installed[row]); ++n) {
90  s << changes[row][n] << " ";
91  }
92  s << "}, num_acked= " << num_acked[row] << ", num_received={ ";
93  for(unsigned int n = 0; n < num_received.size(); n++) {
94  s << num_received[row][n] << " ";
95  }
96  s << "}, joiner_ips={ ";
97  for(int n = 0; n < (num_changes[row] - num_installed[row]); ++n) {
98  s << joiner_ips[row][n] << " ";
99  }
100  s << "}, joiner_gms_ports={ ";
101  for(int n = 0; n < (num_changes[row] - num_installed[row]); ++n) {
102  s << joiner_gms_ports[row][n] << " ";
103  }
104  s << "}, joiner_rpc_ports={ ";
105  for(int n = 0; n < (num_changes[row] - num_installed[row]); ++n) {
106  s << joiner_rpc_ports[row][n] << " ";
107  }
108  s << "}, joiner_sst_ports={ ";
109  for(int n = 0; n < (num_changes[row] - num_installed[row]); ++n) {
110  s << joiner_sst_ports[row][n] << " ";
111  }
112  s << "}, joiner_rdmc_ports={ ";
113  for(int n = 0; n < (num_changes[row] - num_installed[row]); ++n) {
114  s << joiner_rdmc_ports[row][n] << " ";
115  }
116  s << "}, seq_num={ ";
117  for(unsigned int n = 0; n < seq_num.size(); n++) {
118  s << seq_num[row][n] << " ";
119  }
120  s << "}"
121  << ", delivered_num={ ";
122  for(unsigned int n = 0; n < delivered_num.size(); n++) {
123  s << delivered_num[row][n] << " ";
124  }
125  s << "}"
126  << ", wedged = " << (wedged[row] ? "T" : "F") << ", global_min = { ";
127  for(unsigned int n = 0; n < global_min.size(); n++) {
128  s << global_min[row][n] << " ";
129  }
130 
131  s << "}, global_min_ready= { ";
132  for(uint n = 0; n < global_min_ready.size(); n++) {
133  s << global_min_ready[row] << " ";
134  }
135  s << "}"
136  << ", rip = " << rip[row] << std::endl;
137  }
138  return s.str();
139 }
140 
141 namespace gmssst {
142 
149 void set(volatile char* string_array, const std::string& value) {
150  strcpy(const_cast<char*>(string_array), value.c_str());
151  std::atomic_signal_fence(std::memory_order_acq_rel);
152 }
153 
159 void increment(volatile int& member) {
160  member++;
161  std::atomic_signal_fence(std::memory_order_acq_rel);
162 }
163 
164 bool equals(const volatile char* string_array, const std::string& value) {
165  return strcmp(const_cast<const char*>(string_array), value.c_str()) == 0;
166 }
167 
168 } // namespace gmssst
169 } // namespace derecho
unsigned int get_local_index() const
Gets the index of the local row in the table.
Definition: sst.hpp:318
SSTFieldVector< bool > global_min_ready
Array indicating whether each shard leader (indexed by subgroup number) has published a global_min fo...
SSTField< int > num_changes
How many changes to the view have been proposed.
Definition: derecho_sst.hpp:86
SSTField< bool > wedged
Set after calling rdmc::wedged(), reports that this member is wedged.
SSTFieldVector< uint16_t > joiner_gms_ports
joiner_xxx_ports are the port numbers for the joining nodes.
Definition: derecho_sst.hpp:76
SSTFieldVector< uint16_t > joiner_sst_ports
Definition: derecho_sst.hpp:78
unsigned int get_num_rows() const
Returns the total number of rows in the table.
Definition: sst.hpp:315
SSTField< int32_t > vid
View ID associated with this SST.
Definition: derecho_sst.hpp:53
SSTFieldVector< message_id_t > seq_num
Sequence numbers are interpreted like a row-major pair: (sender, index) becomes sender + num_members ...
Definition: derecho_sst.hpp:37
void increment(volatile int &member)
Thread-safe increment of an integer member of GMSTableRow; ensures there is a std::atomic_signal_fenc...
std::string to_string() const
Creates a string representation of the local row (not the whole table).
Definition: derecho_sst.cpp:75
SSTField< int > num_acked
How many proposed changes have been seen.
Definition: derecho_sst.hpp:93
void init_local_row_from_previous(const DerechoSST &old_sst, const int row, const int num_changes_installed)
Initializes the local row of this SST based on the specified row of the previous View&#39;s SST...
Definition: derecho_sst.cpp:7
SSTFieldVector< message_id_t > delivered_num
This represents the highest sequence number that has been delivered at this node. ...
Definition: derecho_sst.hpp:43
SSTField< int > num_installed
How many previously proposed view changes have been installed in the current view.
Definition: derecho_sst.hpp:98
SSTFieldVector< uint16_t > joiner_rdmc_ports
Definition: derecho_sst.hpp:79
SSTFieldVector< int32_t > num_received
Local count of number of received messages by sender.
size_t size() const
Just like std::vector::size(), returns the number of elements in this vector.
Definition: sst.hpp:110
uint32_t node_id_t
Type alias for Node IDs in a Derecho group.
SSTField< bool > rip
to signal a graceful exit
The GMS and derecho_group will share the same SST for efficiency.
Definition: derecho_sst.hpp:22
void init_local_change_proposals(const int other_row)
Copies currently proposed changes and the various counter values associated with them to the local ro...
Definition: derecho_sst.cpp:47
bool equals(const volatile char *string_array, const std::string &value)
SSTFieldVector< uint32_t > joiner_ips
If changes[i] is a Join, joiner_ips[i] is the IP address of the joining node, packed into an unsigned...
Definition: derecho_sst.hpp:74
SSTFieldVector< int > global_min
Array of how many messages to accept from each sender in the current view change. ...
SSTFieldVector< uint16_t > joiner_rpc_ports
Definition: derecho_sst.hpp:77
SSTFieldVector< node_id_t > changes
An array of the same length as View::members, containing a list of proposed changes to the view that ...
Definition: derecho_sst.hpp:67
SSTField< int > num_committed
How many proposed view changes have reached the commit point.
Definition: derecho_sst.hpp:88
SSTFieldVector< bool > suspected
Array of same length as View::members, where each bool represents whether the corresponding member is...
Definition: derecho_sst.hpp:58