So many changes. Broken.
[invirt/third/libt4.git] / rsm_client.cc
index 4a484ae..b24f056 100644 (file)
@@ -1,7 +1,9 @@
-#include "rsm_client.h"
+#include "include/rsm_client.h"
 #include <arpa/inet.h>
 #include <unistd.h>
 
+using namespace std::chrono;
+
 rsm_client::rsm_client(string dst) : primary(dst) {
     LOG << "create rsm_client";
     lock ml(rsm_client_mutex);
@@ -9,12 +11,7 @@ rsm_client::rsm_client(string dst) : primary(dst) {
     LOG << "done";
 }
 
-void rsm_client::primary_failure(lock &) {
-    primary = known_mems.back();
-    known_mems.pop_back();
-}
-
-rsm_protocol::status rsm_client::invoke(unsigned int proc, string & rep, const string & req) {
+rsm_protocol::status rsm_client::invoke(rpc_protocol::proc_id_t proc, string & rep, const string & req) {
     lock ml(rsm_client_mutex);
     while (1) {
         LOG << "proc " << std::hex << proc << " primary " << primary;
@@ -24,7 +21,7 @@ rsm_protocol::status rsm_client::invoke(unsigned int proc, string & rep, const s
         auto cl = rpcc::bind_cached(prim);
         auto ret = rsm_client_protocol::OK;
         if (cl)
-            ret = (rsm_client_protocol::status)cl->call_timeout(rsm_client_protocol::invoke, milliseconds(500), rep, proc, req);
+            ret = (rsm_client_protocol::status)cl->call_timeout(rsm_client_protocol::invoke, 500ms, rep, proc, req);
         ml.lock();
 
         if (!cl)
@@ -35,7 +32,7 @@ rsm_protocol::status rsm_client::invoke(unsigned int proc, string & rep, const s
             return rsm_protocol::OK;
         if (ret == rsm_client_protocol::BUSY) {
             LOG << "rsm is busy " << prim;
-            std::this_thread::sleep_for(milliseconds(300));
+            std::this_thread::sleep_for(300ms);
             continue;
         }
         if (ret == rsm_client_protocol::NOTPRIMARY) {
@@ -45,7 +42,8 @@ rsm_protocol::status rsm_client::invoke(unsigned int proc, string & rep, const s
         }
 prim_fail:
         LOG << "primary " << prim << " failed ret " << std::dec << ret;
-        primary_failure(ml);
+        primary = known_mems.back();
+        known_mems.pop_back();
         LOG << "retry new primary " << prim;
     }
 }
@@ -57,14 +55,13 @@ bool rsm_client::init_members(lock & rsm_client_mutex_lock) {
     shared_ptr<rpcc> cl;
     {
         rsm_client_mutex_lock.unlock();
-        cl = rpcc::bind_cached(prim);
-        if (cl)
-            ret = cl->call_timeout(rsm_client_protocol::members, milliseconds(100), known_mems, 0);
+        if ((cl = rpcc::bind_cached(prim)))
+            ret = cl->call_timeout(rsm_client_protocol::members, 100ms, known_mems, 0);
         rsm_client_mutex_lock.lock();
     }
-    if (cl == 0 || ret != rsm_protocol::OK)
+    if (ret != rsm_protocol::OK)
         return false;
-    if (known_mems.size() < 1) {
+    if (!known_mems.size()) {
         LOG << "do not know any members!";
         VERIFY(0);
     }