Type cleanups
[invirt/third/libt4.git] / rsm.cc
diff --git a/rsm.cc b/rsm.cc
index b93c701..65f60c7 100644 (file)
--- a/rsm.cc
+++ b/rsm.cc
@@ -108,17 +108,17 @@ rsm::rsm(std::string _first, std::string _me) :
         commit_change(1);
     }
     rsmrpc = cfg->get_rpcs();
-    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);
 
     // tester must be on different port, otherwise it may partition itself
-    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((uint32_t)std::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);
@@ -132,7 +132,7 @@ void rsm::reg1(int proc, handler *h) {
 }
 
 // The recovery thread runs this function
-void rsm::recovery() {
+void rsm::recovery() [[noreturn]] {
     bool r = true;
     lock ml(rsm_mutex);
 
@@ -141,7 +141,7 @@ void rsm::recovery() {
             // 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");
+                LOG("recovery: joined");
                 commit_change_wo(cfg->view_id());
             } else {
                 ml.unlock();
@@ -150,13 +150,13 @@ void rsm::recovery() {
             }
         }
         vid_insync = vid_commit;
-        tprintf("recovery: sync vid_insync %d\n", vid_insync);
+        LOG("recovery: sync vid_insync " << vid_insync);
         if (primary == cfg->myaddr()) {
             r = sync_with_backups();
         } else {
             r = sync_with_primary();
         }
-        tprintf("recovery: sync done\n");
+        LOG("recovery: sync done");
 
         // If there was a commited viewchange during the synchronization, restart
         // the recovery
@@ -168,7 +168,7 @@ void rsm::recovery() {
             myvs.seqno = 1;
             inviewchange = false;
         }
-        tprintf("recovery: go to sleep %d %d\n", insync, inviewchange);
+        LOG("recovery: go to sleep " << insync << " " << inviewchange);
         recovery_cond.wait(ml);
     }
 }
@@ -189,12 +189,12 @@ bool rsm::sync_with_backups() {
     adopt_lock ml(rsm_mutex);
     ml.unlock();
     {
-        // Make sure that the state of lock_server_cache_rsm is stable during
+        // Make sure that the state of lock_server is stable during
         // synchronization; otherwise, the primary's state may be more recent
         // than replicas after the synchronization.
-        lock ml(invoke_mutex);
+        lock ml2(invoke_mutex);
         // By acquiring and releasing the invoke_mutex once, we make sure that
-        // the state of lock_server_cache_rsm will not be changed until all
+        // the state of lock_server will not be changed until all
         // replicas are synchronized. The reason is that client_invoke arrives
         // after this point of time will see inviewchange == true, and returns
         // BUSY.
@@ -239,8 +239,8 @@ bool rsm::statetransfer(std::string m)
         ml.unlock();
         cl = h.safebind();
         if (cl) {
-            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);
         }
         ml.lock();
     }
@@ -266,7 +266,7 @@ bool rsm::statetransferdone(std::string m) {
     bool done = false;
     if (cl) {
         int r;
-        rsm_protocol::status ret = cl->call(rsm_protocol::transferdonereq, cfg->myaddr(), vid_insync, r);
+        rsm_protocol::status ret = cl->call(rsm_protocol::transferdonereq, r, cfg->myaddr(), vid_insync);
         done = (ret == rsm_protocol::OK);
     }
     ml.lock();
@@ -279,26 +279,24 @@ bool rsm::join(std::string m) {
     int ret = 0;
     rsm_protocol::joinres r;
 
-    tprintf("rsm::join: %s mylast (%d,%d)\n", m.c_str(), last_myvs.vid,
-            last_myvs.seqno);
+    LOG("rsm::join: " << m << " mylast (" << last_myvs.vid << "," << last_myvs.seqno << ")");
     rpcc *cl;
     {
         adopt_lock ml(rsm_mutex);
         ml.unlock();
         cl = h.safebind();
         if (cl != 0) {
-            ret = cl->call(rsm_protocol::joinreq, cfg->myaddr(), last_myvs,
-                    r, rpcc::to(120000));
+            ret = cl->call_timeout(rsm_protocol::joinreq, rpcc::to(120000), r,
+                    cfg->myaddr(), last_myvs);
         }
         ml.lock();
     }
 
     if (cl == 0 || ret != rsm_protocol::OK) {
-        tprintf("rsm::join: couldn't reach %s %p %d\n", m.c_str(),
-                cl, ret);
+        LOG("rsm::join: couldn't reach " << m << " " << std::hex << cl << " " << std::dec << ret);
         return false;
     }
-    tprintf("rsm::join: succeeded %s\n", r.log.c_str());
+    LOG("rsm::join: succeeded " << r.log);
     cfg->restore(r.log);
     return true;
 }
@@ -336,7 +334,7 @@ void rsm::execute(int procno, std::string req, std::string &r) {
     unmarshall args(req);
     marshall rep;
     std::string reps;
-    rsm_protocol::status ret = h->fn(args, rep);
+    rsm_protocol::status ret = (*h)(args, rep);
     marshall rep1;
     rep1 << ret;
     rep1 << rep.str();
@@ -349,14 +347,14 @@ void rsm::execute(int procno, std::string req, std::string &r) {
 // number, and invokes it on all members of the replicated state
 // machine.
 //
-rsm_client_protocol::status rsm::client_invoke(int procno, std::string req, std::string &r) {
+rsm_client_protocol::status rsm::client_invoke(std::string &r, int procno, std::string req) {
     LOG("rsm::client_invoke: procno 0x" << std::hex << procno);
     lock ml(invoke_mutex);
     std::vector<std::string> m;
     std::string myaddr;
     viewstamp vs;
     {
-        lock ml(rsm_mutex);
+        lock ml2(rsm_mutex);
         LOG("Checking for inviewchange");
         if (inviewchange)
             return rsm_client_protocol::BUSY;
@@ -382,8 +380,8 @@ rsm_client_protocol::status rsm::client_invoke(int procno, std::string req, std:
             if (!cl)
                 return rsm_client_protocol::BUSY;
             rsm_protocol::status ret;
-            int r;
-            ret = cl->call(rsm_protocol::invoke, procno, vs, req, r, rpcc::to(1000));
+            int ignored_rval;
+            ret = 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;
@@ -403,13 +401,13 @@ rsm_client_protocol::status rsm::client_invoke(int procno, std::string req, std:
 // the replica must execute requests in order (with no gaps)
 // according to requests' seqno
 
-rsm_protocol::status rsm::invoke(int proc, viewstamp vs, std::string req, int &dummy) {
+rsm_protocol::status rsm::invoke(int &, int proc, viewstamp vs, std::string req) {
     LOG("rsm::invoke: procno 0x" << std::hex << proc);
     lock ml(invoke_mutex);
     std::vector<std::string> m;
     std::string myaddr;
     {
-        lock ml(rsm_mutex);
+        lock ml2(rsm_mutex);
         // check if !inviewchange
         LOG("Checking for view change");
         if (inviewchange)
@@ -438,8 +436,8 @@ rsm_protocol::status rsm::invoke(int proc, viewstamp vs, std::string req, int &d
 /**
  * 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) {
+rsm_protocol::status rsm::transferreq(rsm_protocol::transferres &r, std::string src,
+        viewstamp last, unsigned vid) {
     lock ml(rsm_mutex);
     int ret = rsm_protocol::OK;
     tprintf("transferreq from %s (%d,%d) vs (%d,%d)\n", src.c_str(),
@@ -457,7 +455,7 @@ rsm_protocol::status rsm::transferreq(std::string src, viewstamp last, unsigned
  * 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 &) {
+rsm_protocol::status rsm::transferdonereq(int &, std::string m, unsigned vid) {
     lock ml(rsm_mutex);
     if (!insync || vid != vid_insync)
         return rsm_protocol::BUSY;
@@ -470,7 +468,7 @@ rsm_protocol::status rsm::transferdonereq(std::string m, unsigned vid, int &) {
 // 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) {
+rsm_protocol::status rsm::joinreq(rsm_protocol::joinres &r, std::string m, viewstamp last) {
     int ret = rsm_protocol::OK;
 
     lock ml(rsm_mutex);
@@ -508,7 +506,7 @@ rsm_protocol::status rsm::joinreq(std::string m, viewstamp last, rsm_protocol::j
  * 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) {
+rsm_client_protocol::status rsm::client_members(std::vector<std::string> &r, int) {
     std::vector<std::string> m;
     lock ml(rsm_mutex);
     cfg->get_view(vid_commit, m);
@@ -568,7 +566,7 @@ void rsm::net_repair_wo(bool heal) {
     rsmrpc->set_reachable(heal);
 }
 
-rsm_test_protocol::status rsm::test_net_repairreq(int heal, int &r) {
+rsm_test_protocol::status rsm::test_net_repairreq(int &r, int heal) {
     lock ml(rsm_mutex);
     tprintf("rsm::test_net_repairreq: %d (dopartition %d, partitioned %d)\n",
             heal, dopartition, partitioned);
@@ -607,7 +605,7 @@ void rsm::partition1() {
     }
 }
 
-rsm_test_protocol::status rsm::breakpointreq(int b, int &r) {
+rsm_test_protocol::status rsm::breakpointreq(int &r, int b) {
     r = rsm_test_protocol::OK;
     lock ml(rsm_mutex);
     tprintf("rsm::breakpointreq: %d\n", b);