Lots more clean-ups
[invirt/third/libt4.git] / config.cc
index 038a100..35654d8 100644 (file)
--- a/config.cc
+++ b/config.cc
@@ -73,7 +73,7 @@ void config::reconstruct(lock &cfg_mutex_lock) {
     my_view_id = paxos.instance();
     if (my_view_id > 0) {
         get_view(my_view_id, mems, cfg_mutex_lock);
-        LOG("config::reconstruct: " << my_view_id << " " << mems);
+        LOG("view " << my_view_id << " " << mems);
     }
 }
 
@@ -82,12 +82,12 @@ void config::paxos_commit(unsigned instance, const string &value) {
     lock cfg_mutex_lock(cfg_mutex);
 
     vector<string> newmem = members(value);
-    LOG("config::paxos_commit: " << instance << ": " << newmem);
+    LOG("instance " << instance << ": " << newmem);
 
     for (auto mem : mems) {
-        LOG("config::paxos_commit: is " << mem << " still a member?");
+        LOG("is " << mem << " still a member?");
         if (!isamember(mem, newmem) && me != mem) {
-            LOG("config::paxos_commit: delete " << mem);
+            LOG("delete " << mem);
             invalidate_handle(mem);
         }
     }
@@ -115,11 +115,12 @@ bool config::add(const string &new_m, unsigned vid) {
         LOG("that's not my view id, " << my_view_id << "!");
         return false;
     }
-    vector<string> m = mems;
+    LOG("calling down to paxos layer");
+    vector<string> m(mems), cmems(mems);
     m.push_back(new_m);
-    vector<string> cmems = mems;
+    LOG("old mems " << cmems << " " << value(cmems));
+    LOG("new mems " << m << " " << value(m));
     unsigned nextvid = my_view_id + 1;
-    LOG("calling down to paxos layer");
     cfg_mutex_lock.unlock();
     bool r = paxos.run(nextvid, cmems, value(m));
     cfg_mutex_lock.lock();
@@ -129,7 +130,7 @@ bool config::add(const string &new_m, unsigned vid) {
 
 // caller should hold cfg_mutex
 bool config::remove(const string &m, lock &cfg_mutex_lock) {
-    LOG("config::remove: my_view_id " << my_view_id << " remove? " << m);
+    LOG("my_view_id " << my_view_id << " remove? " << m);
     vector<string> n;
     for (auto mem : mems) {
         if (mem != m)
@@ -140,7 +141,7 @@ bool config::remove(const string &m, lock &cfg_mutex_lock) {
     cfg_mutex_lock.unlock();
     bool r = paxos.run(nextvid, cmems, value(n));
     cfg_mutex_lock.lock();
-    LOG("config::remove: proposer returned " << (r ? "success" : "failure"));
+    LOG("proposer returned " << (r ? "success" : "failure"));
     return r;
 }
 
@@ -148,17 +149,17 @@ void config::heartbeater() [[noreturn]] {
     lock cfg_mutex_lock(cfg_mutex);
 
     while (1) {
-        auto next_timeout = steady_clock::now() + seconds(3);
-        LOG("heartbeater: go to sleep");
+        auto next_timeout = steady_clock::now() + milliseconds(300);
+        LOG("go to sleep");
         config_cond.wait_until(cfg_mutex_lock, next_timeout);
 
         unsigned vid = my_view_id;
         vector<string> cmems;
         get_view(vid, cmems, cfg_mutex_lock);
-        LOG("heartbeater: current membership " << cmems);
+        LOG("current membership " << cmems);
 
         if (!isamember(me, cmems)) {
-            LOG("heartbeater: not member yet; skip hearbeat");
+            LOG("not member yet; skip hearbeat");
             continue;
         }
 
@@ -197,13 +198,13 @@ paxos_protocol::status config::heartbeat(int &r, string m, unsigned vid) {
 
 config::heartbeat_t config::doheartbeat(const string &m, lock &cfg_mutex_lock) {
     unsigned vid = my_view_id;
-    LOG("doheartbeater to " << m << " (" << vid << ")");
+    LOG("heartbeat to " << m << " (" << vid << ")");
     handle h(m);
 
     cfg_mutex_lock.unlock();
     int r = 0, ret = rpc_const::bind_failure;
     if (rpcc *cl = h.safebind())
-        ret = cl->call_timeout(paxos_protocol::heartbeat, rpcc::to(1000), r, me, vid);
+        ret = cl->call_timeout(paxos_protocol::heartbeat, milliseconds(100), r, me, vid);
     cfg_mutex_lock.lock();
 
     heartbeat_t res = OK;
@@ -215,9 +216,9 @@ config::heartbeat_t config::doheartbeat(const string &m, lock &cfg_mutex_lock) {
             invalidate_handle(m);
             break;
         default:
-            LOG("doheartbeat: problem with " << m << " (" << ret << ") my vid " << vid << " his vid " << r);
+            LOG("problem with " << m << " (" << ret << ") my vid " << vid << " his vid " << r);
             res = (ret < 0) ? FAILURE : VIEWERR;
     }
-    LOG("doheartbeat done " << res);
+    LOG("done " << res);
     return res;
 }