1 #include "rsm_client.h"
7 #include "lang/verify.h"
10 rsm_client::rsm_client(std::string dst) {
11 printf("create rsm_client\n");
12 std::vector<std::string> mems;
14 pthread_mutex_init(&rsm_client_mutex, NULL);
16 make_sockaddr(dst.c_str(), &dstsock);
20 ScopedLock ml(&rsm_client_mutex);
21 VERIFY (init_members());
23 printf("rsm_client: done\n");
26 // Assumes caller holds rsm_client_mutex
27 void rsm_client::primary_failure() {
28 primary = known_mems.back();
29 known_mems.pop_back();
32 rsm_protocol::status rsm_client::invoke(int proc, std::string req, std::string &rep) {
34 ScopedLock ml(&rsm_client_mutex);
36 printf("rsm_client::invoke proc %x primary %s\n", proc, primary.c_str());
39 VERIFY(pthread_mutex_unlock(&rsm_client_mutex)==0);
40 rpcc *cl = h.safebind();
42 ret = cl->call(rsm_client_protocol::invoke, proc, req, rep, rpcc::to(5000));
43 VERIFY(pthread_mutex_lock(&rsm_client_mutex)==0);
48 printf("rsm_client::invoke proc %x primary %s ret %d\n", proc,
49 primary.c_str(), ret);
50 if (ret == rsm_client_protocol::OK)
52 if (ret == rsm_client_protocol::BUSY) {
53 printf("rsm is busy %s\n", primary.c_str());
57 if (ret == rsm_client_protocol::NOTPRIMARY) {
58 printf("primary %s isn't the primary--let's get a complete list of mems\n",
64 printf("primary %s failed ret %d\n", primary.c_str(), ret);
66 printf ("rsm_client::invoke: retry new primary %s\n", primary.c_str());
71 bool rsm_client::init_members() {
72 printf("rsm_client::init_members get members!\n");
74 VERIFY(pthread_mutex_unlock(&rsm_client_mutex)==0);
76 rpcc *cl = h.safebind();
78 ret = cl->call(rsm_client_protocol::members, 0, known_mems,
81 VERIFY(pthread_mutex_lock(&rsm_client_mutex)==0);
82 if (cl == 0 || ret != rsm_protocol::OK)
84 if (known_mems.size() < 1) {
85 printf("rsm_client::init_members do not know any members!\n");
89 primary = known_mems.back();
90 known_mems.pop_back();
92 printf("rsm_client::init_members: primary %s\n", primary.c_str());