-
Notifications
You must be signed in to change notification settings - Fork 0
/
rsm.h
238 lines (220 loc) · 6.32 KB
/
rsm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
// replicated state machine interface.
#ifndef rsm_h
#define rsm_h
#include <string>
#include <vector>
#include "rsm_protocol.h"
#include "rsm_state_transfer.h"
#include "rpc.h"
#include <arpa/inet.h>
#include "config.h"
class rsm : public config_view_change {
private:
void reg1(int proc, handler *);
protected:
std::map<int, handler *> procs;
config *cfg;
class rsm_state_transfer *stf;
rpcs *rsmrpc;
viewstamp myvs;
viewstamp last_myvs;
std::string primary;
bool insync;
bool inviewchange;
unsigned nbackup;
// For testing purposes
rpcs *testsvr;
bool partitioned;
bool dopartition;
bool break1;
bool break2;
rsm_client_protocol::status client_members(int i,
std::vector<std::string> &r);
rsm_protocol::status invoke(int proc, viewstamp vs, std::string mreq,
int &dummy);
rsm_protocol::status transferreq(std::string src, viewstamp last,
rsm_protocol::transferres &r);
rsm_protocol::status transferdonereq(std::string m, int &r);
rsm_protocol::status joinreq(std::string src, viewstamp last,
rsm_protocol::joinres &r);
rsm_test_protocol::status test_net_repairreq(int heal, int &r);
rsm_test_protocol::status breakpointreq(int b, int &r);
pthread_mutex_t rsm_mutex;
pthread_mutex_t invoke_mutex;
pthread_cond_t recovery_cond;
pthread_cond_t sync_cond;
pthread_cond_t join_cond;
std::string execute(int procno, std::string req);
rsm_client_protocol::status client_invoke(int procno, std::string req,
std::string &r);
bool statetransfer(std::string m);
bool statetransferdone(std::string m);
bool join(std::string m);
void set_primary();
std::string find_highest(viewstamp &vs, std::string &m, unsigned &vid);
bool sync_with_backups();
bool sync_with_primary();
bool amiprimary_wo();
void net_repair_wo(bool heal);
void breakpoint1();
void breakpoint2();
void partition1();
public:
rsm (std::string _first, std::string _me);
~rsm() {};
bool amiprimary();
void set_state_transfer(rsm_state_transfer *_stf) { stf = _stf; };
void recovery();
void commit_change();
template<class S, class A1, class R>
void reg(int proc, S*, int (S::*meth)(const A1 a1, R &));
template<class S, class A1, class A2, class R>
void reg(int proc, S*, int (S::*meth)(const A1 a1, const A2 a2, R &));
template<class S, class A1, class A2, class A3, class R>
void reg(int proc, S*, int (S::*meth)(const A1 a1, const A2 a2,
const A3 a3, R &));
template<class S, class A1, class A2, class A3, class A4, class R>
void reg(int proc, S*, int (S::*meth)(const A1 a1, const A2 a2,
const A3 a3, const A4 a4, R &));
template<class S, class A1, class A2, class A3, class A4, class A5, class R>
void reg(int proc, S*, int (S::*meth)(const A1 a1, const A2 a2,
const A3 a3, const A4 a4,
const A5 a5, R &));
};
template<class S, class A1, class R> void
rsm::reg(int proc, S*sob, int (S::*meth)(const A1 a1, R & r))
{
class h1 : public handler {
private:
S * sob;
int (S::*meth)(const A1 a1, R & r);
public:
h1(S *xsob, int (S::*xmeth)(const A1 a1, R & r))
: sob(xsob), meth(xmeth) { }
int fn(unmarshall &args, marshall &ret) {
A1 a1;
R r;
args >> a1;
assert(args.okdone());
int b = (sob->*meth)(a1,r);
ret << r;
return b;
}
};
reg1(proc, new h1(sob, meth));
}
template<class S, class A1, class A2, class R> void
rsm::reg(int proc, S*sob, int (S::*meth)(const A1 a1, const A2 a2, R & r))
{
class h1 : public handler {
private:
S * sob;
int (S::*meth)(const A1 a1, const A2 a2, R & r);
public:
h1(S *xsob, int (S::*xmeth)(const A1 a1, const A2 a2, R & r))
: sob(xsob), meth(xmeth) { }
int fn(unmarshall &args, marshall &ret) {
A1 a1;
A2 a2;
R r;
args >> a1;
args >> a2;
assert(args.okdone());
int b = (sob->*meth)(a1,a2,r);
ret << r;
return b;
}
};
reg1(proc, new h1(sob, meth));
}
template<class S, class A1, class A2, class A3, class R> void
rsm::reg(int proc, S*sob, int (S::*meth)(const A1 a1, const A2 a2,
const A3 a3, R & r))
{
class h1 : public handler {
private:
S * sob;
int (S::*meth)(const A1 a1, const A2 a2, const A3 a3, R & r);
public:
h1(S *xsob, int (S::*xmeth)(const A1 a1, const A2 a2, const A3 a3, R & r))
: sob(xsob), meth(xmeth) { }
int fn(unmarshall &args, marshall &ret) {
A1 a1;
A2 a2;
A3 a3;
R r;
args >> a1;
args >> a2;
args >> a3;
assert(args.okdone());
int b = (sob->*meth)(a1,a2,a3,r);
ret << r;
return b;
}
};
reg1(proc, new h1(sob, meth));
}
template<class S, class A1, class A2, class A3, class A4, class R> void
rsm::reg(int proc, S*sob, int (S::*meth)(const A1 a1, const A2 a2,
const A3 a3, const A4 a4, R & r))
{
class h1 : public handler {
private:
S * sob;
int (S::*meth)(const A1 a1, const A2 a2, const A3 a3, const A4 a4, R & r);
public:
h1(S *xsob, int (S::*xmeth)(const A1 a1, const A2 a2, const A3 a3,
const A4 a4, R & r))
: sob(xsob), meth(xmeth) { }
int fn(unmarshall &args, marshall &ret) {
A1 a1;
A2 a2;
A3 a3;
A4 a4;
R r;
args >> a1;
args >> a2;
args >> a3;
args >> a4;
assert(args.okdone());
int b = (sob->*meth)(a1,a2,a3,a4,r);
ret << r;
return b;
}
};
reg1(proc, new h1(sob, meth));
}
template<class S, class A1, class A2, class A3, class A4, class A5, class R> void
rsm::reg(int proc, S*sob, int (S::*meth)(const A1 a1, const A2 a2,
const A3 a3, const A4 a4,
const A5 a5, R & r))
{
class h1 : public handler {
private:
S * sob;
int (S::*meth)(const A1 a1, const A2 a2, const A3 a3, const A4 a4,
const A5 a5, R & r);
public:
h1(S *xsob, int (S::*xmeth)(const A1 a1, const A2 a2, const A3 a3,
const A4 a4, const A5 a5, R & r))
: sob(xsob), meth(xmeth) { }
int fn(unmarshall &args, marshall &ret) {
A1 a1;
A2 a2;
A3 a3;
A4 a4;
A5 a5;
R r;
args >> a1;
args >> a2;
args >> a3;
args >> a4;
assert(args.okdone());
int b = (sob->*meth)(a1,a2,a3,a4,a5,r);
ret << r;
return b;
}
};
reg1(proc, new h1(sob, meth));
}
#endif /* rsm_h */