11 #ifndef GCOMM_EVS_PROTO_HPP
12 #define GCOMM_EVS_PROTO_HPP
15 #include "gcomm/view.hpp"
18 #include "histogram.hpp"
21 #include "evs_seqno.hpp"
22 #include "evs_node.hpp"
23 #include "evs_consensus.hpp"
25 #include "gu_datetime.hpp"
32 #ifndef GCOMM_EVS_MAX_VERSION
33 #define GCOMM_EVS_MAX_VERSION 0
34 #endif // GCOMM_EVS_MAX_VERSION
42 class MessageNodeList;
44 class DelegateMessage;
52 std::ostream& operator<<(std::ostream&,
const Proto&);
73 static std::string to_string(
const State s)
76 case S_CLOSED:
return "CLOSED";
77 case S_JOINING:
return "JOINING";
78 case S_LEAVING:
return "LEAVING";
79 case S_GATHER:
return "GATHER";
80 case S_INSTALL:
return "INSTALL";
81 case S_OPERATIONAL:
return "OPERATIONAL";
83 gu_throw_fatal <<
"Invalid state";
87 friend std::ostream& operator<<(std::ostream&,
const Proto&);
92 Proto(gu::Config& conf,
95 const gu::URI& uri = gu::URI(
"evs://"),
96 const size_t mtu = std::numeric_limits<size_t>::max());
99 const UUID& uuid()
const {
return my_uuid_; }
101 std::string self_string()
const
103 std::ostringstream os;
104 os <<
"evs::proto(" << uuid() <<
", " << to_string(state())
105 <<
", " << current_view_.id() <<
")";
109 State state()
const {
return state_; }
111 size_t known_size()
const {
return known_.size(); }
113 bool is_output_empty()
const {
return output_.empty(); }
115 std::string stats()
const;
118 bool is_flow_control(
const seqno_t,
const seqno_t win)
const;
124 size_t n_aggregated = 1);
125 size_t mtu()
const {
return mtu_; }
126 size_t aggregate_len()
const;
127 int send_user(
const seqno_t);
128 void complete_user(
const seqno_t);
130 void send_gap(
const UUID&,
const ViewId&,
const Range,
bool commit =
false);
132 void send_join(
bool tval =
true);
135 void send_leave(
bool handle =
true);
144 void set_inactive(
const UUID&);
145 void check_inactive();
148 void cleanup_views();
149 void cleanup_joins();
151 size_t n_operational()
const;
156 void deliver_local(
bool trans =
false);
157 void deliver_causal(uint8_t user_type, seqno_t seqno,
const Datagram&);
159 void deliver_trans();
162 void deliver_empty_view();
164 void setall_committed(
bool val);
165 bool is_all_committed()
const;
166 void setall_installed(
bool val);
167 bool is_all_installed()
const;
170 bool is_representative(
const UUID& pid)
const;
172 void shift_to(
const State,
const bool send_j =
true);
185 seqno_t update_im_safe_seq(
const size_t uuid,
const seqno_t seq);
192 bool is_msg_from_previous_view(
const Message&);
196 void check_nil_view_id();
197 void handle_foreign(
const Message&);
204 void handle_gap(
const GapMessage&, NodeMap::iterator);
205 void handle_join(
const JoinMessage&, NodeMap::iterator);
206 void handle_leave(
const LeaveMessage&, NodeMap::iterator);
210 static size_t unserialize_message(
const UUID&,
213 void handle_msg(
const Message& msg,
218 void handle_stable_view(
const View& view)
220 set_stable_view(view);
222 void connect(
bool first)
224 gu_trace(shift_to(S_JOINING));
225 gu_trace(send_join(first));
228 void close(
bool force =
false)
239 log_debug << self_string() <<
" closing in state " << state();
240 if (state() != S_GATHER && state() != S_INSTALL)
242 gu_trace(shift_to(S_LEAVING));
243 gu_trace(send_leave());
244 pending_leave_ =
false;
248 pending_leave_ =
true;
252 void close(
const UUID& uuid)
257 bool set_param(
const std::string& key,
const std::string& val);
274 public MultiMap<gu::datetime::Date, Timer> { };
279 void handle_inactivity_timer();
280 void handle_retrans_timer();
281 void handle_install_timer();
282 void handle_stats_timer();
283 gu::datetime::Date next_expiration(
const Timer)
const;
285 gu::datetime::Date handle_timers();
320 static const int max_version_ = GCOMM_EVS_MAX_VERSION;
323 gu::datetime::Date last_stats_report_;
328 long long int send_queue_s_;
329 long long int n_send_queue_s_;
330 std::vector<long long int> sent_msgs_;
331 long long int retrans_msgs_;
332 long long int recovered_msgs_;
333 std::vector<long long int> recvd_msgs_;
334 std::vector<long long int> delivered_msgs_;
351 NodeMap::iterator self_i_;
353 gu::datetime::Period view_forget_timeout_;
354 gu::datetime::Period inactive_timeout_;
355 gu::datetime::Period suspect_timeout_;
356 gu::datetime::Period inactive_check_period_;
357 gu::datetime::Period retrans_period_;
358 gu::datetime::Period install_timeout_;
359 gu::datetime::Period join_retrans_period_;
360 gu::datetime::Period stats_report_period_;
361 gu::datetime::Period causal_keepalive_period_;
363 gu::datetime::Date last_inactive_check_;
364 gu::datetime::Date last_causal_keepalive_;
370 std::list<std::pair<ViewId, gu::datetime::Date> > previous_views_;
378 CausalMessage(uint8_t user_type,
382 user_type_(user_type),
384 datagram_ (datagram ),
385 tstamp_ (gu::datetime::Date::now())
387 uint8_t user_type()
const {
return user_type_; }
388 seqno_t seqno()
const {
return seqno_ ; }
389 const Datagram& datagram()
const {
return datagram_ ; }
390 const gu::datetime::Date& tstamp()
const {
return tstamp_ ; }
395 gu::datetime::Date tstamp_;
398 std::deque<CausalMessage> causal_queue_;
400 Consensus consensus_;
402 InstallMessage* install_message_;
404 uint32_t attempt_seq_;
406 int max_install_timeouts_;
407 int install_timeout_count_;
413 seqno_t send_window_;
415 seqno_t user_send_window_;
417 std::deque<std::pair<Datagram, ProtoDownMeta> > output_;
418 std::vector<gu::byte_t> send_buf_;
419 uint32_t max_output_size_;
429 void operator=(
const Proto&);
433 #endif // EVS_PROTO_HPP
Definition: profile.hpp:136
Definition: evs_proto.hpp:294
Definition: evs_proto.hpp:303
Definition: evs_proto.hpp:296
Definition: evs_seqno.hpp:31
Definition: evs_message2.hpp:520
Definition: evs_message2.hpp:465
Class implementing EVS protocol.
Definition: evs_proto.hpp:60
Definition: evs_proto.hpp:314
Definition: evs_proto.hpp:301
Definition: evs_message2.hpp:552
Definition: evs_proto.hpp:300
Definition: evs_proto.hpp:304
Lightweight profiling utility.
Definition: evs_proto.hpp:293
DebugFlags
Flags controlling what debug information is logged if debug logging is turned on. ...
Definition: evs_proto.hpp:291
Definition: evs_proto.hpp:298
Definition: evs_message2.hpp:585
Definition: evs_proto.hpp:302
Definition: evs_proto.hpp:295
Definition: histogram.hpp:14
Definition: evs_node.hpp:137
Definition: evs_message2.hpp:390
Definition: evs_proto.hpp:315
Definition: evs_proto.hpp:312
Definition: evs_proto.hpp:299
InfoFlags
Flags controlling what info log is printed in logs.
Definition: evs_proto.hpp:310
Definition: protolay.hpp:192
Definition: evs_message2.hpp:487
Definition: evs_proto.hpp:273
Protocol layer interface definitions.
Definition: evs_proto.hpp:313
Definition: evs_message2.hpp:113
Definition: evs_message2.hpp:121
Definition: evs_proto.hpp:297
Proto(gu::Config &conf, const UUID &my_uuid, SegmentId segment, const gu::URI &uri=gu::URI("evs://"), const size_t mtu=std::numeric_limits< size_t >::max())
Datagram container.
Definition: datagram.hpp:151