rsm::rsm(std::string _first, std::string _me) :
stf(0), primary(_first), insync (false), inviewchange (true), vid_commit(0),
partitioned (false), dopartition(false), break1(false), break2(false)
{
rsm::rsm(std::string _first, std::string _me) :
stf(0), primary(_first), insync (false), inviewchange (true), vid_commit(0),
partitioned (false), dopartition(false), break1(false), break2(false)
{
- rsmrpc->reg(rsm_client_protocol::invoke, this, &rsm::client_invoke);
- rsmrpc->reg(rsm_client_protocol::members, this, &rsm::client_members);
- rsmrpc->reg(rsm_protocol::invoke, this, &rsm::invoke);
- rsmrpc->reg(rsm_protocol::transferreq, this, &rsm::transferreq);
- rsmrpc->reg(rsm_protocol::transferdonereq, this, &rsm::transferdonereq);
- rsmrpc->reg(rsm_protocol::joinreq, this, &rsm::joinreq);
+ rsmrpc->reg(rsm_client_protocol::invoke, &rsm::client_invoke, this);
+ rsmrpc->reg(rsm_client_protocol::members, &rsm::client_members, this);
+ rsmrpc->reg(rsm_protocol::invoke, &rsm::invoke, this);
+ rsmrpc->reg(rsm_protocol::transferreq, &rsm::transferreq, this);
+ rsmrpc->reg(rsm_protocol::transferdonereq, &rsm::transferdonereq, this);
+ rsmrpc->reg(rsm_protocol::joinreq, &rsm::joinreq, this);
// tester must be on different port, otherwise it may partition itself
testsvr = new rpcs(atoi(_me.c_str()) + 1);
// tester must be on different port, otherwise it may partition itself
testsvr = new rpcs(atoi(_me.c_str()) + 1);
- testsvr->reg(rsm_test_protocol::net_repair, this, &rsm::test_net_repairreq);
- testsvr->reg(rsm_test_protocol::breakpoint, this, &rsm::breakpointreq);
+ testsvr->reg(rsm_test_protocol::net_repair, &rsm::test_net_repairreq, this);
+ testsvr->reg(rsm_test_protocol::breakpoint, &rsm::breakpointreq, this);
- ScopedLock ml(rsm_mutex);
- VERIFY(pthread_create(&th, NULL, &recoverythread, (void *) this) == 0);
+ lock ml(rsm_mutex);
+ std::thread(&rsm::recovery, this).detach();
// Make sure that the state of lock_server_cache_rsm is stable during
// synchronization; otherwise, the primary's state may be more recent
// than replicas after the synchronization.
// Make sure that the state of lock_server_cache_rsm is stable during
// synchronization; otherwise, the primary's state may be more recent
// than replicas after the synchronization.
// By acquiring and releasing the invoke_mutex once, we make sure that
// the state of lock_server_cache_rsm will not be changed until all
// replicas are synchronized. The reason is that client_invoke arrives
// after this point of time will see inviewchange == true, and returns
// BUSY.
}
// By acquiring and releasing the invoke_mutex once, we make sure that
// the state of lock_server_cache_rsm will not be changed until all
// replicas are synchronized. The reason is that client_invoke arrives
// after this point of time will see inviewchange == true, and returns
// BUSY.
}
backups.erase(find(backups.begin(), backups.end(), cfg->myaddr()));
LOG("rsm::sync_with_backups " << backups);
backups.erase(find(backups.begin(), backups.end(), cfg->myaddr()));
LOG("rsm::sync_with_backups " << backups);
tprintf("rsm::statetransfer: contact %s w. my last_myvs(%d,%d)\n",
m.c_str(), last_myvs.vid, last_myvs.seqno);
rpcc *cl;
{
tprintf("rsm::statetransfer: contact %s w. my last_myvs(%d,%d)\n",
m.c_str(), last_myvs.vid, last_myvs.seqno);
rpcc *cl;
{
- ret = cl->call(rsm_protocol::transferreq, cfg->myaddr(),
- last_myvs, vid_insync, r, rpcc::to(1000));
+ ret = cl->call_timeout(rsm_protocol::transferreq, rpcc::to(1000),
+ r, cfg->myaddr(), last_myvs, vid_insync);
}
if (cl == 0 || ret != rsm_protocol::OK) {
tprintf("rsm::statetransfer: couldn't reach %s %lx %d\n", m.c_str(),
}
if (cl == 0 || ret != rsm_protocol::OK) {
tprintf("rsm::statetransfer: couldn't reach %s %lx %d\n", m.c_str(),
- if (!cl)
- return false;
- int r;
- rsm_protocol::status ret = cl->call(rsm_protocol::transferdonereq, cfg->myaddr(), vid_insync, r);
- if (ret != rsm_protocol::OK)
- return false;
- return true;
+ bool done = false;
+ if (cl) {
+ int r;
+ rsm_protocol::status ret = cl->call(rsm_protocol::transferdonereq, r, cfg->myaddr(), vid_insync);
+ done = (ret == rsm_protocol::OK);
+ }
+ ml.lock();
+ return done;
rsm_protocol::joinres r;
tprintf("rsm::join: %s mylast (%d,%d)\n", m.c_str(), last_myvs.vid,
last_myvs.seqno);
rpcc *cl;
{
rsm_protocol::joinres r;
tprintf("rsm::join: %s mylast (%d,%d)\n", m.c_str(), last_myvs.vid,
last_myvs.seqno);
rpcc *cl;
{
- ret = cl->call(rsm_protocol::joinreq, cfg->myaddr(), last_myvs,
- r, rpcc::to(120000));
+ ret = cl->call_timeout(rsm_protocol::joinreq, rpcc::to(120000), r,
+ cfg->myaddr(), last_myvs);
- ret = cl->call(rsm_protocol::invoke, procno, vs, req, r, rpcc::to(1000));
+ ret = cl->call_timeout(rsm_protocol::invoke, rpcc::to(1000), r, procno, vs, req);
LOG("Invoke returned " << ret);
if (ret != rsm_protocol::OK)
return rsm_client_protocol::BUSY;
LOG("Invoke returned " << ret);
if (ret != rsm_protocol::OK)
return rsm_client_protocol::BUSY;
-rsm_protocol::status rsm::invoke(int proc, viewstamp vs, std::string req, int &dummy) {
+rsm_protocol::status rsm::invoke(int &, int proc, viewstamp vs, std::string req) {
if (find(m.begin(), m.end(), myaddr) == m.end())
return rsm_protocol::ERR;
// check sequence number
if (find(m.begin(), m.end(), myaddr) == m.end())
return rsm_protocol::ERR;
// check sequence number
-rsm_protocol::status rsm::transferreq(std::string src, viewstamp last, unsigned vid,
- rsm_protocol::transferres &r) {
- ScopedLock ml(rsm_mutex);
+rsm_protocol::status rsm::transferreq(rsm_protocol::transferres &r, std::string src,
+ viewstamp last, unsigned vid) {
+ lock ml(rsm_mutex);
int ret = rsm_protocol::OK;
tprintf("transferreq from %s (%d,%d) vs (%d,%d)\n", src.c_str(),
last.vid, last.seqno, last_myvs.vid, last_myvs.seqno);
int ret = rsm_protocol::OK;
tprintf("transferreq from %s (%d,%d) vs (%d,%d)\n", src.c_str(),
last.vid, last.seqno, last_myvs.vid, last_myvs.seqno);
-rsm_protocol::status rsm::transferdonereq(std::string m, unsigned vid, int &) {
- ScopedLock ml(rsm_mutex);
+rsm_protocol::status rsm::transferdonereq(int &, std::string m, unsigned vid) {
+ lock ml(rsm_mutex);
if (!insync || vid != vid_insync)
return rsm_protocol::BUSY;
backups.erase(find(backups.begin(), backups.end(), m));
if (backups.empty())
if (!insync || vid != vid_insync)
return rsm_protocol::BUSY;
backups.erase(find(backups.begin(), backups.end(), m));
if (backups.empty())
return rsm_protocol::OK;
}
// a node that wants to join an RSM as a server sends a
// joinreq to the RSM's current primary; this is the
// handler for that RPC.
return rsm_protocol::OK;
}
// a node that wants to join an RSM as a server sends a
// joinreq to the RSM's current primary; this is the
// handler for that RPC.
tprintf("joinreq: src %s last (%d,%d) mylast (%d,%d)\n", m.c_str(),
last.vid, last.seqno, last_myvs.vid, last_myvs.seqno);
if (cfg->ismember(m, vid_commit)) {
tprintf("joinreq: src %s last (%d,%d) mylast (%d,%d)\n", m.c_str(),
last.vid, last.seqno, last_myvs.vid, last_myvs.seqno);
if (cfg->ismember(m, vid_commit)) {
// otherwise, the lowest number node of the previous view.
// caller should hold rsm_mutex
void rsm::set_primary(unsigned vid) {
// otherwise, the lowest number node of the previous view.
// caller should hold rsm_mutex
void rsm::set_primary(unsigned vid) {
- std::vector<std::string> c = cfg->get_view(vid);
- std::vector<std::string> p = cfg->get_view(vid - 1);
+ std::vector<std::string> c, p;
+ cfg->get_view(vid, c);
+ cfg->get_view(vid - 1, p);
// assumes caller holds rsm_mutex
void rsm::net_repair_wo(bool heal) {
std::vector<std::string> m;
// assumes caller holds rsm_mutex
void rsm::net_repair_wo(bool heal) {
std::vector<std::string> m;
tprintf("rsm::test_net_repairreq: %d (dopartition %d, partitioned %d)\n",
heal, dopartition, partitioned);
if (heal) {
tprintf("rsm::test_net_repairreq: %d (dopartition %d, partitioned %d)\n",
heal, dopartition, partitioned);
if (heal) {
tprintf("rsm::breakpointreq: %d\n", b);
if (b == 1) break1 = true;
else if (b == 2) break2 = true;
tprintf("rsm::breakpointreq: %d\n", b);
if (b == 1) break1 = true;
else if (b == 2) break2 = true;