5 // Paxos must maintain some durable state (i.e., that survives power
6 // failures) to run Paxos correct. This module implements a log with
7 // all durable state to run Paxos. Since the values chosen correspond
8 // to views, the log contains all views since the beginning of time.
10 log::log(acceptor *_acc, std::string _me)
13 name = "paxos-" + _me + ".log";
24 from.open(name.c_str());
26 while (from >> type) {
32 pxs->values[instance] = v;
33 pxs->instance_h = instance;
34 printf ("logread: instance: %d w. v = %s\n", instance,
35 pxs->values[instance].c_str());
39 } else if (type == "propseen") {
42 printf("logread: high update: %d(%s)\n", pxs->n_h.n, pxs->n_h.m.c_str());
43 } else if (type == "accepted") {
50 printf("logread: prop update %d(%s) with v = %s\n", pxs->n_a.n,
51 pxs->n_a.m.c_str(), pxs->v_a.c_str());
53 printf("logread: unknown log record\n");
66 from.open(name.c_str());
67 while (getline(from, v)) {
75 log::restore(std::string s)
78 printf("restore: %s\n", s.c_str());
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);