6 // Paxos must maintain some durable state (i.e., that survives power
7 // failures) to run Paxos correct. This module implements a log with
8 // all durable state to run Paxos. Since the values chosen correspond
9 // to views, the log contains all views since the beginning of time.
11 log::log(acceptor *_acc, std::string _me)
14 name = "paxos-" + _me + ".log";
25 from.open(name.c_str());
27 while (from >> type) {
33 pxs->values[instance] = v;
34 pxs->instance_h = instance;
35 LOG("logread: instance: " << instance << " w. v = " <<
36 pxs->values[instance]);
40 } else if (type == "propseen") {
43 LOG("logread: high update: " << pxs->n_h.n << "(" << pxs->n_h.m << ")");
44 } else if (type == "accepted") {
51 LOG("logread: prop update " << pxs->n_a.n << "(" << pxs->n_a.m << ") with v = " << pxs->v_a);
53 LOG("logread: unknown log record");
66 from.open(name.c_str());
67 while (getline(from, v)) {
75 log::restore(std::string s)
78 LOG("restore: " << s);
79 f.open(name.c_str(), std::ios::trunc);
84 // XXX should be an atomic operation
86 log::loginstance(unsigned instance, std::string v)
89 f.open(name.c_str(), std::ios::app);
99 // an acceptor should call logprop(n_h) when it
100 // receives a prepare to which it responds prepare_ok().
102 log::logprop(prop_t n_h)
105 f.open(name.c_str(), std::ios::app);
115 // an acceptor should call logaccept(n_a, v_a) when it
116 // receives an accept RPC to which it replies accept_ok().
118 log::logaccept(prop_t n, std::string v)
121 f.open(name.c_str(), std::ios::app);