X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/f0dcb6b97d6d40f67698d1f71ac26970f1776f82..3efa02fb3a9f0a0566a7f3c99a1efb94e30ea4a6:/rsm_client.cc diff --git a/rsm_client.cc b/rsm_client.cc index 598a1ed..4a484ae 100644 --- a/rsm_client.cc +++ b/rsm_client.cc @@ -1,13 +1,12 @@ #include "rsm_client.h" #include -#include #include rsm_client::rsm_client(string dst) : primary(dst) { - LOG("create rsm_client"); + LOG << "create rsm_client"; lock ml(rsm_client_mutex); VERIFY (init_members(ml)); - LOG("done"); + LOG << "done"; } void rsm_client::primary_failure(lock &) { @@ -18,11 +17,11 @@ void rsm_client::primary_failure(lock &) { rsm_protocol::status rsm_client::invoke(unsigned int proc, string & rep, const string & req) { lock ml(rsm_client_mutex); while (1) { - LOG("proc " << hex << proc << " primary " << primary); - handle h(primary); + LOG << "proc " << std::hex << proc << " primary " << primary; + string prim = primary; ml.unlock(); - rpcc *cl = h.safebind(); + 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); @@ -31,34 +30,34 @@ rsm_protocol::status rsm_client::invoke(unsigned int proc, string & rep, const s if (!cl) goto prim_fail; - LOG("proc " << hex << proc << " primary " << primary << " ret " << dec << ret); + LOG << "proc " << std::hex << proc << " primary " << prim << " ret " << std::dec << ret; if (ret == rsm_client_protocol::OK) return rsm_protocol::OK; if (ret == rsm_client_protocol::BUSY) { - LOG("rsm is busy " << primary); - usleep(300000); + LOG << "rsm is busy " << prim; + std::this_thread::sleep_for(milliseconds(300)); continue; } if (ret == rsm_client_protocol::NOTPRIMARY) { - LOG("primary " << primary << " isn't the primary--let's get a complete list of mems"); + LOG << "primary " << prim << " isn't the primary--let's get a complete list of mems"; if (init_members(ml)) continue; } prim_fail: - LOG("primary " << primary << " failed ret " << dec << ret); + LOG << "primary " << prim << " failed ret " << std::dec << ret; primary_failure(ml); - LOG("retry new primary " << primary); + LOG << "retry new primary " << prim; } } bool rsm_client::init_members(lock & rsm_client_mutex_lock) { - LOG("get members!"); - handle h(primary); + LOG << "get members!"; + string prim = primary; int ret = rsm_client_protocol::ERR; - rpcc *cl; + shared_ptr cl; { rsm_client_mutex_lock.unlock(); - cl = h.safebind(); + cl = rpcc::bind_cached(prim); if (cl) ret = cl->call_timeout(rsm_client_protocol::members, milliseconds(100), known_mems, 0); rsm_client_mutex_lock.lock(); @@ -66,14 +65,14 @@ bool rsm_client::init_members(lock & rsm_client_mutex_lock) { if (cl == 0 || ret != rsm_protocol::OK) return false; if (known_mems.size() < 1) { - LOG("do not know any members!"); + LOG << "do not know any members!"; VERIFY(0); } primary = known_mems.back(); known_mems.pop_back(); - LOG("primary " << primary); + LOG << "primary " << primary; return true; }