1 // replicated state machine interface.
8 #include "rsm_protocol.h"
9 #include "rsm_state_transfer.h"
11 #include <arpa/inet.h>
15 class rsm : public config_view_change {
17 void reg1(int proc, handler *);
19 std::map<int, handler *> procs;
21 class rsm_state_transfer *stf;
23 // On slave: expected viewstamp of next invoke request
24 // On primary: viewstamp for the next request from rsm_client
26 viewstamp last_myvs; // Viewstamp of the last executed request
30 unsigned vid_commit; // Latest view id that is known to rsm layer
31 unsigned vid_insync; // The view id that this node is synchronizing for
32 std::vector<std::string> backups; // A list of unsynchronized backups
34 // For testing purposes
42 rsm_client_protocol::status client_members(int i,
43 std::vector<std::string> &r);
44 rsm_protocol::status invoke(int proc, viewstamp vs, std::string mreq,
46 rsm_protocol::status transferreq(std::string src, viewstamp last, unsigned vid,
47 rsm_protocol::transferres &r);
48 rsm_protocol::status transferdonereq(std::string m, unsigned vid, int &);
49 rsm_protocol::status joinreq(std::string src, viewstamp last,
50 rsm_protocol::joinres &r);
51 rsm_test_protocol::status test_net_repairreq(int heal, int &r);
52 rsm_test_protocol::status breakpointreq(int b, int &r);
59 void execute(int procno, std::string req, std::string &r);
60 rsm_client_protocol::status client_invoke(int procno, std::string req,
62 bool statetransfer(std::string m);
63 bool statetransferdone(std::string m);
64 bool join(std::string m);
65 void set_primary(unsigned vid);
66 std::string find_highest(viewstamp &vs, std::string &m, unsigned &vid);
67 bool sync_with_backups();
68 bool sync_with_primary();
69 void net_repair_wo(bool heal);
73 void commit_change_wo(unsigned vid);
75 rsm (std::string _first, std::string _me);
79 void set_state_transfer(rsm_state_transfer *_stf) { stf = _stf; };
81 void commit_change(unsigned vid);
83 template<class S, class A1, class R>
84 void reg(int proc, S*, int (S::*meth)(const A1 a1, R &));
85 template<class S, class A1, class A2, class R>
86 void reg(int proc, S*, int (S::*meth)(const A1 a1, const A2 a2, R &));
87 template<class S, class A1, class A2, class A3, class R>
88 void reg(int proc, S*, int (S::*meth)(const A1 a1, const A2 a2,
90 template<class S, class A1, class A2, class A3, class A4, class R>
91 void reg(int proc, S*, int (S::*meth)(const A1 a1, const A2 a2,
92 const A3 a3, const A4 a4, R &));
93 template<class S, class A1, class A2, class A3, class A4, class A5, class R>
94 void reg(int proc, S*, int (S::*meth)(const A1 a1, const A2 a2,
95 const A3 a3, const A4 a4, const A5 a5, R &));
98 template<class S, class A1, class R>
99 void rsm::reg(int proc, S*sob, int (S::*meth)(const A1 a1, R & r)) {
100 class h1 : public handler {
103 int (S::*meth)(const A1 a1, R & r);
105 h1(S *xsob, int (S::*xmeth)(const A1 a1, R & r))
106 : sob(xsob), meth(xmeth) { }
107 int fn(unmarshall &args, marshall &ret) {
111 VERIFY(args.okdone());
112 int b = (sob->*meth)(a1,r);
117 reg1(proc, new h1(sob, meth));
120 template<class S, class A1, class A2, class R>
121 void rsm::reg(int proc, S*sob, int (S::*meth)(const A1 a1, const A2 a2, R & r)) {
122 class h1 : public handler {
125 int (S::*meth)(const A1 a1, const A2 a2, R & r);
127 h1(S *xsob, int (S::*xmeth)(const A1 a1, const A2 a2, R & r))
128 : sob(xsob), meth(xmeth) { }
129 int fn(unmarshall &args, marshall &ret) {
135 VERIFY(args.okdone());
136 int b = (sob->*meth)(a1,a2,r);
141 reg1(proc, new h1(sob, meth));
144 template<class S, class A1, class A2, class A3, class R>
145 void rsm::reg(int proc, S*sob, int (S::*meth)(const A1 a1, const A2 a2,
146 const A3 a3, R & r)) {
147 class h1 : public handler {
150 int (S::*meth)(const A1 a1, const A2 a2, const A3 a3, R & r);
152 h1(S *xsob, int (S::*xmeth)(const A1 a1, const A2 a2, const A3 a3, R & r))
153 : sob(xsob), meth(xmeth) { }
154 int fn(unmarshall &args, marshall &ret) {
162 VERIFY(args.okdone());
163 int b = (sob->*meth)(a1,a2,a3,r);
168 reg1(proc, new h1(sob, meth));
171 template<class S, class A1, class A2, class A3, class A4, class R>
172 void rsm::reg(int proc, S*sob, int (S::*meth)(const A1 a1, const A2 a2,
173 const A3 a3, const A4 a4, R & r)) {
174 class h1 : public handler {
177 int (S::*meth)(const A1 a1, const A2 a2, const A3 a3, const A4 a4, R & r);
179 h1(S *xsob, int (S::*xmeth)(const A1 a1, const A2 a2, const A3 a3,
181 : sob(xsob), meth(xmeth) { }
182 int fn(unmarshall &args, marshall &ret) {
192 VERIFY(args.okdone());
193 int b = (sob->*meth)(a1,a2,a3,a4,r);
198 reg1(proc, new h1(sob, meth));
202 template<class S, class A1, class A2, class A3, class A4, class A5, class R> void
203 rsm::reg(int proc, S*sob, int (S::*meth)(const A1 a1, const A2 a2,
204 const A3 a3, const A4 a4,
207 class h1 : public handler {
210 int (S::*meth)(const A1 a1, const A2 a2, const A3 a3, const A4 a4,
213 h1(S *xsob, int (S::*xmeth)(const A1 a1, const A2 a2, const A3 a3,
214 const A4 a4, const A5 a5, R & r))
215 : sob(xsob), meth(xmeth) { }
216 int fn(unmarshall &args, marshall &ret) {
227 VERIFY(args.okdone());
228 int b = (sob->*meth)(a1,a2,a3,a4,a5,r);
233 reg1(proc, new h1(sob, meth));