X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/5d99dbf06a14904944f5593c63705934bdfdcfb7..b2609562b3d4fc548afcc0a3dfe4ff5fd4ae3d36:/paxos.cc diff --git a/paxos.cc b/paxos.cc index b39fa5b..8b00ad8 100644 --- a/paxos.cc +++ b/paxos.cc @@ -20,7 +20,7 @@ bool majority(const nodes_t &l1, const nodes_t &l2) { // paxos_commit to inform higher layers of the agreed value for this // instance. -proposer_acceptor::proposer_acceptor(class paxos_change *_delegate, +proposer_acceptor::proposer_acceptor(paxos_change *_delegate, bool _first, const node_t & _me, const value_t & _value) : delegate(_delegate), me (_me) { @@ -48,12 +48,15 @@ bool proposer_acceptor::run(unsigned instance, const nodes_t & cur_nodes, const bool r = false; proposal.n = max(promise.n, proposal.n) + 1; nodes_t accepts; - value_t v = newv; + value_t v; if (prepare(instance, accepts, cur_nodes, v)) { if (majority(cur_nodes, accepts)) { LOG("received a majority of prepare responses"); + if (!v.size()) + v = newv; + breakpoint1(); nodes_t nodes; @@ -91,7 +94,7 @@ bool proposer_acceptor::prepare(unsigned instance, nodes_t & accepts, if (!r) continue; auto status = (paxos_protocol::status)r->call_timeout( - paxos_protocol::preparereq, rpcc::to(1000), res, me, instance, proposal); + paxos_protocol::preparereq, milliseconds(100), res, me, instance, proposal); if (status == paxos_protocol::OK) { if (res.oldinstance) { LOG("commiting old instance!"); @@ -122,7 +125,7 @@ void proposer_acceptor::accept(unsigned instance, nodes_t & accepts, continue; bool accept = false; int status = r->call_timeout( - paxos_protocol::acceptreq, rpcc::to(1000), accept, me, instance, proposal, v); + paxos_protocol::acceptreq, milliseconds(100), accept, me, instance, proposal, v); if (status == paxos_protocol::OK && accept) accepts.push_back(i); } @@ -135,7 +138,7 @@ void proposer_acceptor::decide(unsigned instance, const nodes_t & accepts, const if (!r) continue; int res = 0; - r->call_timeout(paxos_protocol::decidereq, rpcc::to(1000), res, me, instance, v); + r->call_timeout(paxos_protocol::decidereq, milliseconds(100), res, me, instance, v); } } @@ -203,17 +206,18 @@ void proposer_acceptor::commit(unsigned instance, const value_t & value) { } void proposer_acceptor::commit(unsigned instance, const value_t & value, lock & pxs_mutex_lock) { - LOG("acceptor::commit: instance=" << instance << " has v=" << value); + LOG("instance=" << instance << " has v=" << value); if (instance > instance_h) { - LOG("commit: highestacceptedinstance = " << instance); + LOG("highestacceptedinstance = " << instance); values[instance] = value; l.loginstance(instance, value); instance_h = instance; accepted = promise = {0, me}; - accepted_value.clear(); + string v = value; // gaaahhh aliasing of value and accepted_value + accepted_value.clear(); // this wipes out "value", too if (delegate) { pxs_mutex_lock.unlock(); - delegate->paxos_commit(instance, value); + delegate->paxos_commit(instance, v); pxs_mutex_lock.lock(); } }