Rewrote threaded log code to be more idiomatic.
[invirt/third/libt4.git] / config.cc
index cd06e1b..374757f 100644 (file)
--- a/config.cc
+++ b/config.cc
@@ -59,7 +59,7 @@ void config::get_view(unsigned instance, vector<string> & m) {
 void config::get_view(unsigned instance, vector<string> & m, lock & cfg_mutex_lock) {
     VERIFY(cfg_mutex_lock);
     string value = paxos.value(instance);
-    LOG("get_view(" << instance << "): returns " << value);
+    LOG << "get_view(" << instance << "): returns " << value;
     m = explode(value);
 }
 
@@ -68,7 +68,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("view " << my_view_id << " " << mems);
+        LOG << "view " << my_view_id << " " << mems;
     }
 }
 
@@ -77,12 +77,12 @@ void config::paxos_commit(unsigned instance, const string & value) {
     lock cfg_mutex_lock(cfg_mutex);
 
     vector<string> newmem = explode(value);
-    LOG("instance " << instance << ": " << newmem);
+    LOG << "instance " << instance << ": " << newmem;
 
     for (auto mem : mems) {
-        LOG("is " << mem << " still a member?");
+        LOG << "is " << mem << " still a member?";
         if (!isamember(mem, newmem) && me != mem) {
-            LOG("delete " << mem);
+            LOG << "delete " << mem;
             handle(mem).invalidate();
         }
     }
@@ -105,28 +105,28 @@ bool config::ismember(const string & m, unsigned vid) {
 
 bool config::add(const string & new_m, unsigned vid) {
     lock cfg_mutex_lock(cfg_mutex);
-    LOG("adding " << new_m << " to " << vid);
+    LOG << "adding " << new_m << " to " << vid;
     if (vid != my_view_id) {
-        LOG("that's not my view id, " << my_view_id << "!");
+        LOG << "that's not my view id, " << my_view_id << "!";
         return false;
     }
-    LOG("calling down to paxos layer");
+    LOG << "calling down to paxos layer";
     vector<string> m(mems), cmems(mems);
     m.push_back(new_m);
-    LOG("old mems " << cmems << " " << implode(cmems));
-    LOG("new mems " << m << " " << implode(m));
+    LOG << "old mems " << cmems << " " << implode(cmems);
+    LOG << "new mems " << m << " " << implode(m);
     unsigned nextvid = my_view_id + 1;
     cfg_mutex_lock.unlock();
     bool r = paxos.run(nextvid, cmems, implode(m));
     cfg_mutex_lock.lock();
-    LOG("paxos proposer returned " << (r ? "success" : "failure"));
+    LOG << "paxos proposer returned " << (r ? "success" : "failure");
     return r;
 }
 
 // caller should hold cfg_mutex
 bool config::remove(const string & m, lock & cfg_mutex_lock) {
     VERIFY(cfg_mutex_lock);
-    LOG("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)
@@ -137,7 +137,7 @@ bool config::remove(const string & m, lock & cfg_mutex_lock) {
     cfg_mutex_lock.unlock();
     bool r = paxos.run(nextvid, cmems, implode(n));
     cfg_mutex_lock.lock();
-    LOG("proposer returned " << (r ? "success" : "failure"));
+    LOG << "proposer returned " << (r ? "success" : "failure");
     return r;
 }
 
@@ -146,16 +146,16 @@ void config::heartbeater() {
 
     while (1) {
         auto next_timeout = steady_clock::now() + milliseconds(300);
-        LOG("go to sleep");
+        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("current membership " << cmems);
+        LOG << "current membership " << cmems;
 
         if (!isamember(me, cmems)) {
-            LOG("not member yet; skip hearbeat");
+            LOG << "not member yet; skip hearbeat";
             continue;
         }
 
@@ -182,7 +182,7 @@ void config::heartbeater() {
 paxos_protocol::status config::heartbeat(int & r, string m, unsigned vid) {
     lock cfg_mutex_lock(cfg_mutex);
     r = (int) my_view_id;
-    LOG("heartbeat from " << m << "(" << vid << ") my_view_id " << my_view_id);
+    LOG<< "heartbeat from " << m << "(" << vid << ") my_view_id " << my_view_id;
     if (vid == my_view_id)
         return paxos_protocol::OK;
     else if (paxos.isrunning()) {
@@ -195,7 +195,7 @@ paxos_protocol::status config::heartbeat(int & r, string m, unsigned vid) {
 config::heartbeat_t config::doheartbeat(const string & m, lock & cfg_mutex_lock) {
     VERIFY(cfg_mutex_lock);
     unsigned vid = my_view_id;
-    LOG("heartbeat to " << m << " (" << vid << ")");
+    LOG << "heartbeat to " << m << " (" << vid << ")";
     handle h(m);
 
     cfg_mutex_lock.unlock();
@@ -213,9 +213,9 @@ config::heartbeat_t config::doheartbeat(const string & m, lock & cfg_mutex_lock)
             h.invalidate();
             break;
         default:
-            LOG("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("done " << res);
+    LOG << "done " << res;
     return res;
 }