5 #ifndef GCOMM_PC_PROTO_HPP
6 #define GCOMM_PC_PROTO_HPP
11 #include "gcomm/uuid.hpp"
14 #include "pc_message.hpp"
15 #include "defaults.hpp"
19 #ifndef GCOMM_PC_MAX_VERSION
20 #define GCOMM_PC_MAX_VERSION 0
21 #endif // GCOMM_PC_MAX_VERSION
28 std::ostream& operator<<(std::ostream& os,
const Proto& p);
48 static std::string to_string(
const State s)
52 case S_CLOSED:
return "CLOSED";
53 case S_STATES_EXCH:
return "STATES_EXCH";
54 case S_INSTALL:
return "INSTALL";
55 case S_TRANS:
return "TRANS";
56 case S_PRIM:
return "PRIM";
57 case S_NON_PRIM:
return "NON_PRIM";
59 gu_throw_fatal <<
"Invalid state";
64 Proto(gu::Config& conf,
67 const gu::URI& uri = gu::URI(
"pc://"))
74 0, max_version_ + 1)),
77 npvo_ (param<bool>(conf, uri,
Conf::PcNpvo, Defaults::PcNpvo)),
79 Defaults::PcIgnoreQuorum)),
81 gu::to_string(ignore_quorum_))),
86 Defaults::PcChecksum)),
88 self_i_ (instances_.insert_unique(std::make_pair(uuid,
Node()))),
90 current_view_ (V_NONE),
91 pc_view_ (V_NON_PRIM),
93 mtu_ (std::numeric_limits<int32_t>::max()),
99 log_info <<
"PC version " << version_;
101 NodeMap::value(self_i_).set_segment(segment);
113 const UUID& uuid()
const {
return my_uuid_; }
115 bool prim()
const {
return NodeMap::value(self_i_).prim(); }
117 void set_prim(
const bool val) { NodeMap::value(self_i_).set_prim(val); }
119 void mark_non_prim();
122 const ViewId& last_prim()
const
123 {
return NodeMap::value(self_i_).last_prim(); }
125 void set_last_prim(
const ViewId& vid)
128 NodeMap::value(self_i_).set_last_prim(vid);
131 uint32_t last_seq()
const
132 {
return NodeMap::value(self_i_).last_seq(); }
134 void set_last_seq(
const uint32_t seq)
135 { NodeMap::value(self_i_).set_last_seq(seq); }
137 int64_t to_seq()
const
138 {
return NodeMap::value(self_i_).to_seq(); }
140 void set_to_seq(
const int64_t seq)
141 { NodeMap::value(self_i_).set_to_seq(seq); }
143 void set_weight(
int weight)
144 { NodeMap::value(self_i_).set_weight(weight); }
149 const View& current_view()
const {
return current_view_; }
151 const UUID& self_id()
const {
return my_uuid_; }
153 State state()
const {
return state_; }
155 void shift_to (State);
157 void send_install(
bool bootstrap,
int weight = -1);
159 void handle_first_trans (
const View&);
160 void handle_trans (
const View&);
161 void handle_reg (
const View&);
163 void handle_msg (
const Message&,
const Datagram&,
165 void handle_up (
const void*,
const Datagram&,
167 int handle_down (Datagram&,
const ProtoDownMeta&);
169 void connect(
bool first)
171 log_debug << self_id() <<
" start_prim " << first;
174 shift_to(S_NON_PRIM);
177 void close(
bool force =
false) { closing_ =
true; }
179 void handle_view (
const View&);
181 bool set_param(
const std::string& key,
const std::string& val);
182 void set_mtu(
size_t mtu) { mtu_ = mtu; }
183 size_t mtu()
const {
return mtu_; }
185 friend std::ostream& operator<<(std::ostream& os,
const Proto& p);
186 Proto (
const Proto&);
187 Proto& operator=(
const Proto&);
189 bool requires_rtr()
const;
190 bool is_prim()
const;
191 bool have_quorum(
const View&,
const View&)
const;
192 bool have_split_brain(
const View&)
const;
193 void validate_state_msgs()
const;
194 void cleanup_instances();
195 void handle_state(
const Message&,
const UUID&);
196 void handle_install(
const Message&,
const UUID&);
197 void handle_trans_install(
const Message&,
const UUID&);
198 void handle_user(
const Message&,
const Datagram&,
200 void deliver_view(
bool bootstrap =
false);
203 static const int max_version_ = GCOMM_PC_MAX_VERSION;
211 uint32_t last_sent_seq_;
214 NodeMap::iterator self_i_;
219 std::list<View> views_;
225 #endif // PC_PROTO_HPP
static std::string const PcWeight
Node weight in prim comp voting.
Definition: conf.hpp:421
static std::string const PcVersion
PC protocol version.
Definition: conf.hpp:362
Definition: pc_message.hpp:34
static std::string const PcIgnoreSb
PC split-brain mode.
Definition: conf.hpp:370
static std::string const PcNpvo
PC newer prim view overrides.
Definition: conf.hpp:401
Configuration parameters and utility templates.
Definition: pc_proto.hpp:33
static std::string const PcIgnoreQuorum
PC quorum mode.
Definition: conf.hpp:378
static std::string const PcChecksum
PC message checksumming.
Definition: conf.hpp:386
Definition: protolay.hpp:192
Protocol layer interface definitions.
Definition: pc_proto.hpp:147
#define gcomm_assert(cond_)
Definition: exception.hpp:21