// The rule is that a module releases its internal locks before it
// upcalls, but can keep its locks when calling down.
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "types.h"
-#include "handle.h"
#include "rsm.h"
+#include "handle.h"
#include "rsm_client.h"
+#include <unistd.h>
rsm::rsm(const string & _first, const string & _me) :
stf(0), primary(_first), insync (false), inviewchange (true), vid_commit(0),
partitioned (false), dopartition(false), break1(false), break2(false)
{
- cfg = new config(_first, _me, this);
+ cfg = unique_ptr<config>(new config(_first, _me, this));
if (_first == _me) {
// Commit the first view here. We can not have acceptor::acceptor
rsmrpc->reg(rsm_protocol::joinreq, &rsm::joinreq, this);
// tester must be on different port, otherwise it may partition itself
- testsvr = new rpcs((in_port_t)stoi(_me) + 1);
+ testsvr = unique_ptr<rpcs>(new rpcs((in_port_t)stoi(_me) + 1));
testsvr->reg(rsm_test_protocol::net_repair, &rsm::test_net_repairreq, this);
testsvr->reg(rsm_test_protocol::breakpoint, &rsm::breakpointreq, this);
+}
- {
- lock ml(rsm_mutex);
- thread(&rsm::recovery, this).detach();
- }
+void rsm::start() {
+ lock ml(rsm_mutex);
+ rsmrpc->start();
+ testsvr->start();
+ thread(&rsm::recovery, this).detach();
}
-void rsm::reg1(int proc, handler *h) {
+void rsm::reg1(rpc_protocol::proc_id_t proc, handler *h) {
lock ml(rsm_mutex);
procs[proc] = h;
}
// XXX iannucci 2013/09/15 -- I don't understand whether accessing
// cfg->view_id in this manner involves a race. I suspect not.
if (join(primary, ml)) {
- LOG("recovery: joined");
+ LOG("joined");
commit_change(cfg->view_id(), ml);
} else {
ml.unlock();
}
}
vid_insync = vid_commit;
- LOG("recovery: sync vid_insync " << vid_insync);
+ LOG("sync vid_insync " << vid_insync);
if (primary == cfg->myaddr()) {
r = sync_with_backups(ml);
} else {
r = sync_with_primary(ml);
}
- LOG("recovery: sync done");
+ LOG("sync done");
// If there was a commited viewchange during the synchronization, restart
// the recovery
myvs.seqno = 1;
inviewchange = false;
}
- LOG("recovery: go to sleep " << insync << " " << inviewchange);
+ LOG("go to sleep " << insync << " " << inviewchange);
recovery_cond.wait(ml);
}
}
rsm_mutex_lock.unlock();
cl = h.safebind();
if (cl) {
- ret = cl->call_timeout(rsm_protocol::transferreq, rpcc::to(100),
+ ret = cl->call_timeout(rsm_protocol::transferreq, milliseconds(100),
r, cfg->myaddr(), last_myvs, vid_insync);
}
rsm_mutex_lock.lock();
rsm_mutex_lock.unlock();
cl = h.safebind();
if (cl != 0) {
- ret = cl->call_timeout(rsm_protocol::joinreq, rpcc::to(12000), log,
+ ret = cl->call_timeout(rsm_protocol::joinreq, milliseconds(12000), log,
cfg->myaddr(), last_myvs);
}
rsm_mutex_lock.lock();
void rsm::commit_change(unsigned vid, lock &) {
if (vid <= vid_commit)
return;
- LOG("commit_change: new view (" << vid << ") last vs (" << last_myvs.vid << "," <<
+ LOG("new view (" << vid << ") last vs (" << last_myvs.vid << "," <<
last_myvs.seqno << ") " << primary << " insync " << insync);
vid_commit = vid;
inviewchange = true;
}
-void rsm::execute(int procno, const string & req, string & r) {
+void rsm::execute(rpc_protocol::proc_id_t procno, const string & req, string & r) {
LOG("execute");
handler *h = procs[procno];
VERIFY(h);
// number, and invokes it on all members of the replicated state
// machine.
//
-rsm_client_protocol::status rsm::client_invoke(string & r, int procno, const string & req) {
+rsm_client_protocol::status rsm::client_invoke(string & r, rpc_protocol::proc_id_t procno, const string & req) {
LOG("invoke procno 0x" << hex << procno);
lock ml(invoke_mutex);
vector<string> m;
if (!cl)
return rsm_client_protocol::BUSY;
int ignored_rval;
- auto ret = (rsm_protocol::status)cl->call_timeout(rsm_protocol::invoke, rpcc::to(100), ignored_rval, procno, vs, req);
+ auto ret = (rsm_protocol::status)cl->call_timeout(rsm_protocol::invoke, milliseconds(100), ignored_rval, procno, vs, req);
LOG("Invoke returned " << ret);
if (ret != rsm_protocol::OK)
return rsm_client_protocol::BUSY;
// the replica must execute requests in order (with no gaps)
// according to requests' seqno
-rsm_protocol::status rsm::invoke(int &, int proc, viewstamp vs, const string & req) {
+rsm_protocol::status rsm::invoke(int &, rpc_protocol::proc_id_t proc, viewstamp vs, const string & req) {
LOG("invoke procno 0x" << hex << proc);
lock ml(invoke_mutex);
vector<string> m;
VERIFY (c.size() > 0);
if (isamember(primary,c)) {
- LOG("set_primary: primary stays " << primary);
+ LOG("primary stays " << primary);
return;
}
for (unsigned i = 0; i < p.size(); i++) {
if (isamember(p[i], c)) {
primary = p[i];
- LOG("set_primary: primary is " << primary);
+ LOG("primary is " << primary);
return;
}
}