// The rule is that a module releases its internal locks before it
// upcalls, but can keep its locks when calling down.
// The rule is that a module releases its internal locks before it
// upcalls, but can keep its locks when calling down.
stf(0), primary(_first), insync (false), inviewchange (true), vid_commit(0),
partitioned (false), dopartition(false), break1(false), break2(false)
{
stf(0), primary(_first), insync (false), inviewchange (true), vid_commit(0),
partitioned (false), dopartition(false), break1(false), break2(false)
{
- rsmrpc->reg(rsm_client_protocol::invoke, this, &rsm::client_invoke);
- rsmrpc->reg(rsm_client_protocol::members, this, &rsm::client_members);
- rsmrpc->reg(rsm_protocol::invoke, this, &rsm::invoke);
- rsmrpc->reg(rsm_protocol::transferreq, this, &rsm::transferreq);
- rsmrpc->reg(rsm_protocol::transferdonereq, this, &rsm::transferdonereq);
- rsmrpc->reg(rsm_protocol::joinreq, this, &rsm::joinreq);
+ rsmrpc->reg(rsm_client_protocol::invoke, &rsm::client_invoke, this);
+ rsmrpc->reg(rsm_client_protocol::members, &rsm::client_members, this);
+ rsmrpc->reg(rsm_protocol::invoke, &rsm::invoke, this);
+ rsmrpc->reg(rsm_protocol::transferreq, &rsm::transferreq, this);
+ rsmrpc->reg(rsm_protocol::transferdonereq, &rsm::transferdonereq, this);
+ rsmrpc->reg(rsm_protocol::joinreq, &rsm::joinreq, this);
- testsvr = new rpcs(atoi(_me.c_str()) + 1);
- testsvr->reg(rsm_test_protocol::net_repair, this, &rsm::test_net_repairreq);
- testsvr->reg(rsm_test_protocol::breakpoint, this, &rsm::breakpointreq);
+ testsvr = 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);
while (!cfg->ismember(cfg->myaddr(), vid_commit)) {
// XXX iannucci 2013/09/15 -- I don't understand whether accessing
// cfg->view_id in this manner involves a race. I suspect not.
while (!cfg->ismember(cfg->myaddr(), vid_commit)) {
// 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)) {
- tprintf("recovery: joined\n");
- commit_change_wo(cfg->view_id());
+ if (join(primary, ml)) {
+ LOG("recovery: joined");
+ commit_change(cfg->view_id(), ml);
-template <class A>
-std::ostream & operator<<(std::ostream &o, const std::vector<A> &d) {
- o << "[";
- for (typename std::vector<A>::const_iterator i=d.begin(); i!=d.end(); i++) {
- o << *i;
- if (i+1 != d.end())
- o << ", ";
- }
- o << "]";
- return o;
-}
-
-bool rsm::sync_with_backups() {
- adopt_lock ml(rsm_mutex);
- ml.unlock();
+bool rsm::sync_with_backups(lock & rsm_mutex_lock) {
+ rsm_mutex_lock.unlock();
// synchronization; otherwise, the primary's state may be more recent
// than replicas after the synchronization.
// synchronization; otherwise, the primary's state may be more recent
// than replicas after the synchronization.
// replicas are synchronized. The reason is that client_invoke arrives
// after this point of time will see inviewchange == true, and returns
// BUSY.
}
// replicas are synchronized. The reason is that client_invoke arrives
// after this point of time will see inviewchange == true, and returns
// BUSY.
}
// Start accepting synchronization request (statetransferreq) now!
insync = true;
cfg->get_view(vid_insync, backups);
backups.erase(find(backups.begin(), backups.end(), cfg->myaddr()));
// Start accepting synchronization request (statetransferreq) now!
insync = true;
cfg->get_view(vid_insync, backups);
backups.erase(find(backups.begin(), backups.end(), cfg->myaddr()));
-/**
- * Call to transfer state from m to the local node.
- * Assumes that rsm_mutex is already held.
- */
-bool rsm::statetransfer(std::string m)
+//
+// Call to transfer state from m to the local node.
+// Assumes that rsm_mutex is already held.
+//
+bool rsm::statetransfer(const string & m, lock & rsm_mutex_lock)
- tprintf("rsm::statetransfer: contact %s w. my last_myvs(%d,%d)\n",
- m.c_str(), last_myvs.vid, last_myvs.seqno);
+ LOG("contact " << m << " w. my last_myvs(" << last_myvs.vid << "," << last_myvs.seqno << ")");
- ret = cl->call(rsm_protocol::transferreq, cfg->myaddr(),
- last_myvs, vid_insync, r, rpcc::to(1000));
+ ret = cl->call_timeout(rsm_protocol::transferreq, rpcc::to(1000),
+ r, cfg->myaddr(), last_myvs, vid_insync);
- tprintf("rsm::statetransfer: couldn't reach %s %lx %d\n", m.c_str(),
- (long unsigned) cl, ret);
+ LOG("couldn't reach " << m << " " << hex << cl << " " << dec << ret);
- tprintf("rsm::statetransfer transfer from %s success, vs(%d,%d)\n",
- m.c_str(), last_myvs.vid, last_myvs.seqno);
+ LOG("transfer from " << m << " success, vs(" << last_myvs.vid << "," << last_myvs.seqno << ")");
-bool rsm::statetransferdone(std::string m) {
- adopt_lock ml(rsm_mutex);
- ml.unlock();
+bool rsm::statetransferdone(const string & m, lock & rsm_mutex_lock) {
+ rsm_mutex_lock.unlock();
- rsm_protocol::status ret = cl->call(rsm_protocol::transferdonereq, cfg->myaddr(), vid_insync, r);
+ auto ret = (rsm_protocol::status)cl->call(rsm_protocol::transferdonereq, r, cfg->myaddr(), vid_insync);
- tprintf("rsm::join: %s mylast (%d,%d)\n", m.c_str(), last_myvs.vid,
- last_myvs.seqno);
+ LOG("contacting " << m << " mylast (" << last_myvs.vid << "," << last_myvs.seqno << ")");
- ret = cl->call(rsm_protocol::joinreq, cfg->myaddr(), last_myvs,
- r, rpcc::to(120000));
+ ret = cl->call_timeout(rsm_protocol::joinreq, rpcc::to(120000), log,
+ cfg->myaddr(), last_myvs);
- tprintf("commit_change: new view (%d) last vs (%d,%d) %s insync %d\n",
- vid, last_myvs.vid, last_myvs.seqno, primary.c_str(), insync);
+ LOG("commit_change: new view (" << vid << ") last vs (" << last_myvs.vid << "," <<
+ last_myvs.seqno << ") " << primary << " insync " << insync);
- std::string reps;
- rsm_protocol::status ret = h->fn(args, rep);
- marshall rep1;
- rep1 << ret;
- rep1 << rep.str();
- r = rep1.str();
+ auto ret = (rsm_protocol::status)(*h)(args, rep);
+ r = marshall{ret, rep.content()}.content();
-rsm_client_protocol::status rsm::client_invoke(int procno, std::string req, std::string &r) {
- LOG("rsm::client_invoke: procno 0x" << std::hex << procno);
+rsm_client_protocol::status rsm::client_invoke(string & r, int procno, const string & req) {
+ LOG("invoke procno 0x" << hex << procno);
- rsm_protocol::status ret;
- int r;
- ret = cl->call(rsm_protocol::invoke, procno, vs, req, r, rpcc::to(1000));
+ int ignored_rval;
+ auto ret = (rsm_protocol::status)cl->call_timeout(rsm_protocol::invoke, rpcc::to(1000), ignored_rval, procno, vs, req);
LOG("Invoke returned " << ret);
if (ret != rsm_protocol::OK)
return rsm_client_protocol::BUSY;
breakpoint1();
LOG("Invoke returned " << ret);
if (ret != rsm_protocol::OK)
return rsm_client_protocol::BUSY;
breakpoint1();
-rsm_protocol::status rsm::invoke(int proc, viewstamp vs, std::string req, int &dummy) {
- LOG("rsm::invoke: procno 0x" << std::hex << proc);
+rsm_protocol::status rsm::invoke(int &, int proc, viewstamp vs, const string & req) {
+ LOG("invoke procno 0x" << hex << proc);
-/**
- * RPC handler: Send back the local node's state to the caller
- */
-rsm_protocol::status rsm::transferreq(std::string src, viewstamp last, unsigned vid,
- rsm_protocol::transferres &r) {
+//
+// RPC handler: Send back the local node's state to the caller
+//
+rsm_protocol::status rsm::transferreq(rsm_protocol::transferres &r, const string & src,
+ viewstamp last, unsigned vid) {
- int ret = rsm_protocol::OK;
- tprintf("transferreq from %s (%d,%d) vs (%d,%d)\n", src.c_str(),
- last.vid, last.seqno, last_myvs.vid, last_myvs.seqno);
- if (!insync || vid != vid_insync) {
+ LOG("transferreq from " << src << " (" << last.vid << "," << last.seqno << ") vs (" <<
+ last_myvs.vid << "," << last_myvs.seqno << ")");
+ if (!insync || vid != vid_insync)
-/**
- * RPC handler: Inform the local node (the primary) that node m has synchronized
- * for view vid
- */
-rsm_protocol::status rsm::transferdonereq(std::string m, unsigned vid, int &) {
+//
+// RPC handler: Inform the local node (the primary) that node m has synchronized
+// for view vid
+//
+rsm_protocol::status rsm::transferdonereq(int &, const string & m, unsigned vid) {
// a node that wants to join an RSM as a server sends a
// joinreq to the RSM's current primary; this is the
// handler for that RPC.
// a node that wants to join an RSM as a server sends a
// joinreq to the RSM's current primary; this is the
// handler for that RPC.
-rsm_protocol::status rsm::joinreq(std::string m, viewstamp last, rsm_protocol::joinres &r) {
- int ret = rsm_protocol::OK;
+rsm_protocol::status rsm::joinreq(string & log, const string & m, viewstamp last) {
+ auto ret = rsm_protocol::OK;
- tprintf("joinreq: src %s last (%d,%d) mylast (%d,%d)\n", m.c_str(),
- last.vid, last.seqno, last_myvs.vid, last_myvs.seqno);
+ LOG("join request from " << m << "; last=(" << last.vid << "," << last.seqno << "), mylast=(" <<
+ last_myvs.vid << "," << last_myvs.seqno << ")");
ret = rsm_protocol::BUSY;
} else {
// We cache vid_commit to avoid adding m to a view which already contains
// m due to race condition
ret = rsm_protocol::BUSY;
} else {
// We cache vid_commit to avoid adding m to a view which already contains
// m due to race condition
-/*
- * RPC handler: Send back all the nodes this local knows about to client
- * so the client can switch to a different primary
- * when it existing primary fails
- */
-rsm_client_protocol::status rsm::client_members(int i, std::vector<std::string> &r) {
- std::vector<std::string> m;
+//
+// RPC handler: Send back all the nodes this local knows about to client
+// so the client can switch to a different primary
+// when it existing primary fails
+//
+rsm_client_protocol::status rsm::client_members(vector<string> &r, int) {
+ vector<string> m;
// otherwise, the lowest number node of the previous view.
// caller should hold rsm_mutex
void rsm::set_primary(unsigned vid) {
// otherwise, the lowest number node of the previous view.
// caller should hold rsm_mutex
void rsm::set_primary(unsigned vid) {
cfg->get_view(vid, c);
cfg->get_view(vid - 1, p);
VERIFY (c.size() > 0);
if (isamember(primary,c)) {
cfg->get_view(vid, c);
cfg->get_view(vid - 1, p);
VERIFY (c.size() > 0);
if (isamember(primary,c)) {
for (unsigned i = 0; i < p.size(); i++) {
if (isamember(p[i], c)) {
primary = p[i];
for (unsigned i = 0; i < p.size(); i++) {
if (isamember(p[i], c)) {
primary = p[i];
cfg->get_view(vid_commit, m);
for (unsigned i = 0; i < m.size(); i++) {
if (m[i] != cfg->myaddr()) {
handle h(m[i]);
cfg->get_view(vid_commit, m);
for (unsigned i = 0; i < m.size(); i++) {
if (m[i] != cfg->myaddr()) {
handle h(m[i]);
- tprintf("rsm::test_net_repairreq: %d (dopartition %d, partitioned %d)\n",
- heal, dopartition, partitioned);
+ LOG("heal " << heal << " (dopartition " <<
+ dopartition << ", partitioned " << partitioned << ")");
if (b == 1) break1 = true;
else if (b == 2) break2 = true;
else if (b == 3 || b == 4) cfg->breakpoint(b);
if (b == 1) break1 = true;
else if (b == 2) break2 = true;
else if (b == 3 || b == 4) cfg->breakpoint(b);