Fixed two major bugs in paxos.cc.
[invirt/third/libt4.git] / paxos.cc
index 3166c92..85507d5 100644 (file)
--- a/paxos.cc
+++ b/paxos.cc
@@ -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;
@@ -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();
         }
     }